2013-07-26 58 views
4

我玩實況電視流中的iOS應用,我發展。我正在使用MPMoviePlayerController並需要創建自定義控件(播放,暫停,進度條等)。的MPMoviePlayerController:得到一個可靠的非跳過currentPlaybackTime

雖然試圖獲得currentPlaybackTime我注意到一些非常奇怪的行爲:它跳過周圍像有沒有明天。

持續時間屬性是在7170秒穩定的,它永遠不會改變。該playableDuration財產的增長,而在影片播放,並currentPlaybackTime不斷跳來跳去:

playableDuration: 7179.875398 
currentPlaybackTime: 7170.181204 
-------------- 
playableDuration: 7187.655396 
currentPlaybackTime: 7171.079373 
-------------- 
playableDuration: 7197.208128 
currentPlaybackTime: 7172.131998 
-------------- 
playableDuration: 7197.208128 
currentPlaybackTime: 7173.139118 
-------------- 
playableDuration: 7197.208128 
currentPlaybackTime: 7174.139770 
-------------- 
playableDuration: 7197.208128 
currentPlaybackTime: 7175.139666 
-------------- 
playableDuration: 7197.208128 
currentPlaybackTime: 7176.140805 
-------------- 
playableDuration: 7197.208128 
currentPlaybackTime: 7177.139057 
-------------- 
playableDuration: 7197.208128 
currentPlaybackTime: 7178.139128 
-------------- 
playableDuration: 7197.208128 
currentPlaybackTime: 7179.139911 
-------------- 
playableDuration: 7199.822063 
currentPlaybackTime: 7170.095921 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7171.140078 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7172.140715 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7173.076899 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7174.139497 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7175.139907 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7176.138233 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7177.139523 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7178.135736 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7179.138545 
-------------- 
playableDuration: 7209.959997 
currentPlaybackTime: 7180.111102 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7171.132859 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7172.128591 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7173.136137 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7174.135416 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7175.137593 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7176.131573 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7177.137812 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7178.131751 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7179.135922 
-------------- 
playableDuration: 7219.939398 
currentPlaybackTime: 7180.139828 
-------------- 
playableDuration: 7229.752731 
currentPlaybackTime: 7171.129731 
-------------- 
playableDuration: 7229.752731 
currentPlaybackTime: 7172.136576 
-------------- 
playableDuration: 7229.752731 
currentPlaybackTime: 7173.132362 
-------------- 
playableDuration: 7229.752731 
currentPlaybackTime: 7174.139998 

正如你可以看到它跳從7179到7170,再從7180回到7171,一次又一次......在換句話說,似乎沒有辦法獲得一個穩定遞增的currentPlaybackTime。這導致我的進度條跳轉,並且進度標籤(0:04:30/2:00:00)也表現得非常奇怪。

有沒有人見過這種行爲?有沒有解決方法?

+0

我實際上看到的與本地MPMoviePlayerViewController完全相同的行爲。經過的時間每10秒回跳一次。我猜測我無能爲力。 –

+0

這聽起來像不正確的編碼數據 - 檢查你的電影流和它的編碼非常密切。 – Till

+0

我有同樣的問題:我稱之爲「setCurrentPlaybackTime」然後我得到「currentPlaybackTime」爲我設置它,那麼它就跳回到以前的值。這是很煩人的行爲。蘋果沒有正確解決這個問題真是太神奇了。 – bashan

回答

0

最終我用我自己的內部屬性解決了這個問題,以保持軌道的播放時間:

@property (nonatomic) NSTimeInterval previousPlaybackTime; 
@property (nonatomic) NSTimeInterval currentPlaybackTime; 
@property (strong, nonatomic) NSTimer *timer; 

- (void)setCurrentPlaybackTime:(NSTimeInterval)currentPlaybackTime { 
    BOOL force = (self.moviePlayer.playbackState == MPMoviePlaybackStatePaused); 
    [self setCurrentPlaybackTime:currentPlaybackTime force:force]; 
} 

- (void)setCurrentPlaybackTime:(NSTimeInterval)currentPlaybackTime force:(BOOL)force { 
    if (currentPlaybackTime > self.moviePlayer.duration) { 
     currentPlaybackTime = self.moviePlayer.duration; 
    } 

    if (!force && currentPlaybackTime < _previousPlaybackTime) { 
     // Don't go backwards in time if it's less then 50 seconds (solves the 10 seconds going back problem) 
     if (_previousPlaybackTime - currentPlaybackTime < 50) { 
      return; 
     } 
    } 

    if (!force && _previousPlaybackTime && currentPlaybackTime > _previousPlaybackTime) { 
     // Don't go forward in time if it's more then 10 seconds (solves the huge jumps when using the progress bar) 
     if (currentPlaybackTime - _previousPlaybackTime > 10) { 
      return; 
     } 
    } 

    _previousPlaybackTime = currentPlaybackTime; 
    _currentPlaybackTime = currentPlaybackTime; 
} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timedJob) userInfo:nil repeats:YES]; 
    [self.timer fire]; 
} 

- (void)timedJob { 
    if (self.moviePlayer.playbackState == MPMoviePlaybackStateSeekingBackward) return; 
    if (self.moviePlayer.playbackState == MPMoviePlaybackStateSeekingForward) return; 

    self.currentPlaybackTime = self.moviePlayer.currentPlaybackTime; 
} 

所以在我的界面我現在用self.currentPlaybackTime其內置了跳躍保護, 可以這麼說。當用戶使用滑塊更改播放位置時,則使用force:YES參數。

相關問題