瀏覽代碼

VLCKit: Reset time, remaining time and position of VLCMediaPlayer when media is changed

When the VLCMediaPlayer switches between two media, there is a short period of time when the new media is set but when the time, remaining time and position are still set to the last time and position of the previous media. This is visible on tvOS where there is a short time when switching media where the new title is already being displayed but the old time and position is still being shown. This commit resets the time, remaining time and position of the VLCMediaPlayer when its media has changed.

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Benjamin Adolphi 9 年之前
父節點
當前提交
cc1ddef474
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12 1
      Sources/VLCMediaPlayer.m

+ 12 - 1
Sources/VLCMediaPlayer.m

@@ -1385,9 +1385,20 @@ static void HandleMediaPlayerSnapshot(const libvlc_event_t * event, void * self)
 - (void)mediaPlayerMediaChanged:(VLCMedia *)newMedia
 {
     [self willChangeValueForKey:@"media"];
-    if (_media != newMedia)
+    if (_media != newMedia) {
         _media = newMedia;
 
+        [self willChangeValueForKey:@"time"];
+        [self willChangeValueForKey:@"remainingTime"];
+        [self willChangeValueForKey:@"position"];
+        _cachedTime = [VLCTime nullTime];
+        _cachedRemainingTime = [VLCTime nullTime];
+        _position = 0.0f;
+        [self didChangeValueForKey:@"position"];
+        [self didChangeValueForKey:@"remainingTime"];
+        [self didChangeValueForKey:@"time"];
+    }
+
     [self didChangeValueForKey:@"media"];
 }