2011-11-07 7 views
1

私は、連続して再生したい一連のオーディオファイルを持っています。私は、audioPlayerDidFinishPlayingデリゲートメソッドを設定して、シーケンス内の次のファイルを開始します。スクリーンロックをオフにするか、エミュレータまたはiOS4デバイスで実行すると問題なく動作します。しかし、私はそれを切断されたデバイス、iOS5、画面ロックされた上で実行すると、最初のトラックの後に停止します。画面ロックがオンになった後に新しいサウンドトラックを開始する方法はありますか?ここでiphone iOS5 audioPlayerDidFinishPlayingがスクリーンロックと呼ばれていませんか?

は、アプリが画面ロックがオンになっても、私はちょうどそれが次のトラックを起動するために得ることができない現在のトラックを再生し続けて、私はすでにそれを作った私の基本的なコード

// Registers this class as the delegate of the audio session. 
[[AVAudioSession sharedInstance] setDelegate: self]; 

// Use this code instead to allow the app sound to continue to play when the screen is locked. 
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; 

UInt32 doSetProperty = 0; 
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, 
         sizeof (doSetProperty), 
         &doSetProperty 
         ); 

// Registers the audio route change listener callback function 
AudioSessionAddPropertyListener (
           kAudioSessionProperty_AudioRouteChange, 
           audioRouteChangeListenerCallback, 
           self 
           ); 

// Activates the audio session. 

NSError *activationError = nil; 
[[AVAudioSession sharedInstance] setActive: YES error: &activationError]; 

    NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"m4a"]; 
    float vol = [appSoundPlayer volume]; 

    AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
    self.appSoundPlayer = newAudio; // automatically retain audio and dealloc old file if new file is loaded 

    [newAudio release]; // release the audio safely 

    appSoundPlayer.delegate = self; 
    [appSoundPlayer prepareToPlay]; 
    [appSoundPlayer setNumberOfLoops:0]; 
    [appSoundPlayer play]; 
    [appSoundPlayer setVolume:vol]; 
    [progTime setProgress:0]; 
} 


    - (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) lappSoundPlayer successfully: (BOOL) flag { 
    //... code here to select nex sound track 
        [lappSoundPlayer play]; 
    } 

です。

注:これはiOS4で動作していたことを確認しました。

答えて

2

AVAudioSessionCategoryPlaybackというオーディオセッションカテゴリを設定しましたか?here

[[AVAudioSession sharedInstance] setDelegate: self];  
NSError *error = nil; 
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error]; 

問題が解決しない場合は、アップルのdevのフォーラムでthis messageでユーザーアスカニオによると、しようとする他の事は、リモートコントロールイベントをリッスンするようにアプリを設定することです:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
+0

最初の質問にはい。 2番目の可能性があります、私はそれをチェックします - ありがとう! –

+0

予備テストでは、2番目の解決策が働いています。テストを完了した後、私は賞金を授与されます。 –

+0

うまくいきますように!しかし、私はあなたの質問を見つけたばかりで誰もそれに答えなかったのを見たので、恩恵を受け入れることについて罪悪感を感じます。 – Don

関連する問題