Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[video_player_videohole] Implement 'httpHeaders' of 'VideoPlayerController.network'. #628

Merged
merged 7 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/video_player_videohole/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0

* Implement `httpHeaders` of `VideoPlayerController.network`.

## 0.2.0

* Implement functionality of selecting video, audio and text tracks.
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_videohole/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 30 additions & 1 deletion packages/video_player_videohole/tizen/src/video_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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++;
Expand Down Expand Up @@ -151,6 +152,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<std::string>(iter->second)) {
std::string cookie = std::get<std::string>(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<std::string>(iter->second)) {
std::string user_agent = std::get<std::string>(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));
}
}
}
}
xiaowei-guan marked this conversation as resolved.
Show resolved Hide resolved

ret = player_set_uri(player_, uri.c_str());
if (ret != PLAYER_ERROR_NONE) {
LOG_ERROR("[VideoPlayer] player_set_uri failed: %s",
Expand Down
3 changes: 2 additions & 1 deletion packages/video_player_videohole/tizen/src/video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ ErrorOr<PlayerMessage> 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();
Expand Down Expand Up @@ -145,11 +146,17 @@ ErrorOr<PlayerMessage> VideoPlayerTizenPlugin::Create(
}
}
}

const flutter::EncodableMap *http_headers_map = msg.http_headers();
if (http_headers_map) {
http_headers = *http_headers_map;
xiaowei-guan marked this conversation as resolved.
Show resolved Hide resolved
}
} 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.");
}
Expand Down