Skip to content
Permalink
Browse files

Add support of custom contentType

  • Loading branch information...
brozikcz committed May 6, 2019
1 parent 1b3413a commit ab842a2c2e13af0bac25c6d39f550a3c28d77dec
@@ -71,6 +71,7 @@
EventChannel eventChannel,
TextureRegistry.SurfaceTextureEntry textureEntry,
String dataSource,
@C.ContentType Integer contentType,
Result result) {
this.eventChannel = eventChannel;
this.textureEntry = textureEntry;
@@ -93,7 +94,7 @@
true);
}

MediaSource mediaSource = buildMediaSource(uri, dataSourceFactory, context);
MediaSource mediaSource = buildMediaSource(uri, contentType, dataSourceFactory, context);
exoPlayer.prepare(mediaSource);

setupVideoPlayer(eventChannel, textureEntry, result);
@@ -108,8 +109,8 @@ private static boolean isFileOrAsset(Uri uri) {
}

private MediaSource buildMediaSource(
Uri uri, DataSource.Factory mediaDataSourceFactory, Context context) {
int type = Util.inferContentType(uri.getLastPathSegment());
Uri uri, @C.ContentType Integer contentType, DataSource.Factory mediaDataSourceFactory, Context context) {
int type = contentType != null ? contentType : Util.inferContentType(uri.getLastPathSegment());
switch (type) {
case C.TYPE_SS:
return new SsMediaSource.Factory(
@@ -343,12 +344,28 @@ public void onMethodCall(MethodCall call, Result result) {
eventChannel,
handle,
"asset:///" + assetLookupKey,
null,
result);
videoPlayers.put(handle.id(), player);
} else {
@C.ContentType Integer contentType = null;
String encoding = call.argument("encoding");
if (encoding != null) {
switch (encoding) {
case "hls":
contentType = C.TYPE_HLS;
break;
case "dash":
contentType = C.TYPE_DASH;
break;
default:
contentType = null;
break;
}
}
player =
new VideoPlayer(
registrar.context(), eventChannel, handle, call.argument("uri"), result);
registrar.context(), eventChannel, handle, call.argument("uri"), contentType, result);
videoPlayers.put(handle.id(), player);
}
break;
@@ -225,7 +225,7 @@ abstract class _PlayerLifeCycleState extends State<PlayerLifeCycle> {
class _NetworkPlayerLifeCycleState extends _PlayerLifeCycleState {
@override
VideoPlayerController createVideoPlayerController() {
return VideoPlayerController.network(widget.dataSource);
return VideoPlayerController.network(widget.dataSource, DataSourceEncoding.hls);
}
}

@@ -132,6 +132,7 @@ class VideoPlayerValue {
}

enum DataSourceType { asset, network, file }
enum DataSourceEncoding { hls, dash }

/// Controls a platform video player, and provides updates when the state is
/// changing.
@@ -151,17 +152,18 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
/// package and null otherwise.
VideoPlayerController.asset(this.dataSource, {this.package})
: dataSourceType = DataSourceType.asset,
dataSourceEncoding = null,
super(VideoPlayerValue(duration: null));

/// Constructs a [VideoPlayerController] playing a video from obtained from
/// the network.
///
/// The URI for the video is given by the [dataSource] argument and must not be
/// null.
VideoPlayerController.network(this.dataSource)
VideoPlayerController.network(this.dataSource, this.dataSourceEncoding)
: dataSourceType = DataSourceType.network,
package = null,
super(VideoPlayerValue(duration: null));
super(VideoPlayerValue(duration: null));

/// Constructs a [VideoPlayerController] playing a video from a file.
///
@@ -171,14 +173,16 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
: dataSource = 'file://${file.path}',
dataSourceType = DataSourceType.file,
package = null,
super(VideoPlayerValue(duration: null));
dataSourceEncoding = null,
super(VideoPlayerValue(duration: null));

int _textureId;
final String dataSource;

/// Describes the type of data source this [VideoPlayerController]
/// is constructed with.
final DataSourceType dataSourceType;
final DataSourceEncoding dataSourceEncoding;

final String package;
Timer _timer;
@@ -203,7 +207,18 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
};
break;
case DataSourceType.network:
dataSourceDescription = <String, dynamic>{'uri': dataSource};
String encoding;
if (dataSourceEncoding == DataSourceEncoding.hls) {
encoding = "hls";
} else if (dataSourceEncoding == DataSourceEncoding.dash) {
encoding = "dash";
} else {
encoding = null;
}
dataSourceDescription = <String, dynamic>{
'uri': dataSource,
'encoding' : encoding
};
break;
case DataSourceType.file:
dataSourceDescription = <String, dynamic>{'uri': dataSource};
@@ -21,6 +21,8 @@ class FakeController extends ValueNotifier<VideoPlayerValue>
@override
DataSourceType get dataSourceType => DataSourceType.file;
@override
DataSourceEncoding get dataSourceEncoding => DataSourceEncoding.hls;
@override
String get package => null;
@override
Future<Duration> get position async => value.position;

0 comments on commit ab842a2

Please sign in to comment.
You can’t perform that action at this time.