3

私はiPhoneアプリケーションを開発しています。このアプリでは、オーディオの再生にAVAudioPlayerを使用しています。これは、サウンドを再生するための私のコードです。

  NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
    resourcePath = [resourcePath stringByAppendingString:@"/sound.mp3"];

    NSError* err;

    player_ = [[AVAudioPlayer alloc] initWithContentsOfURL:
               [NSURL fileURLWithPath:resourcePath] error:&err];

    if( err )
    {
    }
    else
    {
        [player_ prepareToPlay];

        [player_ play];

        int playingLoops = 0;

        player_.numberOfLoops = playingLoops;
    }

iPhone5以外のiPhoneデバイスでは問題なく動作しています。iPhone5でアプリを実行していると、次のエラーが発生し、アプリがクラッシュします。

2012-11-26 09:02:28.484 test[728:1dd03] <0xb0081000> Error '!obj' trying to fetch default input device's sample rate
2012-11-26 09:02:28.484 test[728:1dd03]  <0xb0081000> Error getting     audio input  device sample rate: '!obj'
2012-11-26 09:02:28.494 test[728:1dd03]  <0xb0081000> AQMEIOManager::FindIOUnit: error '!dev'
4

3 に答える 3

0

AVAudioPlayerDelegateを.hファイルに追加し、次のコードを.mファイルに追加する必要があります

NSString* resourcePath =[[NSBundle mainBundle]pathForResource:@"sound" ofType:@"mp3"];
NSError* err;
AVAudioPlayer *audioplayer =[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath: resourcePath]  error:&err];
audioplayer.delegate=self;
if( err )
{
   NSLog(@"%@",err);
}
else
{
   [audioplayer prepareToPlay];
   [audioplayer play];
}

このコードは私のために機能しており、機能している場合は答えを受け入れます。

于 2012-11-26T04:20:14.253 に答える
0

アンブ、以下のコードを試してみてください。私の最後では、正常に動作しています。

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]];

NSLog(@"File path is:->%@",[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]);

NSFileManager* manager;
manager = [NSFileManager defaultManager];
if([manager fileExistsAtPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]])
{
    printf("file Exists...\n\n");
}
else
    printf("File not exist...\n\n");

NSError *er;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;

if (audioPlayer == nil)
    NSLog([er description]);                
else 
    [audioPlayer play];

どんな懸念でも、私に知らせてください。また、コンソールでフルパスとファイルが存在するかどうかを確認してください。

于 2012-11-26T06:19:35.850 に答える
0

私も同じエラーに直面して同じ問題に直面していました。この問題を解決しようとすると、コードに問題がないことに気付きます。メディアプレーヤーを更新するか、Flash Playerをインストールする必要があり、正常に動作します。

于 2012-12-03T11:36:50.733 に答える