-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[video_player] Make initialize not depend on duration, fix the live stream
#1743
Changes from all commits
6f85e06
5883b42
d15419f
93debc9
ffedc7e
a20c8d2
5f73640
4e74ed4
2af2529
bd6a6ad
f9a531d
f243d3a
2093139
138bfd3
c5fdba6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the quicker fix can be something like if ([self duration] == 0 && ![self isDurationIndefinate])And create a method to check if the duration isDurationIndefinate as simple as return CMTIME_IS_INDEFINITE([[_player currentItem] duration]);This way we can avoid the breakage also we won't need to introduce the new api for duration anymore. |
||
| 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])) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is computing the length of loaded times in livestream. I personally would think the duration is the length of the whole video. Maybe create a different method for getting the "loadedTimes" for livestream videos? |
||
| int64_t maxBuffering = 0; | ||
| for (NSValue* rangeValue in [_player currentItem].loadedTimeRanges) { | ||
| CMTimeRange range = [rangeValue CMTimeRangeValue]; | ||
| int64_t start = FLTCMTimeToMillis(range.start); | ||
| if (start > maxBuffering) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did we need this check? Can start somehow be negative? If the start is 0, do we not add the range.duration to 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); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<VideoPlayerValue> { | |
| 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<VideoPlayerValue> { | |
| ); | ||
| } | ||
|
|
||
| /// The duration in the current video. | ||
| Future<Duration> get duration async { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would seem to fail if called on Android. |
||
| if (_isDisposed) { | ||
| return null; | ||
| } | ||
| return Duration( | ||
| milliseconds: await _channel.invokeMethod<int>( | ||
| 'duration', | ||
| <String, dynamic>{'textureId': _textureId}, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| Future<void> seekTo(Duration moment) async { | ||
| if (_isDisposed) { | ||
| return; | ||
|
|
@@ -612,6 +626,10 @@ class _VideoProgressIndicatorState extends State<VideoProgressIndicator> { | |
| 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; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 <[email protected]> | ||
| version: 0.10.1+3 | ||
| version: 0.10.2 | ||
| homepage: https://github.com/flutter/plugins/tree/master/packages/video_player | ||
|
|
||
| flutter: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add what is added in this patch as well.