2009-07-21 11 views
12

現在再生中のプレイヤーをリセットして再生するAVAudioPlayerを使用して問題が発生しています。AVAudioPlayer現在再生中のサウンドをリセットして最初から再生します

私は運で次の操作を試してください。

音が一度演じているが、その後、私はそれが音を停止ボタンを選択し二回目は、三回目は再び音を起動します。私もそれが機能しなかった選手を、リセットする示しplayer.currentTime = 0を使用してみました

//Stop the player and restart it 
if (player.playing) { 
    NSLog(@"Reset sound: %@", selectedSound); 
    [player stop]; 
    [player play]; 
} else { 
    NSLog(@"playSound: %@", selectedSound); 
    [player play];  
} 

は、私はまた、CURRENTTIME = 0をリセットしてから動作しませんでした遊びを呼び出してみました。あなたの状況については

//Stop the player and restart it 
if (player.playing) { 
    NSLog(@"Reset sound: %@", selectedSound); 
    player.currentTime = 0; 
    [player play]; 
} else { 
    NSLog(@"playSound: %@", selectedSound); 
    [player play];  
} 

答えて

33

私はあなたがすぐに再びサウンドを再生しようとしている場合は、私が代わりに停止の一時停止を示唆している以下の

//Pause the player and restart it 
if (player.playing) { 
    NSLog(@"Reset sound: %@", selectedSound); 
    [player pause]; 
} 

player.currentTime = 0; 
[player play]; 

をしようとするだろう。呼び出し停止 "再生を停止し、再生に必要な設定を元に戻します。"

+6

FWIW、私はちょうどゼロにCURRENTTIMEを設定することが十分であることを見てきました。ここで説明した方法では、オーディオを数回連続して再生することを拒否していることがわかります。 – Plumenator

0

スウィフト例:

player.currentTime = 0.0; 
関連する問題