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] Support httpHeaders option of VideoPlayerController.network #751

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions packages/video_player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion packages/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 30 additions & 1 deletion packages/video_player/tizen/src/video_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<VideoPlayer *>(data);
Expand All @@ -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<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));
}
}
}
}

ret = player_set_uri(player_, uri.c_str());
if (ret != PLAYER_ERROR_NONE) {
player_destroy(player_);
Expand Down
3 changes: 2 additions & 1 deletion packages/video_player/tizen/src/video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion packages/video_player/tizen/src/video_player_tizen_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "video_player_tizen_plugin.h"

#include <app_common.h>
#include <flutter/encodable_value.h>
#include <flutter/plugin_registrar.h>

#include <cstdint>
Expand Down Expand Up @@ -84,6 +85,8 @@ std::optional<FlutterError> VideoPlayerTizenPlugin::Initialize() {
ErrorOr<TextureMessage> 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) {
Expand All @@ -94,6 +97,11 @@ ErrorOr<TextureMessage> 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.");
}
Expand All @@ -102,7 +110,7 @@ ErrorOr<TextureMessage> VideoPlayerTizenPlugin::Create(
int64_t texture_id = 0;
try {
auto player = std::make_unique<VideoPlayer>(
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) {
Expand Down
Loading