diff --git a/packages/video_player/ios/Classes/VideoPlayerPlugin.m b/packages/video_player/ios/Classes/VideoPlayerPlugin.m index 868be6912334..b6788d148647 100644 --- a/packages/video_player/ios/Classes/VideoPlayerPlugin.m +++ b/packages/video_player/ios/Classes/VideoPlayerPlugin.m @@ -66,10 +66,14 @@ - (instancetype)initWithURL:(NSURL*)url _isPlaying = false; _disposed = false; - AVURLAsset* urlAsset = [AVURLAsset URLAssetWithURL:url - options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}]; + NSDictionary* options = nil; + if (headers != (NSDictionary*)[NSNull null]) { + options = @{@"AVURLAssetHTTPHeaderFieldsKey" : headers}; + } + + AVURLAsset* asset = [AVURLAsset URLAssetWithURL:url options:options]; + AVPlayerItem* item = [AVPlayerItem playerItemWithAsset:asset]; - AVPlayerItem* item = [AVPlayerItem playerItemWithAsset:urlAsset]; [item addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew @@ -112,7 +116,6 @@ - (instancetype)initWithURL:(NSURL*)url }; _videoOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes]; - AVAsset* asset = [item asset]; void (^assetCompletionHandler)(void) = ^{ if ([asset statusOfValueForKey:@"tracks" error:nil] == AVKeyValueStatusLoaded) { NSArray* tracks = [asset tracksWithMediaType:AVMediaTypeVideo]; diff --git a/packages/video_player/lib/video_player.dart b/packages/video_player/lib/video_player.dart index cdc71226ded9..be79e8475b34 100644 --- a/packages/video_player/lib/video_player.dart +++ b/packages/video_player/lib/video_player.dart @@ -154,8 +154,8 @@ class VideoPlayerController extends ValueNotifier { /// the network. /// /// The URI for the video is given by the [dataSource] argument and must not be - /// null. - VideoPlayerController.network(this.dataSource) + /// null. The [httpHeaders] for the request to the [dataSource] is optional and may be null. + VideoPlayerController.network(this.dataSource, {this.httpHeaders}) : dataSourceType = DataSourceType.network, package = null, super(VideoPlayerValue(duration: null)); @@ -172,6 +172,7 @@ class VideoPlayerController extends ValueNotifier { int _textureId; final String dataSource; + Map httpHeaders; /// Describes the type of data source this [VideoPlayerController] /// is constructed with. @@ -183,7 +184,6 @@ class VideoPlayerController extends ValueNotifier { Completer _creatingCompleter; StreamSubscription _eventSubscription; _VideoAppLifeCycleObserver _lifeCycleObserver; - Map httpHeaders; @visibleForTesting int get textureId => _textureId;