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