diff --git a/packages/video_player/video_player_platform_interface/CHANGELOG.md b/packages/video_player/video_player_platform_interface/CHANGELOG.md index 8af22f783675..4593dcbb2194 100644 --- a/packages/video_player/video_player_platform_interface/CHANGELOG.md +++ b/packages/video_player/video_player_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.0 + +* Add cookie support for network resources. + ## 2.2.0 * Added option to set the video playback speed on the video controller. diff --git a/packages/video_player/video_player_platform_interface/lib/messages.dart b/packages/video_player/video_player_platform_interface/lib/messages.dart index bfe65f1fd2ea..4dafef428c9c 100644 --- a/packages/video_player/video_player_platform_interface/lib/messages.dart +++ b/packages/video_player/video_player_platform_interface/lib/messages.dart @@ -14,10 +14,9 @@ class TextureMessage { pigeonMap['textureId'] = textureId; return pigeonMap; } - // ignore: unused_element static TextureMessage _fromMap(Map pigeonMap) { - if (pigeonMap == null) { + if (pigeonMap == null){ return null; } final TextureMessage result = TextureMessage(); @@ -31,6 +30,7 @@ class CreateMessage { String uri; String packageName; String formatHint; + List cookies; // ignore: unused_element Map _toMap() { final Map pigeonMap = {}; @@ -38,12 +38,12 @@ class CreateMessage { pigeonMap['uri'] = uri; pigeonMap['packageName'] = packageName; pigeonMap['formatHint'] = formatHint; + pigeonMap['cookies'] = cookies; return pigeonMap; } - // ignore: unused_element static CreateMessage _fromMap(Map pigeonMap) { - if (pigeonMap == null) { + if (pigeonMap == null){ return null; } final CreateMessage result = CreateMessage(); @@ -51,6 +51,7 @@ class CreateMessage { result.uri = pigeonMap['uri']; result.packageName = pigeonMap['packageName']; result.formatHint = pigeonMap['formatHint']; + result.cookies = pigeonMap['cookies']; return result; } } @@ -65,10 +66,9 @@ class LoopingMessage { pigeonMap['isLooping'] = isLooping; return pigeonMap; } - // ignore: unused_element static LoopingMessage _fromMap(Map pigeonMap) { - if (pigeonMap == null) { + if (pigeonMap == null){ return null; } final LoopingMessage result = LoopingMessage(); @@ -88,10 +88,9 @@ class VolumeMessage { pigeonMap['volume'] = volume; return pigeonMap; } - // ignore: unused_element static VolumeMessage _fromMap(Map pigeonMap) { - if (pigeonMap == null) { + if (pigeonMap == null){ return null; } final VolumeMessage result = VolumeMessage(); @@ -111,10 +110,9 @@ class PlaybackSpeedMessage { pigeonMap['speed'] = speed; return pigeonMap; } - // ignore: unused_element static PlaybackSpeedMessage _fromMap(Map pigeonMap) { - if (pigeonMap == null) { + if (pigeonMap == null){ return null; } final PlaybackSpeedMessage result = PlaybackSpeedMessage(); @@ -134,10 +132,9 @@ class PositionMessage { pigeonMap['position'] = position; return pigeonMap; } - // ignore: unused_element static PositionMessage _fromMap(Map pigeonMap) { - if (pigeonMap == null) { + if (pigeonMap == null){ return null; } final PositionMessage result = PositionMessage(); @@ -155,10 +152,9 @@ class MixWithOthersMessage { pigeonMap['mixWithOthers'] = mixWithOthers; return pigeonMap; } - // ignore: unused_element static MixWithOthersMessage _fromMap(Map pigeonMap) { - if (pigeonMap == null) { + if (pigeonMap == null){ return null; } final MixWithOthersMessage result = MixWithOthersMessage(); @@ -169,15 +165,15 @@ class MixWithOthersMessage { class VideoPlayerApi { Future initialize() async { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.initialize', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.initialize', StandardMessageCodec()); + final Map replyMap = await channel.send(null); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -187,19 +183,19 @@ class VideoPlayerApi { } else { // noop } + } - Future create(CreateMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.create', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.create', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -209,19 +205,19 @@ class VideoPlayerApi { } else { return TextureMessage._fromMap(replyMap['result']); } + } - Future dispose(TextureMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.dispose', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.dispose', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -231,19 +227,19 @@ class VideoPlayerApi { } else { // noop } + } - Future setLooping(LoopingMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.setLooping', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.setLooping', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -253,19 +249,19 @@ class VideoPlayerApi { } else { // noop } + } - Future setVolume(VolumeMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.setVolume', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.setVolume', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -275,20 +271,19 @@ class VideoPlayerApi { } else { // noop } + } - Future setPlaybackSpeed(PlaybackSpeedMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.setPlaybackSpeed', - StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.setPlaybackSpeed', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -298,19 +293,19 @@ class VideoPlayerApi { } else { // noop } + } - Future play(TextureMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.play', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.play', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -320,19 +315,19 @@ class VideoPlayerApi { } else { // noop } + } - Future position(TextureMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -342,19 +337,19 @@ class VideoPlayerApi { } else { return PositionMessage._fromMap(replyMap['result']); } + } - Future seekTo(PositionMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.seekTo', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.seekTo', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -364,19 +359,19 @@ class VideoPlayerApi { } else { // noop } + } - Future pause(TextureMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.pause', StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.pause', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -386,20 +381,19 @@ class VideoPlayerApi { } else { // noop } + } - Future setMixWithOthers(MixWithOthersMessage arg) async { final Map requestMap = arg._toMap(); - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.setMixWithOthers', - StandardMessageCodec()); - + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.setMixWithOthers', StandardMessageCodec()); + final Map replyMap = await channel.send(requestMap); if (replyMap == null) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - details: null); + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null); } else if (replyMap['error'] != null) { final Map error = replyMap['error']; throw PlatformException( @@ -409,6 +403,7 @@ class VideoPlayerApi { } else { // noop } + } } @@ -426,129 +421,113 @@ abstract class TestHostVideoPlayerApi { void setMixWithOthers(MixWithOthersMessage arg); static void setup(TestHostVideoPlayerApi api) { { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.initialize', - StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.initialize', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { api.initialize(); return {}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.create', StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.create', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; + final Map mapMessage = message as Map; final CreateMessage input = CreateMessage._fromMap(mapMessage); final TextureMessage output = api.create(input); return {'result': output._toMap()}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.dispose', StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.dispose', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; + final Map mapMessage = message as Map; final TextureMessage input = TextureMessage._fromMap(mapMessage); api.dispose(input); return {}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.setLooping', - StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.setLooping', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; + final Map mapMessage = message as Map; final LoopingMessage input = LoopingMessage._fromMap(mapMessage); api.setLooping(input); return {}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.setVolume', - StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.setVolume', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; + final Map mapMessage = message as Map; final VolumeMessage input = VolumeMessage._fromMap(mapMessage); api.setVolume(input); return {}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.setPlaybackSpeed', - StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.setPlaybackSpeed', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; - final PlaybackSpeedMessage input = - PlaybackSpeedMessage._fromMap(mapMessage); + final Map mapMessage = message as Map; + final PlaybackSpeedMessage input = PlaybackSpeedMessage._fromMap(mapMessage); api.setPlaybackSpeed(input); return {}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.play', StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.play', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; + final Map mapMessage = message as Map; final TextureMessage input = TextureMessage._fromMap(mapMessage); api.play(input); return {}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; + final Map mapMessage = message as Map; final TextureMessage input = TextureMessage._fromMap(mapMessage); final PositionMessage output = api.position(input); return {'result': output._toMap()}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.seekTo', StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.seekTo', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; + final Map mapMessage = message as Map; final PositionMessage input = PositionMessage._fromMap(mapMessage); api.seekTo(input); return {}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.pause', StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.pause', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; + final Map mapMessage = message as Map; final TextureMessage input = TextureMessage._fromMap(mapMessage); api.pause(input); return {}; }); } { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.VideoPlayerApi.setMixWithOthers', - StandardMessageCodec()); + const BasicMessageChannel channel = + BasicMessageChannel('dev.flutter.pigeon.VideoPlayerApi.setMixWithOthers', StandardMessageCodec()); channel.setMockMessageHandler((dynamic message) async { - final Map mapMessage = - message as Map; - final MixWithOthersMessage input = - MixWithOthersMessage._fromMap(mapMessage); + final Map mapMessage = message as Map; + final MixWithOthersMessage input = MixWithOthersMessage._fromMap(mapMessage); api.setMixWithOthers(input); return {}; }); } } } + diff --git a/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart b/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart index 0ea443fb6e12..00d31d381f93 100644 --- a/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart +++ b/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart @@ -37,6 +37,7 @@ class MethodChannelVideoPlayer extends VideoPlayerPlatform { case DataSourceType.network: message.uri = dataSource.uri; message.formatHint = _videoFormatStringMap[dataSource.formatHint]; + message.cookies = dataSource.cookies; break; case DataSourceType.file: message.uri = dataSource.uri; diff --git a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart index 2757fb135af6..05e1960484d6 100644 --- a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart +++ b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart @@ -151,6 +151,7 @@ class DataSource { this.formatHint, this.asset, this.package, + this.cookies, }); /// The way in which the video was originally loaded. @@ -175,6 +176,12 @@ class DataSource { /// The package that the asset was loaded from. Only set for /// [DataSourceType.asset] videos. final String package; + + /// Http cookies string to include with [DataSourceType.network] requests. + /// + /// Each cookie should be formatted as expected from a "set-cookie" header. + /// Some platforms will ignore cookies without matching domain and path. + final List cookies; } /// The way in which the video was originally loaded. diff --git a/packages/video_player/video_player_platform_interface/pubspec.yaml b/packages/video_player/video_player_platform_interface/pubspec.yaml index cc3cd79f1f33..430a63fb93e3 100644 --- a/packages/video_player/video_player_platform_interface/pubspec.yaml +++ b/packages/video_player/video_player_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the video_player plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.2.0 +version: 2.3.0 dependencies: flutter: