Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 3f94042

Browse files
[video_player] Fixed HLS Streams on iOS (#3360)
Refactor `FLTCMTimeToMillis` to support indefinite streams. Co-authored-by: Mike Diarmid <[email protected]>
1 parent b16697c commit 3f94042

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

packages/video_player/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.8
2+
3+
* Refactor `FLTCMTimeToMillis` to support indefinite streams. Fixes [#48670](https://github.com/flutter/flutter/issues/48670).
4+
15
## 2.1.7
26

37
* Update exoplayer to 2.14.1, removing dependency on Bintray.

packages/video_player/video_player/example/integration_test/video_player_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ void main() {
7777
skip: !(kIsWeb || defaultTargetPlatform == TargetPlatform.android),
7878
);
7979

80+
testWidgets(
81+
'live stream duration != 0',
82+
(WidgetTester tester) async {
83+
VideoPlayerController networkController = VideoPlayerController.network(
84+
'https://cph-p2p-msl.akamaized.net/hls/live/2000341/test/master.m3u8',
85+
);
86+
await networkController.initialize();
87+
88+
expect(networkController.value.isInitialized, true);
89+
// Live streams should have either a positive duration or C.TIME_UNSET if the duration is unknown
90+
// See https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/Player.html#getDuration--
91+
expect(networkController.value.duration,
92+
(Duration duration) => duration != Duration.zero);
93+
},
94+
skip: (kIsWeb),
95+
);
96+
8097
testWidgets(
8198
'can be played',
8299
(WidgetTester tester) async {

packages/video_player/video_player/ios/Classes/FLTVideoPlayerPlugin.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
#error Code Requires ARC.
1212
#endif
1313

14-
int64_t FLTCMTimeToMillis(CMTime time) {
15-
if (time.timescale == 0) return 0;
16-
return time.value * 1000 / time.timescale;
17-
}
18-
1914
@interface FLTFrameUpdater : NSObject
2015
@property(nonatomic) int64_t textureId;
2116
@property(nonatomic, weak, readonly) NSObject<FlutterTextureRegistry>* registry;
@@ -107,6 +102,16 @@ - (void)itemDidPlayToEndTime:(NSNotification*)notification {
107102
}
108103
}
109104

105+
const int64_t TIME_UNSET = -9223372036854775807;
106+
107+
static inline int64_t FLTCMTimeToMillis(CMTime time) {
108+
// When CMTIME_IS_INDEFINITE return a value that matches TIME_UNSET from ExoPlayer2 on Android.
109+
// Fixes https://github.com/flutter/flutter/issues/48670
110+
if (CMTIME_IS_INDEFINITE(time)) return TIME_UNSET;
111+
if (time.timescale == 0) return 0;
112+
return time.value * 1000 / time.timescale;
113+
}
114+
110115
static inline CGFloat radiansToDegrees(CGFloat radians) {
111116
// Input range [-pi, pi] or [-180, 180]
112117
CGFloat degrees = GLKMathRadiansToDegrees((float)radians);

packages/video_player/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android, iOS, and web.
44
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
6-
version: 2.1.7
6+
version: 2.1.8
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)