我正在尝试播放 mp3 文件但不播放。没有错误。就是不玩。
我已经导入了必要的文件:
#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 的播放器上播放它,但不能在我的应用程序上播放。