Skip to content

Commit 0187eaf

Browse files
napoleon-naandroidseb
authored andcommitted
[video_player_avfoundation] Support the audio-only HLS (.m3u8) on iOS (flutter#7890)
Supports the audio-only HLS on iOS. After through flutter/plugins#4639 and flutter/plugins#4727, we can play HLS videos and audios, but it does not support audio-only HLS. When attempting to play that on iOS, it never finishes initialization. Show the before/after demonstration here: flutter/flutter#156589 (comment) Fixes: flutter/flutter#156589 Test with flutter/assets-for-api-docs#252
1 parent 820be68 commit 0187eaf

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

packages/video_player/video_player_avfoundation/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.6.5
2+
3+
* Bugfix to allow the audio-only HLS (.m3u8) on iOS.
4+
15
## 2.6.4
26

37
* Refactors native code structure.

packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,22 @@ - (void)testHLSControls {
530530
XCTAssertEqualWithAccuracy([videoInitialization[@"duration"] intValue], 4000, 200);
531531
}
532532

533+
- (void)testAudioOnlyHLSControls {
534+
NSObject<FlutterPluginRegistrar> *registrar =
535+
[GetPluginRegistry() registrarForPlugin:@"TestAudioOnlyHLSControls"];
536+
537+
FVPVideoPlayerPlugin *videoPlayerPlugin =
538+
(FVPVideoPlayerPlugin *)[[FVPVideoPlayerPlugin alloc] initWithRegistrar:registrar];
539+
540+
NSDictionary<NSString *, id> *videoInitialization =
541+
[self testPlugin:videoPlayerPlugin
542+
uri:@"https://flutter.github.io/assets-for-api-docs/assets/videos/hls/"
543+
@"bee_audio_only.m3u8"];
544+
XCTAssertEqualObjects(videoInitialization[@"height"], @0);
545+
XCTAssertEqualObjects(videoInitialization[@"width"], @0);
546+
XCTAssertEqualWithAccuracy([videoInitialization[@"duration"] intValue], 4000, 200);
547+
}
548+
533549
#if TARGET_OS_IOS
534550
- (void)testTransformFix {
535551
[self validateTransformFixForOrientation:UIImageOrientationUp];

packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ - (void)setupEventSinkIfReadyToPlay {
383383
}
384384

385385
BOOL hasVideoTracks = [asset tracksWithMediaType:AVMediaTypeVideo].count != 0;
386-
BOOL hasNoTracks = asset.tracks.count == 0;
386+
// Audio-only HLS files have no size, so `currentItem.tracks.count` must be used to check for
387+
// track presence, as AVAsset does not always provide track information in HLS streams.
388+
BOOL hasNoTracks = currentItem.tracks.count == 0 && asset.tracks.count == 0;
387389

388390
// The player has not yet initialized when it has no size, unless it is an audio-only track.
389391
// HLS m3u8 video files never load any tracks, and are also not yet initialized until they have

packages/video_player/video_player_avfoundation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_avfoundation
22
description: iOS and macOS implementation of the video_player plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.6.4
5+
version: 2.6.5
66

77
environment:
88
sdk: ^3.3.0

0 commit comments

Comments
 (0)