From a56f1444661d57fda1fe4040fbb663f9bef494dc Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Tue, 24 Sep 2024 10:57:07 +0900 Subject: [PATCH] [video_player] Support httpHeaders option of VideoPlayerController.network (#751) --- packages/video_player/CHANGELOG.md | 4 +++ packages/video_player/README.md | 6 ++-- packages/video_player/pubspec.yaml | 2 +- .../video_player/tizen/src/video_player.cc | 31 ++++++++++++++++++- .../video_player/tizen/src/video_player.h | 3 +- .../tizen/src/video_player_tizen_plugin.cc | 10 +++++- 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/packages/video_player/CHANGELOG.md b/packages/video_player/CHANGELOG.md index e9bf2c2b3..a99537df1 100644 --- a/packages/video_player/CHANGELOG.md +++ b/packages/video_player/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.5.3 + +* Support `httpHeaders` option of `VideoPlayerController.network`. + ## 2.5.2 * Live streaming content starts playing immediately when SeekTo() is called. diff --git a/packages/video_player/README.md b/packages/video_player/README.md index ce8c8861b..f95e29931 100644 --- a/packages/video_player/README.md +++ b/packages/video_player/README.md @@ -48,14 +48,14 @@ For detailed information on Tizen privileges, see [Tizen Docs: API Privileges](h This plugin is not supported on TV emulators. -The following options are not supported on Tizen. +The following options are not currently supported. -- The `httpHeaders` option of `VideoPlayerController.networkUrl` - `VideoPlayerOptions.allowBackgroundPlayback` - `VideoPlayerOptions.mixWithOthers` -This plugin has some limitations on TV devices. +This plugin has the following limitations. +- The `httpHeaders` option of `VideoPlayerController.networkUrl` only support `Cookie` and `User-Agent`. - The `setPlaybackSpeed` method will fail if triggered within the last 3 seconds of the video. - The playback speed will reset to 1.0 when the video is replayed in loop mode. - The `seekTo` method works only when the playback speed is 1.0, and it sets the video position to the nearest keyframe, not the exact value passed. diff --git a/packages/video_player/pubspec.yaml b/packages/video_player/pubspec.yaml index 657b4faed..0bed634e0 100644 --- a/packages/video_player/pubspec.yaml +++ b/packages/video_player/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player_tizen description: Tizen implementation of the video_player plugin. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player -version: 2.5.2 +version: 2.5.3 environment: sdk: ">=3.3.0 <4.0.0" diff --git a/packages/video_player/tizen/src/video_player.cc b/packages/video_player/tizen/src/video_player.cc index a54a81697..b4d4094b3 100644 --- a/packages/video_player/tizen/src/video_player.cc +++ b/packages/video_player/tizen/src/video_player.cc @@ -111,7 +111,8 @@ void VideoPlayer::InitScreenSaverApi() { VideoPlayer::VideoPlayer(flutter::PluginRegistrar *plugin_registrar, flutter::TextureRegistrar *texture_registrar, - const std::string &uri, VideoPlayerOptions &options) { + const std::string &uri, VideoPlayerOptions &options, + flutter::EncodableMap &http_headers) { sink_event_pipe_ = ecore_pipe_add( [](void *data, void *buffer, unsigned int nbyte) -> void { auto *self = static_cast(data); @@ -138,6 +139,34 @@ VideoPlayer::VideoPlayer(flutter::PluginRegistrar *plugin_registrar, throw VideoPlayerError("player_create failed", get_error_message(ret)); } + if (!http_headers.empty()) { + auto iter = http_headers.find(flutter::EncodableValue("Cookie")); + if (iter != http_headers.end()) { + if (std::holds_alternative(iter->second)) { + std::string cookie = std::get(iter->second); + ret = + player_set_streaming_cookie(player_, cookie.c_str(), cookie.size()); + if (ret != PLAYER_ERROR_NONE) { + LOG_ERROR("[MediaPlayer] player_set_streaming_cookie failed: %s.", + get_error_message(ret)); + } + } + } + + iter = http_headers.find(flutter::EncodableValue("User-Agent")); + if (iter != http_headers.end()) { + if (std::holds_alternative(iter->second)) { + std::string user_agent = std::get(iter->second); + ret = player_set_streaming_user_agent(player_, user_agent.c_str(), + user_agent.size()); + if (ret != PLAYER_ERROR_NONE) { + LOG_ERROR("[MediaPlayer] player_set_streaming_user_agent failed: %s.", + get_error_message(ret)); + } + } + } + } + ret = player_set_uri(player_, uri.c_str()); if (ret != PLAYER_ERROR_NONE) { player_destroy(player_); diff --git a/packages/video_player/tizen/src/video_player.h b/packages/video_player/tizen/src/video_player.h index 16dc85ad2..1709f4c25 100644 --- a/packages/video_player/tizen/src/video_player.h +++ b/packages/video_player/tizen/src/video_player.h @@ -30,7 +30,8 @@ class VideoPlayer { explicit VideoPlayer(flutter::PluginRegistrar *plugin_registrar, flutter::TextureRegistrar *texture_registrar, - const std::string &uri, VideoPlayerOptions &options); + const std::string &uri, VideoPlayerOptions &options, + flutter::EncodableMap &http_headers); ~VideoPlayer(); void Play(); diff --git a/packages/video_player/tizen/src/video_player_tizen_plugin.cc b/packages/video_player/tizen/src/video_player_tizen_plugin.cc index 60f2920cf..29504b857 100644 --- a/packages/video_player/tizen/src/video_player_tizen_plugin.cc +++ b/packages/video_player/tizen/src/video_player_tizen_plugin.cc @@ -5,6 +5,7 @@ #include "video_player_tizen_plugin.h" #include +#include #include #include @@ -84,6 +85,8 @@ std::optional VideoPlayerTizenPlugin::Initialize() { ErrorOr VideoPlayerTizenPlugin::Create( const CreateMessage &msg) { std::string uri; + flutter::EncodableMap http_headers = {}; + if (msg.asset() && !msg.asset()->empty()) { char *res_path = app_get_resource_path(); if (res_path) { @@ -94,6 +97,11 @@ ErrorOr VideoPlayerTizenPlugin::Create( } } else if (msg.uri() && !msg.uri()->empty()) { uri = *msg.uri(); + + const flutter::EncodableMap &http_headers_map = msg.http_headers(); + if (!http_headers_map.empty()) { + http_headers = http_headers_map; + } } else { return FlutterError("Invalid argument", "Either asset or uri must be set."); } @@ -102,7 +110,7 @@ ErrorOr VideoPlayerTizenPlugin::Create( int64_t texture_id = 0; try { auto player = std::make_unique( - plugin_registrar_, texture_registrar_, uri, options_); + plugin_registrar_, texture_registrar_, uri, options_, http_headers); texture_id = player->GetTextureId(); players_[texture_id] = std::move(player); } catch (const VideoPlayerError &error) {