From 2f57d9bb4f6f71379f6b0180081be881e75d327c Mon Sep 17 00:00:00 2001 From: "yue7.huang" Date: Fri, 27 Oct 2023 15:30:02 +0800 Subject: [PATCH 1/4] Implement set cookies --- .../tizen/src/video_player.cc | 31 ++++++++++++++++++- .../tizen/src/video_player.h | 3 +- .../tizen/src/video_player_tizen_plugin.cc | 9 +++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/video_player_videohole/tizen/src/video_player.cc b/packages/video_player_videohole/tizen/src/video_player.cc index 7c2f12e16..7fb6c4b88 100644 --- a/packages/video_player_videohole/tizen/src/video_player.cc +++ b/packages/video_player_videohole/tizen/src/video_player.cc @@ -75,7 +75,8 @@ bool VideoPlayer::SetDisplay() { } int64_t VideoPlayer::Create(const std::string &uri, int drm_type, - const std::string &license_server_url) { + const std::string &license_server_url, + flutter::EncodableMap &http_headers) { LOG_INFO("[VideoPlayer] uri: %s, drm_type: %d", uri.c_str(), drm_type); player_id_ = player_index++; @@ -105,6 +106,34 @@ int64_t VideoPlayer::Create(const std::string &uri, int drm_type, } } + 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) { LOG_ERROR("[VideoPlayer] player_set_uri failed: %s", diff --git a/packages/video_player_videohole/tizen/src/video_player.h b/packages/video_player_videohole/tizen/src/video_player.h index 077559c99..0436ec187 100644 --- a/packages/video_player_videohole/tizen/src/video_player.h +++ b/packages/video_player_videohole/tizen/src/video_player.h @@ -34,7 +34,8 @@ class VideoPlayer { ~VideoPlayer(); int64_t Create(const std::string &uri, int drm_type, - const std::string &license_server_url); + const std::string &license_server_url, + flutter::EncodableMap &http_headers); void Dispose(); void SetDisplayRoi(int32_t x, int32_t y, int32_t width, int32_t height); diff --git a/packages/video_player_videohole/tizen/src/video_player_tizen_plugin.cc b/packages/video_player_videohole/tizen/src/video_player_tizen_plugin.cc index b72ae520a..af77473da 100644 --- a/packages/video_player_videohole/tizen/src/video_player_tizen_plugin.cc +++ b/packages/video_player_videohole/tizen/src/video_player_tizen_plugin.cc @@ -115,6 +115,7 @@ ErrorOr VideoPlayerTizenPlugin::Create( std::string uri; int32_t drm_type = 0; // DRM_TYPE_NONE std::string license_server_url; + flutter::EncodableMap http_headers = {}; if (msg.asset() && !msg.asset()->empty()) { char *res_path = app_get_resource_path(); @@ -142,11 +143,17 @@ ErrorOr VideoPlayerTizenPlugin::Create( } } } + + const flutter::EncodableMap *http_headers_map = msg.http_headers(); + if (http_headers_map) { + http_headers = *http_headers_map; + } } else { return FlutterError("Invalid argument", "Either asset or uri must be set."); } - int64_t player_id = player->Create(uri, drm_type, license_server_url); + int64_t player_id = + player->Create(uri, drm_type, license_server_url, http_headers); if (player_id == -1) { return FlutterError("Operation failed", "Failed to create a player."); } From 3c59fd3b38398696742c2fa50dcebb909bb0871c Mon Sep 17 00:00:00 2001 From: "yue7.huang" Date: Fri, 17 Nov 2023 11:05:07 +0800 Subject: [PATCH 2/4] Update README and CHANGELOG --- packages/video_player_videohole/CHANGELOG.md | 4 ++++ packages/video_player_videohole/README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/video_player_videohole/CHANGELOG.md b/packages/video_player_videohole/CHANGELOG.md index 07752697b..2e0cecd94 100644 --- a/packages/video_player_videohole/CHANGELOG.md +++ b/packages/video_player_videohole/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.0 + +* Implement `httpHeaders` of `VideoPlayerController.network`. + ## 0.2.0 * Implement functionality of selecting video, audio and text tracks. diff --git a/packages/video_player_videohole/README.md b/packages/video_player_videohole/README.md index 252c1cd97..0d26bf8b9 100644 --- a/packages/video_player_videohole/README.md +++ b/packages/video_player_videohole/README.md @@ -112,12 +112,12 @@ TV emulator support is experimental. DRM content playback is not supported on TV The following options are not currently supported. -- The `httpHeaders` option of `VideoPlayerController.network` - `VideoPlayerOptions.allowBackgroundPlayback` - `VideoPlayerOptions.mixWithOthers` This plugin has the following limitations. +- The `httpHeaders` option of `VideoPlayerController.network` 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. From 9725753b774b557da63e4db84affc54a6642f83f Mon Sep 17 00:00:00 2001 From: "yue7.huang" Date: Tue, 21 Nov 2023 13:57:27 +0800 Subject: [PATCH 3/4] Extract a method to get value from EncodableMap --- .../tizen/src/video_player.cc | 50 +++++++++++-------- .../tizen/src/video_player.h | 2 +- .../tizen/src/video_player_tizen_plugin.cc | 7 +-- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/packages/video_player_videohole/tizen/src/video_player.cc b/packages/video_player_videohole/tizen/src/video_player.cc index 0e0e33024..4bbc25dd9 100644 --- a/packages/video_player_videohole/tizen/src/video_player.cc +++ b/packages/video_player_videohole/tizen/src/video_player.cc @@ -15,6 +15,19 @@ static int64_t player_index = 1; +template +static bool GetValueFromEncodableMap(const flutter::EncodableMap *map, + const char *key, T &out) { + auto iter = map->find(flutter::EncodableValue(key)); + if (iter != map->end()) { + if (std::holds_alternative(iter->second)) { + out = std::get(iter->second); + return true; + } + } + return false; +} + VideoPlayer::VideoPlayer(flutter::PluginRegistrar *plugin_registrar, void *native_window) : plugin_registrar_(plugin_registrar), native_window_(native_window) { @@ -122,7 +135,7 @@ bool VideoPlayer::SetDisplay() { int64_t VideoPlayer::Create(const std::string &uri, int drm_type, const std::string &license_server_url, - flutter::EncodableMap &http_headers) { + const flutter::EncodableMap *http_headers) { LOG_INFO("[VideoPlayer] uri: %s, drm_type: %d", uri.c_str(), drm_type); player_id_ = player_index++; @@ -152,30 +165,23 @@ int64_t VideoPlayer::Create(const std::string &uri, int drm_type, } } - 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)); - } + if (http_headers && !http_headers->empty()) { + std::string cookie; + if (GetValueFromEncodableMap(http_headers, "Cookie", cookie)) { + 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)); - } + std::string user_agent; + if (GetValueFromEncodableMap(http_headers, "User-Agent", user_agent)) { + 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)); } } } diff --git a/packages/video_player_videohole/tizen/src/video_player.h b/packages/video_player_videohole/tizen/src/video_player.h index 077024b80..0eb02900e 100644 --- a/packages/video_player_videohole/tizen/src/video_player.h +++ b/packages/video_player_videohole/tizen/src/video_player.h @@ -76,7 +76,7 @@ class VideoPlayer { int64_t Create(const std::string &uri, int drm_type, const std::string &license_server_url, - flutter::EncodableMap &http_headers); + const flutter::EncodableMap *http_headers); void Dispose(); void SetDisplayRoi(int32_t x, int32_t y, int32_t width, int32_t height); diff --git a/packages/video_player_videohole/tizen/src/video_player_tizen_plugin.cc b/packages/video_player_videohole/tizen/src/video_player_tizen_plugin.cc index 5a0ffd663..e32bad05e 100644 --- a/packages/video_player_videohole/tizen/src/video_player_tizen_plugin.cc +++ b/packages/video_player_videohole/tizen/src/video_player_tizen_plugin.cc @@ -118,7 +118,7 @@ ErrorOr VideoPlayerTizenPlugin::Create( std::string uri; int32_t drm_type = 0; // DRM_TYPE_NONE std::string license_server_url; - flutter::EncodableMap http_headers = {}; + const flutter::EncodableMap *http_headers = nullptr; if (msg.asset() && !msg.asset()->empty()) { char *res_path = app_get_resource_path(); @@ -147,10 +147,7 @@ ErrorOr VideoPlayerTizenPlugin::Create( } } - const flutter::EncodableMap *http_headers_map = msg.http_headers(); - if (http_headers_map) { - http_headers = *http_headers_map; - } + http_headers = msg.http_headers(); } else { return FlutterError("Invalid argument", "Either asset or uri must be set."); } From 4cac49d17b83284f2c237a751febd2650d346493 Mon Sep 17 00:00:00 2001 From: "yue7.huang" Date: Thu, 23 Nov 2023 11:43:51 +0800 Subject: [PATCH 4/4] Minor update --- packages/video_player_videohole/README.md | 2 +- packages/video_player_videohole/example/lib/main.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/video_player_videohole/README.md b/packages/video_player_videohole/README.md index 0d26bf8b9..0f79a937c 100644 --- a/packages/video_player_videohole/README.md +++ b/packages/video_player_videohole/README.md @@ -12,7 +12,7 @@ To use this package, add `video_player_videohole` as a dependency in your `pubsp ```yaml dependencies: - video_player_videohole: ^0.2.0 + video_player_videohole: ^0.3.0 ``` Then you can import `video_player_videohole` in your Dart code: diff --git a/packages/video_player_videohole/example/lib/main.dart b/packages/video_player_videohole/example/lib/main.dart index 873360c4d..d65a58f77 100644 --- a/packages/video_player_videohole/example/lib/main.dart +++ b/packages/video_player_videohole/example/lib/main.dart @@ -24,7 +24,7 @@ class _App extends StatelessWidget { @override Widget build(BuildContext context) { return DefaultTabController( - length: 5, + length: 6, child: Scaffold( key: const ValueKey('home_page'), appBar: AppBar(