diff --git a/packages/video_player/CHANGELOG.md b/packages/video_player/CHANGELOG.md index 559456c14908..0ed4ddcaf7ec 100644 --- a/packages/video_player/CHANGELOG.md +++ b/packages/video_player/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.2 + +* iOS: Revert the changes made in version `0.10.1` that made live streams not able to initialize on the absence of `duration`. + ## 0.10.1+3 * Add missing template type parameter to `invokeMethod` calls. diff --git a/packages/video_player/ios/Classes/VideoPlayerPlugin.m b/packages/video_player/ios/Classes/VideoPlayerPlugin.m index 4aea59f34e8b..7a3f9f2e3c22 100644 --- a/packages/video_player/ios/Classes/VideoPlayerPlugin.m +++ b/packages/video_player/ios/Classes/VideoPlayerPlugin.m @@ -305,10 +305,6 @@ - (void)sendInitialized { if (height == CGSizeZero.height && width == CGSizeZero.width) { return; } - // The player may be initialized but still needs to determine the duration. - if ([self duration] == 0) { - return; - } _isInitialized = true; _eventSink(@{ @@ -335,6 +331,17 @@ - (int64_t)position { } - (int64_t)duration { + if (CMTIME_IS_INDEFINITE([[_player currentItem] duration])) { + int64_t maxBuffering = 0; + for (NSValue* rangeValue in [_player currentItem].loadedTimeRanges) { + CMTimeRange range = [rangeValue CMTimeRangeValue]; + int64_t start = FLTCMTimeToMillis(range.start); + if (start > maxBuffering) { + maxBuffering = start + FLTCMTimeToMillis(range.duration); + } + } + return maxBuffering; + } return FLTCMTimeToMillis([[_player currentItem] duration]); } @@ -498,6 +505,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { result(nil); } else if ([@"position" isEqualToString:call.method]) { result(@([player position])); + } else if ([@"duration" isEqualToString:call.method]) { + result(@([player duration])); } else if ([@"seekTo" isEqualToString:call.method]) { [player seekTo:[argsMap[@"location"] intValue]]; result(nil); diff --git a/packages/video_player/lib/video_player.dart b/packages/video_player/lib/video_player.dart index fb42096d9709..c2d8aed21705 100644 --- a/packages/video_player/lib/video_player.dart +++ b/packages/video_player/lib/video_player.dart @@ -122,7 +122,7 @@ class VideoPlayerValue { 'buffered: [${buffered.join(', ')}], ' 'isPlaying: $isPlaying, ' 'isLooping: $isLooping, ' - 'isBuffering: $isBuffering' + 'isBuffering: $isBuffering, ' 'volume: $volume, ' 'errorDescription: $errorDescription)'; } @@ -331,10 +331,11 @@ class VideoPlayerController extends ValueNotifier { return; } final Duration newPosition = await position; + final Duration newDuration = await duration; if (_isDisposed) { return; } - value = value.copyWith(position: newPosition); + value = value.copyWith(position: newPosition, duration: newDuration); }, ); } else { @@ -369,6 +370,19 @@ class VideoPlayerController extends ValueNotifier { ); } + /// The duration in the current video. + Future get duration async { + if (_isDisposed) { + return null; + } + return Duration( + milliseconds: await _channel.invokeMethod( + 'duration', + {'textureId': _textureId}, + ), + ); + } + Future seekTo(Duration moment) async { if (_isDisposed) { return; @@ -612,6 +626,10 @@ class _VideoProgressIndicatorState extends State { final int duration = controller.value.duration.inMilliseconds; final int position = controller.value.position.inMilliseconds; + if (duration.isNaN || position.isNaN || duration == 0 || position == 0) { + return const SizedBox(); + } + int maxBuffering = 0; for (DurationRange range in controller.value.buffered) { final int end = range.end.inMilliseconds; diff --git a/packages/video_player/pubspec.yaml b/packages/video_player/pubspec.yaml index 8ed4025501d0..3c18e734c964 100644 --- a/packages/video_player/pubspec.yaml +++ b/packages/video_player/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player description: Flutter plugin for displaying inline video with other Flutter widgets on Android and iOS. author: Flutter Team -version: 0.10.1+3 +version: 0.10.2 homepage: https://github.com/flutter/plugins/tree/master/packages/video_player flutter: diff --git a/packages/video_player/test/video_player_test.dart b/packages/video_player/test/video_player_test.dart index 94bebbd331d8..20cf17f7385f 100644 --- a/packages/video_player/test/video_player_test.dart +++ b/packages/video_player/test/video_player_test.dart @@ -24,6 +24,8 @@ class FakeController extends ValueNotifier String get package => null; @override Future get position async => value.position; + @override + Future get duration async => value.duration; @override Future seekTo(Duration moment) async {}