Skip to content

Commit

Permalink
[video_player_avfoundation] Support the audio-only HLS (.m3u8) on iOS (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
napoleon-na authored Dec 11, 2024
1 parent 16616ad commit 374d1be
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/video_player/video_player_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.6.5

* Bugfix to allow the audio-only HLS (.m3u8) on iOS.

## 2.6.4

* Refactors native code structure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,22 @@ - (void)testHLSControls {
XCTAssertEqualWithAccuracy([videoInitialization[@"duration"] intValue], 4000, 200);
}

- (void)testAudioOnlyHLSControls {
NSObject<FlutterPluginRegistrar> *registrar =
[GetPluginRegistry() registrarForPlugin:@"TestAudioOnlyHLSControls"];

FVPVideoPlayerPlugin *videoPlayerPlugin =
(FVPVideoPlayerPlugin *)[[FVPVideoPlayerPlugin alloc] initWithRegistrar:registrar];

NSDictionary<NSString *, id> *videoInitialization =
[self testPlugin:videoPlayerPlugin
uri:@"https://flutter.github.io/assets-for-api-docs/assets/videos/hls/"
@"bee_audio_only.m3u8"];
XCTAssertEqualObjects(videoInitialization[@"height"], @0);
XCTAssertEqualObjects(videoInitialization[@"width"], @0);
XCTAssertEqualWithAccuracy([videoInitialization[@"duration"] intValue], 4000, 200);
}

#if TARGET_OS_IOS
- (void)testTransformFix {
[self validateTransformFixForOrientation:UIImageOrientationUp];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ - (void)setupEventSinkIfReadyToPlay {
}

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

// The player has not yet initialized when it has no size, unless it is an audio-only track.
// HLS m3u8 video files never load any tracks, and are also not yet initialized until they have
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_avfoundation
description: iOS and macOS implementation of the video_player plugin.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.6.4
version: 2.6.5

environment:
sdk: ^3.3.0
Expand Down

0 comments on commit 374d1be

Please sign in to comment.