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

Commit

Permalink
Fixes and improvements for HTTP headers in video_player plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarikk26 committed Jan 5, 2019
1 parent 084b971 commit 5f4452c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions packages/video_player/ios/Classes/VideoPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ - (instancetype)initWithURL:(NSURL*)url
_isPlaying = false;
_disposed = false;

AVURLAsset* urlAsset = [AVURLAsset URLAssetWithURL:url
options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}];
NSDictionary<NSString*, id>* options = nil;
if (headers != (NSDictionary<NSString*, NSString*>*)[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
Expand Down Expand Up @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions packages/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
/// 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));
Expand All @@ -172,6 +172,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {

int _textureId;
final String dataSource;
Map<String, String> httpHeaders;

/// Describes the type of data source this [VideoPlayerController]
/// is constructed with.
Expand All @@ -183,7 +184,6 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
Completer<void> _creatingCompleter;
StreamSubscription<dynamic> _eventSubscription;
_VideoAppLifeCycleObserver _lifeCycleObserver;
Map<String, String> httpHeaders;

@visibleForTesting
int get textureId => _textureId;
Expand Down

0 comments on commit 5f4452c

Please sign in to comment.