0
我想播放mp3文件但不播放。没有错误。只是不玩。AVAudioPlayer不播放音频
我已经导入必需的文件:
#import <AudioToolbox/AudioServices.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
这是我的代码:
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *soundFilePath = [NSString stringWithFormat:@"%@/music.mp3", documentsDirectory];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:&error];
player.numberOfLoops = -1; //Infinite
player.volume=1;
player.delegate=self;
[player prepareToPlay];
[player play];
没有什么是错的MP3文件。我可以在我的iPhone播放器上播放它,但不能在我的应用程序中播放。
非常感谢@RegularExpression – onivi