0

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のプレーヤーでは再生できますが、アプリでは再生できません。

4

1 に答える 1