Skip to content

Commit 744baeb

Browse files
najeirasigurdm
authored andcommitted
Supports HLS video on iOS (flutter#568)
Some HLS do not have tracks, item was not set to player and it was not played. Fixed that by initializing AVPlayer with AVPlayerItem.
1 parent c75a8fd commit 744baeb

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

packages/video_player/ios/Classes/VideoPlayerPlugin.m

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,22 @@ - (instancetype)initWithURL:(NSURL*)url frameUpdater:(FLTFrameUpdater*)frameUpda
5959
_isInitialized = false;
6060
_isPlaying = false;
6161
_disposed = false;
62-
_player = [[AVPlayer alloc] init];
62+
63+
AVPlayerItem* item = [AVPlayerItem playerItemWithURL:url];
64+
[item addObserver:self
65+
forKeyPath:@"loadedTimeRanges"
66+
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
67+
context:timeRangeContext];
68+
[item addObserver:self
69+
forKeyPath:@"status"
70+
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
71+
context:statusContext];
72+
[item addObserver:self
73+
forKeyPath:@"playbackLikelyToKeepUp"
74+
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
75+
context:playbackLikelyToKeepUpContext];
76+
77+
_player = [AVPlayer playerWithPlayerItem:item];
6378
_player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
6479
[[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
6580
object:[_player currentItem]
@@ -79,20 +94,6 @@ - (instancetype)initWithURL:(NSURL*)url frameUpdater:(FLTFrameUpdater*)frameUpda
7994
(id)kCVPixelBufferIOSurfacePropertiesKey : @{}
8095
};
8196
_videoOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes];
82-
AVPlayerItem* item = [AVPlayerItem playerItemWithURL:url];
83-
84-
[item addObserver:self
85-
forKeyPath:@"loadedTimeRanges"
86-
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
87-
context:timeRangeContext];
88-
[item addObserver:self
89-
forKeyPath:@"status"
90-
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
91-
context:statusContext];
92-
[item addObserver:self
93-
forKeyPath:@"playbackLikelyToKeepUp"
94-
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
95-
context:playbackLikelyToKeepUpContext];
9697

9798
AVAsset* asset = [item asset];
9899
void (^assetCompletionHandler)(void) = ^{

0 commit comments

Comments
 (0)