私のプロジェクトでは、私は歌を再生するAVAudioPlayerを持っています。私はそれを一時停止してからもう一度ヒットした後、一時停止した場所ではなく上からやり直します。なぜそれが起こっているのですか? また、最初に再生を押すと、曲が3〜4秒ほど読み込まれます。私はそれを他のスレッドで読み込んで解決したと思ったが、それでもまだ読み込みが遅すぎる(少なくともビューはもう凍結しない)。どうすれば修正できますか?コードは次のとおりです。AVAudioPlayer一時停止の問題
- (IBAction)play:(id)sender {
songIsCurrentlyPaused = NO;
if(songIsCurrentlyPaused==YES){
[self.background play];
} else {
playQueue = dispatch_queue_create("volume_change", NULL);
dispatch_async(playQueue, ^{ NSString *filePath =
[[NSBundle mainBundle]pathForResource:@"some_song" ofType:@"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
self.background = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
self.background.delegate = self;
[self.background setNumberOfLoops:1];
[self.background setVolume:0.5];
[self.background play]; });
[trackNameLabel setText:@"Currently playing :\n some_song"];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(updateProgressBar) userInfo:nil repeats:YES];
}
}
- (IBAction)pause:(id)sender {
songIsCurrentlyPaused = YES;
[self.background pause];
[trackNameLabel setText:@"Currently playing : some_song (paused)"];
[self.progressBar setProgress:self.background.currentTime/self.background.duration animated:YES];
}
ありがとうございます!
問題解決ポーズで!ありがとう、非常に感謝!しかし、ローディングはまだ遅いです:( – nemesis
@ネメシス:私は自分の答えを編集しました。私は現時点では私のマックではないので、コードは不可能です。 –
あなたが再生ボタンを押すと、ビューが読み込まれた後にうまくいきます。完全に削除する方法はありませんか?遅れ?ありがとう!! – nemesis