我将此路径 (file://localhost/var/mobile/Applications/8F81BA4C-7C6F-4496-BDA7-30C45478D758/Documents/sound.wav) 转换为音频文件,即录制。
我正在将此路径转换为 NSData。
NSData 是:示例:
<00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 64617461 1cf50200 32003200 e2ffe2ff 3cff3cff 08fe08fe 44fe44fe 04fe04fe e6fde6fd 95fd95fd 96fe96fe b9feb9fe ........................................................................................................................f7fef7fe 96ff96ff bdffbdff d6ffd6ff 92009200 23012301 b200b200 79007900 5c015c01 fe01fe01 f101f101 fc01fc01 7b027b02 36023602 >
我想玩这个 NSData ,
我喜欢下面的内容:
NSString *urlString = [[NSString alloc] initWithData:appDelegate.dataTestingWasteData encoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:urlString];
self.palyer=[[AVPlayer alloc] initWithURL:url];
[self.palyer play];
但没有播放,urlString 打印为空。
同路径(file://localhost/var/mobile/Applications/8F81BA4C-7C6F-4496-BDA7-30C45478D758/Documents/sound.wav)
如果我们使用下面的代码正在播放:
-(void)playAudio
{
if (!audioRecorder.recording)
{
stopButton.enabled = YES;
recordButton.enabled = NO;
NSError *error;
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:audioRecorder.url
error:&error];
audioPlayer.delegate = self;
if (error)
NSLog(@"Error: %@",[error localizedDescription]);
else
[audioPlayer play];
}
}
最佳答案
NSString *urlString = [[NSString alloc] initWithData:appDelegate.dataTestingWasteData encoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSData *wavDATA = [NSData dataWithContentsOfURL:url];
NSError *error;
self.player=[[AVAudioPlayer alloc] initWithData:wavDATA error:&error];
[self.player play];
关于iphone - 如果我们传递 NSData 如何播放音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15272204/