내 프로젝트에서 노래를 재생하는 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