Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0

* Add `httpHeaders` option to `VideoPlayerController.network`

## 2.0.2

* Fix `VideoPlayerValue` size and aspect ratio documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Autogenerated from Pigeon (v0.1.19), do not edit directly.
// Autogenerated from Pigeon (v0.1.21), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.videoplayer;
Expand Down Expand Up @@ -87,12 +87,23 @@ public void setFormatHint(String setterArg) {
this.formatHint = setterArg;
}

private HashMap httpHeaders;

public HashMap getHttpHeaders() {
return httpHeaders;
}

public void setHttpHeaders(HashMap setterArg) {
this.httpHeaders = setterArg;
}

HashMap toMap() {
HashMap<String, Object> toMapResult = new HashMap<>();
toMapResult.put("asset", asset);
toMapResult.put("uri", uri);
toMapResult.put("packageName", packageName);
toMapResult.put("formatHint", formatHint);
toMapResult.put("httpHeaders", httpHeaders);
return toMapResult;
}

Expand All @@ -106,6 +117,8 @@ static CreateMessage fromMap(HashMap map) {
fromMapResult.packageName = (String) packageName;
Object formatHint = map.get("formatHint");
fromMapResult.formatHint = (String) formatHint;
Object httpHeaders = map.get("httpHeaders");
fromMapResult.httpHeaders = (HashMap) httpHeaders;
return fromMapResult;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ final class VideoPlayer {
TextureRegistry.SurfaceTextureEntry textureEntry,
String dataSource,
String formatHint,
Map<String, String> httpHeaders,
VideoPlayerOptions options) {
this.eventChannel = eventChannel;
this.textureEntry = textureEntry;
Expand All @@ -76,13 +77,17 @@ final class VideoPlayer {

DataSource.Factory dataSourceFactory;
if (isHTTP(uri)) {
dataSourceFactory =
DefaultHttpDataSourceFactory httpDataSourceFactory =
new DefaultHttpDataSourceFactory(
"ExoPlayer",
null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
true);
if (httpHeaders != null && !httpHeaders.isEmpty()) {
httpDataSourceFactory.getDefaultRequestProperties().set(httpHeaders);
}
dataSourceFactory = httpDataSourceFactory;
} else {
dataSourceFactory = new DefaultDataSourceFactory(context, "ExoPlayer");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.flutter.view.TextureRegistry;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;

/** Android platform implementation of the VideoPlayerPlugin. */
Expand Down Expand Up @@ -138,15 +139,19 @@ public TextureMessage create(CreateMessage arg) {
handle,
"asset:///" + assetLookupKey,
null,
null,
options);
} else {
@SuppressWarnings("unchecked")
Map<String, String> httpHeaders = arg.getHttpHeaders();
player =
new VideoPlayer(
flutterState.applicationContext,
eventChannel,
handle,
arg.getUri(),
arg.getFormatHint(),
httpHeaders,
options);
}
videoPlayers.put(handle.id(), player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
@property(nonatomic, readonly) bool isPlaying;
@property(nonatomic) bool isLooping;
@property(nonatomic, readonly) bool isInitialized;
- (instancetype)initWithURL:(NSURL*)url frameUpdater:(FLTFrameUpdater*)frameUpdater;
- (instancetype)initWithURL:(NSURL*)url
frameUpdater:(FLTFrameUpdater*)frameUpdater
httpHeaders:(NSDictionary<NSString*, NSString*>*)headers;
- (void)play;
- (void)pause;
- (void)setIsLooping:(bool)isLooping;
Expand All @@ -62,7 +64,7 @@ - (void)updatePlayingState;
@implementation FLTVideoPlayer
- (instancetype)initWithAsset:(NSString*)asset frameUpdater:(FLTFrameUpdater*)frameUpdater {
NSString* path = [[NSBundle mainBundle] pathForResource:asset ofType:nil];
return [self initWithURL:[NSURL fileURLWithPath:path] frameUpdater:frameUpdater];
return [self initWithURL:[NSURL fileURLWithPath:path] frameUpdater:frameUpdater httpHeaders:nil];
}

- (void)addObservers:(AVPlayerItem*)item {
Expand Down Expand Up @@ -162,8 +164,15 @@ - (void)createVideoOutputAndDisplayLink:(FLTFrameUpdater*)frameUpdater {
_displayLink.paused = YES;
}

- (instancetype)initWithURL:(NSURL*)url frameUpdater:(FLTFrameUpdater*)frameUpdater {
AVPlayerItem* item = [AVPlayerItem playerItemWithURL:url];
- (instancetype)initWithURL:(NSURL*)url
frameUpdater:(FLTFrameUpdater*)frameUpdater
httpHeaders:(NSDictionary<NSString*, NSString*>*)headers {
NSDictionary<NSString*, id>* options = nil;
if (headers != nil && [headers count] != 0) {
options = @{@"AVURLAssetHTTPHeaderFieldsKey" : headers};
}
AVURLAsset* urlAsset = [AVURLAsset URLAssetWithURL:url options:options];
AVPlayerItem* item = [AVPlayerItem playerItemWithAsset:urlAsset];
return [self initWithPlayerItem:item frameUpdater:frameUpdater];
}

Expand Down Expand Up @@ -522,7 +531,8 @@ - (FLTTextureMessage*)create:(FLTCreateMessage*)input error:(FlutterError**)erro
return [self onPlayerSetup:player frameUpdater:frameUpdater];
} else if (input.uri) {
player = [[FLTVideoPlayer alloc] initWithURL:[NSURL URLWithString:input.uri]
frameUpdater:frameUpdater];
frameUpdater:frameUpdater
httpHeaders:input.httpHeaders];
return [self onPlayerSetup:player frameUpdater:frameUpdater];
} else {
*error = [FlutterError errorWithCode:@"video_player" message:@"not implemented" details:nil];
Expand Down
3 changes: 2 additions & 1 deletion packages/video_player/video_player/ios/Classes/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Autogenerated from Pigeon (v0.1.19), do not edit directly.
// Autogenerated from Pigeon (v0.1.21), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import <Foundation/Foundation.h>
@protocol FlutterBinaryMessenger;
Expand All @@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, nullable) NSString *uri;
@property(nonatomic, copy, nullable) NSString *packageName;
@property(nonatomic, copy, nullable) NSString *formatHint;
@property(nonatomic, strong, nullable) NSDictionary *httpHeaders;
@end

@interface FLTLoopingMessage : NSObject
Expand Down
50 changes: 28 additions & 22 deletions packages/video_player/video_player/ios/Classes/messages.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Autogenerated from Pigeon (v0.1.19), do not edit directly.
// Autogenerated from Pigeon (v0.1.21), do not edit directly.
// See also: https://pub.dev/packages/pigeon
#import "messages.h"
#import <Flutter/Flutter.h>
Expand All @@ -11,18 +11,19 @@
#error File requires ARC to be enabled.
#endif

#ifndef __clang_analyzer__
static NSDictionary *wrapResult(NSDictionary *result, FlutterError *error) {
static NSDictionary<NSString *, id> *wrapResult(NSDictionary *result, FlutterError *error) {
NSDictionary *errorDict = (NSDictionary *)[NSNull null];
if (error) {
errorDict = [NSDictionary
dictionaryWithObjectsAndKeys:(error.code ? error.code : [NSNull null]), @"code",
(error.message ? error.message : [NSNull null]), @"message",
(error.details ? error.details : [NSNull null]), @"details",
nil];
errorDict = @{
@"code" : (error.code ? error.code : [NSNull null]),
@"message" : (error.message ? error.message : [NSNull null]),
@"details" : (error.details ? error.details : [NSNull null]),
};
}
return [NSDictionary dictionaryWithObjectsAndKeys:(result ? result : [NSNull null]), @"result",
errorDict, @"error", nil];
return @{
@"result" : (result ? result : [NSNull null]),
@"error" : errorDict,
};
}

@interface FLTTextureMessage ()
Expand Down Expand Up @@ -89,6 +90,10 @@ + (FLTCreateMessage *)fromMap:(NSDictionary *)dict {
if ((NSNull *)result.formatHint == [NSNull null]) {
result.formatHint = nil;
}
result.httpHeaders = dict[@"httpHeaders"];
if ((NSNull *)result.httpHeaders == [NSNull null]) {
result.httpHeaders = nil;
}
return result;
}
- (NSDictionary *)toMap {
Expand All @@ -98,7 +103,9 @@ - (NSDictionary *)toMap {
(self.packageName ? self.packageName : [NSNull null]),
@"packageName",
(self.formatHint ? self.formatHint : [NSNull null]),
@"formatHint", nil];
@"formatHint",
(self.httpHeaders ? self.httpHeaders : [NSNull null]),
@"httpHeaders", nil];
}
@end

Expand Down Expand Up @@ -221,8 +228,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTCreateMessage *input = [FLTCreateMessage fromMap:message];
FlutterError *error;
FLTTextureMessage *output = [api create:input error:&error];
callback(wrapResult([output toMap], error));
}];
Expand All @@ -236,8 +243,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTTextureMessage *input = [FLTTextureMessage fromMap:message];
FlutterError *error;
[api dispose:input error:&error];
callback(wrapResult(nil, error));
}];
Expand All @@ -251,8 +258,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTLoopingMessage *input = [FLTLoopingMessage fromMap:message];
FlutterError *error;
[api setLooping:input error:&error];
callback(wrapResult(nil, error));
}];
Expand All @@ -266,8 +273,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTVolumeMessage *input = [FLTVolumeMessage fromMap:message];
FlutterError *error;
[api setVolume:input error:&error];
callback(wrapResult(nil, error));
}];
Expand All @@ -281,8 +288,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTPlaybackSpeedMessage *input = [FLTPlaybackSpeedMessage fromMap:message];
FlutterError *error;
[api setPlaybackSpeed:input error:&error];
callback(wrapResult(nil, error));
}];
Expand All @@ -296,8 +303,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTTextureMessage *input = [FLTTextureMessage fromMap:message];
FlutterError *error;
[api play:input error:&error];
callback(wrapResult(nil, error));
}];
Expand All @@ -311,8 +318,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTTextureMessage *input = [FLTTextureMessage fromMap:message];
FlutterError *error;
FLTPositionMessage *output = [api position:input error:&error];
callback(wrapResult([output toMap], error));
}];
Expand All @@ -326,8 +333,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTPositionMessage *input = [FLTPositionMessage fromMap:message];
FlutterError *error;
[api seekTo:input error:&error];
callback(wrapResult(nil, error));
}];
Expand All @@ -341,8 +348,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTTextureMessage *input = [FLTTextureMessage fromMap:message];
FlutterError *error;
[api pause:input error:&error];
callback(wrapResult(nil, error));
}];
Expand All @@ -356,8 +363,8 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
binaryMessenger:binaryMessenger];
if (api) {
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTMixWithOthersMessage *input = [FLTMixWithOthersMessage fromMap:message];
FlutterError *error;
[api setMixWithOthers:input error:&error];
callback(wrapResult(nil, error));
}];
Expand All @@ -366,4 +373,3 @@ void FLTVideoPlayerApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<FLTVi
}
}
}
#endif
20 changes: 17 additions & 3 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
{this.package, this.closedCaptionFile, this.videoPlayerOptions})
: dataSourceType = DataSourceType.asset,
formatHint = null,
httpHeaders = const {},
super(VideoPlayerValue(duration: Duration.zero));

