[英]How to play a wav file placed in Documents directory in OSX using objective c
我一直在尝试播放音频文件,但无法成功。
SoundFilePath :/Users/admin/Library/Containers/com.abc.myApp/Data/Documents/MyAudioSample1.wav
NSSound:
NSSound *sound = [[NSSound alloc] initWithContentsOfFile:soundFilePath byReference:YES];
sound.volume = 1;
sound.delegate = self;
[sound play];
我的音频播放五次中只有一次。
AVFoundation:
NSURL* file = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:nil];
[audioPlayer prepareToPlay];
添加[audioPlayer play];
您正在准备玩但不玩。 添加以上行后,您的代码将是:
NSURL* file = [NSURL fileURLWithPath:soundFilePath]; AVAudioPlayer *audioPlayer = [[AVAudioPlayeralloc]initWithContentsOfURL:file error:nil]; [audioPlayer prepareToPlay]; [audioPlayer play];
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.