エターナルループのある音楽ファイルを再生しようとしています。私のコードは次のとおりです。
NSString *path = [[NSBundle mainBundle] pathForResource:@"theme" ofType:@"mp3" inDirectory:@"assets/audios" ];
NSURL *url = [NSURL fileURLWithPath:path];
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
audioPlayer.volume = 1.0;
if (audioPlayer == nil){
NSLog(@"Error creating player: %@", error);
}
[audioPlayer prepareToPlay];
[audioPlayer play];
しかし、それは何もしません。何も再生されず、メッセージ ログが出力されます。
以下のコードはうまく機能します:
NSString *path = [[NSBundle mainBundle] pathForResource:@"theme" ofType:@"mp3" inDirectory:@"assets/audios" ];
NSURL *url = [NSURL fileURLWithPath:path];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)CFBridgingRetain(url), &soundID);
AudioServicesPlaySystemSound (soundID);
しかし、ボリュームとループを制御する必要があります。
何が間違っているのかわかりません。誰でも私を助けることができますか?