/// Constructs a [VideoPlayerController] playing a video from obtained from
Expand All @@ -196,9 +197,15 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
/// null.
/// **Android only**: The [formatHint] option allows the caller to override
/// the video format detection code.
VideoPlayerController.network(this.dataSource,
{this.formatHint, this.closedCaptionFile, this.videoPlayerOptions})
: dataSourceType = DataSourceType.network,
/// [httpHeaders] option allows to specify HTTP headers
/// for the request to the [dataSource].
VideoPlayerController.network(
this.dataSource, {
this.formatHint,
this.closedCaptionFile,
this.videoPlayerOptions,
this.httpHeaders = const {},
}) : dataSourceType = DataSourceType.network,
package = null,
super(VideoPlayerValue(duration: Duration.zero));

Expand All @@ -212,12 +219,18 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
dataSourceType = DataSourceType.file,
package = null,
formatHint = null,
httpHeaders = const {},
super(VideoPlayerValue(duration: Duration.zero));

/// The URI to the video file. This will be in different formats depending on
/// the [DataSourceType] of the original video.
final String dataSource;

/// HTTP headers used for the request to the [dataSource].
/// Only for [VideoPlayerController.network].
/// Always empty for other video types.
final Map<String, String> httpHeaders;

/// **Android only**. Will override the platform's generic file format
/// detection with whatever is set here.
final VideoFormat? formatHint;
Expand Down Expand Up @@ -276,6 +289,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
sourceType: DataSourceType.network,
uri: dataSource,
formatHint: formatHint,
httpHeaders: httpHeaders,
);
break;
case DataSourceType.file:
Expand Down
1 change: 1 addition & 0 deletions packages/video_player/video_player/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CreateMessage {
String uri;
String packageName;
String formatHint;
Map<String, String> httpHeaders;
}

class MixWithOthersMessage {
Expand Down
Loading