Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Copy link
Contributor

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.


## 0.10.1+3

* Add missing template type parameter to `invokeMethod` calls.
Expand Down
17 changes: 13 additions & 4 deletions packages/video_player/ios/Classes/VideoPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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(@{
Expand All @@ -335,6 +331,17 @@ - (int64_t)position {
}

- (int64_t)duration {
if (CMTIME_IS_INDEFINITE([[_player currentItem] duration])) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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]);
}

Expand Down Expand Up @@ -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);
Expand Down
22 changes: 20 additions & 2 deletions packages/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class VideoPlayerValue {
'buffered: [${buffered.join(', ')}], '
'isPlaying: $isPlaying, '
'isLooping: $isLooping, '
'isBuffering: $isBuffering'
'isBuffering: $isBuffering, '
'volume: $volume, '
'errorDescription: $errorDescription)';
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -369,6 +370,19 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
);
}

/// The duration in the current video.
Future<Duration> get duration async {
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions packages/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class FakeController extends ValueNotifier<VideoPlayerValue>
String get package => null;
@override
Future<Duration> get position async => value.position;
@override
Future<Duration> get duration async => value.duration;

@override
Future<void> seekTo(Duration moment) async {}
Expand Down