2011-12-26 4 views
1

私はAVPlayerで音楽を再生するアプリケーションを作成しています。電話がかかったり、何かが終了したときにイベントをキャッチしたい音楽はバックグラウンドで再生されます。電話やその他のイベントが音楽プレーヤーのiPhoneをシャットダウンしたときのイベントをキャッチ

- (void)applicationWillResignActive:(UIApplication *)application

これはアプリが中断されたときにキャッチする権利の方法ですが、どのようなユーザーは電話で行われたときについては、私はそれは時に中断したところから私のプレーヤーを再開することができ、別の方法があります電話が終了し、アプリケーションが再度アクティブに設定されていますか?

ご協力ありがとうございます。

EDIT:ANSWER

- (void) beginInterruption { 
    if (playing) { 
     playing = NO; 
     interruptedWhilePlaying = YES; 
     [self updateUserInterface]; 
    } 
} 

NSError *activationError = nil; 
- (void) endInterruption { 
    if (interruptedWhilePlaying) { 
     [[AVAudioSession sharedInstance] setActive: YES error: &activationError]; 
     [player play]; 
     playing = YES; 
     interruptedWhilePlaying = NO; 
     [self updateUserInterface]; 
    } 
} 

これは、限り、あなたはAVAudioSessionデリゲートオーディオコードの

答えて

1

を実装するとして、あなたはあなたのAVAudioPlayerDelegateに実装する機能があり、答えは:

- (void)audioPlayerBeginInterruption:(AVAudioPlayer *) player; 
- (void)audioPlayerEndInterruption:(AVAudioPlayer *) player; 
+0

AVAlayerを使用していないAVAlayerを使用している場合はどうなりますか?あなたは方法が同じだと思いますか? – Krzemienski

+0

ああ、申し訳ありませんが、誤読。いいえ、私はAVPlayerのデリゲートメソッドを認識していません。 AudioSessionInitializeでは、割り込みハンドラを渡すことができます:https://developer.apple.com/library/IOs/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html#//apple_ref/doc/uid/TP40007875-CH6- SW5 –

+0

ご協力ありがとうございます。 – Krzemienski

関連する問題