2012-04-27 16 views
0

私は、さまざまなViewController間で音楽を再生および制御するアプリケーションを持っています。これを行うには、私は、アプリデリゲートのDidFinishLaunchingMethodにAVAudioPLayerの2つのインスタンスを作成:5.0で問題なく動作するAVAudioPlayer 4.0-4.3.5の問題

NSString *path = [[NSBundle mainBundle] pathForResource:@"minnie1" ofType:@"mp3"]; 
NSURL *path1 = [[NSURL alloc] initFileURLWithPath:path]; 
menuLoop =[[AVAudioPlayer alloc] initWithContentsOfURL:path1 error:NULL]; 
[menuLoop setDelegate:self]; 
menuLoop.numberOfLoops = -1; 
[menuLoop play]; 


NSString *path2 = [[NSBundle mainBundle] pathForResource:@"minnie2" ofType:@"mp3"]; 
NSURL *path3 = [[NSURL alloc] initFileURLWithPath:path2]; 
gameLoop=[[AVAudioPlayer alloc] initWithContentsOfURL:path3 error:NULL]; 
gameLoop.numberOfLoops = -1; 
[gameLoop setDelegate:self]; 
[gameLoop prepareToPlay]; 

この後、私は停止またはのようなコードを使用して再起動するように、様々なviewControllersでそれを呼び出す:

- (IBAction)playGameLoop{ 

NSLog(@"Begin playGameLoop"); 
FPAppDelegate *app = (FPAppDelegate *)[[UIApplication sharedApplication] delegate]; 

if ([FPAVManager audioEnabled] == NO){ 
    //DO NOTHING 
} 
else { 
    if (app.gameLoop.playing ==YES) { 
     //DO NOTHING 
    } 
    else { [app.gameLoop play]; 
    NSLog(@"End playGameLoop"); 
    } 
    } 

オーディオファイル初めてうまくいき、止めるように頼まれると止まる。しかし、iOS4デバイスでは、再び呼び出されたときに再生を開始しません。

ありがとうございます!ドキュメントから

答えて

0

:あなたは音をループしている

 
Calling this method [stop] or allowing a sound to finish playing, 
undoes the setup performed upon calling the play or prepareToPlay 
methods. 

The stop method does not reset the value of the currentTime property 
to 0. In other words, if you call stop during playback and then call 
play, playback resumes at the point where it left off. 

は、私がstopを呼び出してから、playを呼び出すことができることを期待します。しかし、私は自分自身に実行の曖昧な想起があります。 stopではなくpauseという呼び出しが、より良い解決策であることが判明しました。特に私はplayに再度電話をかけて再生を再開できます。 stopを呼び出すと、少なくとも私の経験ではplayを呼び出す前に、prepareToPlayを呼び出す必要があるようです。

iOS4.xとiOS5の間のAPIの実装にもいくつかの変更があった可能性があります。開発者のウェブサイトのAPI差分を確認してください。

+0

少なくとも私がテストした1つのデバイスでこの問題を解決したようです。 これは適切な解決策ではないかもしれませんが、新しいviewControllerの内部からプレーヤーを再初期化するとうまくいくようです。 私はまた、このviewControllerのプロパティとしてmenuLoopをリストしました。今それは大丈夫と思われる。皆さんありがとう。 – Fluffhead

関連する問題