1
上的iOS應用程序的工作,我在玩使用AVPlayer視頻,我使用同步滑塊與playerItem電流持續時間同步:AVPlayer與UISlider iOS中
//synchronizing the current time label and slider with the player.
[self.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 100) queue:dispatch_get_main_queue() usingBlock:^(CMTime time)
{
CMTime endTime = CMTimeConvertScale (self.player.currentItem.asset.duration, self.player.currentTime.timescale, kCMTimeRoundingMethod_RoundHalfAwayFromZero);
if (CMTimeCompare(endTime, kCMTimeZero) != 0) {
double normalizedTime = (double) self.player.currentTime.value/(double) endTime.value;
self.slider.value = normalizedTime;
}
Float64 currentSeconds = CMTimeGetSeconds(self.player.currentTime);
int mins = currentSeconds/60.0;
int secs = fmodf(currentSeconds, 60.0);
NSString *minsString = mins < 10 ? [NSString stringWithFormat:@"0%d", mins] : [NSString stringWithFormat:@"%d", mins];
NSString *secsString = secs < 10 ? [NSString stringWithFormat:@"0%d", secs] : [NSString stringWithFormat:@"%d", secs];
self.currentTimeLabel.text = [NSString stringWithFormat:@"%@:%@", minsString, secsString];
}];
的問題是,我玩視頻在Modal視圖中,當我按下按鈕關閉視圖控制器時,視圖控制器關閉,但視頻繼續在後臺播放(因爲可以聽到資源的音頻)。我該如何解決這個問題?我確信它與我正在使用的隊列有關,但我已經嘗試了主隊列和併發隊列,但每次結果都是一樣的。
什麼應該是「removeTimeObserver:(id)observer」中的參數觀察者? –
它必須是您的調用返回值'addPeriodicTimeObserverForInterval:queue:usingBlock:' –
我怎樣才能得到由方法addPeriodicTimeObserverForInterval:queue:usingBlock返回的值:在上面提到的代碼? –