diff --git a/packages/video_player_avplayer/README.md b/packages/video_player_avplayer/README.md index 5e03afb44..6e6d3c2b3 100644 --- a/packages/video_player_avplayer/README.md +++ b/packages/video_player_avplayer/README.md @@ -114,12 +114,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. diff --git a/packages/video_player_avplayer/tizen/src/media_player.cc b/packages/video_player_avplayer/tizen/src/media_player.cc index e9861af7e..c4055de2c 100644 --- a/packages/video_player_avplayer/tizen/src/media_player.cc +++ b/packages/video_player_avplayer/tizen/src/media_player.cc @@ -32,7 +32,8 @@ MediaPlayer::~MediaPlayer() { Dispose(); } int64_t MediaPlayer::Create(const std::string &uri, int drm_type, const std::string &license_server_url, - bool is_prebuffer_mode) { + bool is_prebuffer_mode, + flutter::EncodableMap &http_headers) { LOG_INFO("[MediaPlayer] uri: %s, drm_type: %d.", uri.c_str(), drm_type); if (uri.empty()) { @@ -47,6 +48,34 @@ int64_t MediaPlayer::Create(const std::string &uri, int drm_type, return -1; } + 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)); + } + } + } + } + if (drm_type != 0) { if (!SetDrm(uri, drm_type, license_server_url)) { LOG_ERROR("[MediaPlayer] Failed to set drm."); diff --git a/packages/video_player_avplayer/tizen/src/media_player.h b/packages/video_player_avplayer/tizen/src/media_player.h index b695b390d..042ec9d45 100644 --- a/packages/video_player_avplayer/tizen/src/media_player.h +++ b/packages/video_player_avplayer/tizen/src/media_player.h @@ -22,8 +22,8 @@ class MediaPlayer : public VideoPlayer { ~MediaPlayer(); int64_t Create(const std::string &uri, int drm_type, - const std::string &license_server_url, - bool is_prebuffer_mode) override; + const std::string &license_server_url, bool is_prebuffer_mode, + flutter::EncodableMap &http_headers) override; void Dispose() override; void SetDisplayRoi(int32_t x, int32_t y, int32_t width, diff --git a/packages/video_player_avplayer/tizen/src/plus_player.cc b/packages/video_player_avplayer/tizen/src/plus_player.cc index 75930090d..f7a0f81c2 100644 --- a/packages/video_player_avplayer/tizen/src/plus_player.cc +++ b/packages/video_player_avplayer/tizen/src/plus_player.cc @@ -33,7 +33,8 @@ PlusPlayer::~PlusPlayer() { Dispose(); } int64_t PlusPlayer::Create(const std::string &uri, int drm_type, const std::string &license_server_url, - bool is_prebuffer_mode) { + bool is_prebuffer_mode, + flutter::EncodableMap &http_headers) { LOG_INFO("[PlusPlayer] Create player."); if (!video_format_.compare("dash")) { player_ = plusplayer::PlusPlayer::Create(plusplayer::PlayerType::kDASH); @@ -46,6 +47,24 @@ int64_t PlusPlayer::Create(const std::string &uri, int drm_type, return -1; } + 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); + player_->SetStreamingProperty("COOKIE", cookie); + } + } + + 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); + player_->SetStreamingProperty("USER_AGENT", user_agent); + } + } + } + if (!player_->Open(uri)) { LOG_ERROR("[PlusPlayer] Fail to open uri : %s.", uri.c_str()); return -1; diff --git a/packages/video_player_avplayer/tizen/src/plus_player.h b/packages/video_player_avplayer/tizen/src/plus_player.h index 2c04c8c9e..5e20a12ae 100644 --- a/packages/video_player_avplayer/tizen/src/plus_player.h +++ b/packages/video_player_avplayer/tizen/src/plus_player.h @@ -22,8 +22,8 @@ class PlusPlayer : public VideoPlayer, public plusplayer::EventListener { ~PlusPlayer(); int64_t Create(const std::string &uri, int drm_type, - const std::string &license_server_url, - bool is_prebuffer_mode) override; + const std::string &license_server_url, bool is_prebuffer_mode, + flutter::EncodableMap &http_headers) override; void Dispose() override; void SetDisplayRoi(int32_t x, int32_t y, int32_t width, diff --git a/packages/video_player_avplayer/tizen/src/video_player.h b/packages/video_player_avplayer/tizen/src/video_player.h index 4bad1c911..53d3c3154 100644 --- a/packages/video_player_avplayer/tizen/src/video_player.h +++ b/packages/video_player_avplayer/tizen/src/video_player.h @@ -29,7 +29,8 @@ class VideoPlayer { virtual int64_t Create(const std::string &uri, int drm_type, const std::string &license_server_url, - bool is_prebuffer_mode) = 0; + bool is_prebuffer_mode, + flutter::EncodableMap &http_headers) = 0; virtual void Dispose() = 0; virtual void SetDisplayRoi(int32_t x, int32_t y, int32_t width, diff --git a/packages/video_player_avplayer/tizen/src/video_player_tizen_plugin.cc b/packages/video_player_avplayer/tizen/src/video_player_tizen_plugin.cc index 2d8b2cb85..29a129b7d 100644 --- a/packages/video_player_avplayer/tizen/src/video_player_tizen_plugin.cc +++ b/packages/video_player_avplayer/tizen/src/video_player_tizen_plugin.cc @@ -120,6 +120,7 @@ ErrorOr VideoPlayerTizenPlugin::Create( std::string license_server_url; bool prebuffer_mode; std::string format; + flutter::EncodableMap http_headers = {}; if (msg.asset() && !msg.asset()->empty()) { char *res_path = app_get_resource_path(); @@ -161,6 +162,12 @@ 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."); } @@ -169,14 +176,14 @@ ErrorOr VideoPlayerTizenPlugin::Create( if (uri.substr(0, 4) == "http") { auto player = std::make_unique(plugin_registrar_->messenger(), native_window, format); - player_id = - player->Create(uri, drm_type, license_server_url, prebuffer_mode); + player_id = player->Create(uri, drm_type, license_server_url, + prebuffer_mode, http_headers); players_[player_id] = std::move(player); } else { auto player = std::make_unique(plugin_registrar_->messenger(), native_window); - player_id = - player->Create(uri, drm_type, license_server_url, prebuffer_mode); + player_id = player->Create(uri, drm_type, license_server_url, + prebuffer_mode, http_headers); players_[player_id] = std::move(player); }