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] Live streaming content starts playing immediately when seekTo is called #742

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.2

* Live streaming content starts playing immediately when SeekTo() is called.

## 2.5.1

* Update pigeon to 22.3.0.
Expand Down
3 changes: 2 additions & 1 deletion packages/video_player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This package is not an _endorsed_ implementation of `video_player`. Therefore, y
```yaml
dependencies:
video_player: ^2.9.1
video_player_tizen: ^2.5.1
video_player_tizen: ^2.5.2
```

Then you can import `video_player` in your Dart code:
Expand Down Expand Up @@ -59,3 +59,4 @@ This plugin has some limitations on TV devices.
- 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.
- The live streaming content does not support `seekTo` and `duration` is fixed to 1.
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.1
version: 2.5.2

environment:
sdk: ">=3.3.0 <4.0.0"
Expand Down
31 changes: 21 additions & 10 deletions packages/video_player/tizen/src/video_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ VideoPlayer::VideoPlayer(flutter::PluginRegistrar *plugin_registrar,
player_destroy(player_);
throw VideoPlayerError("player_set_uri failed", get_error_message(ret));
}
uri_ = uri;

ret = player_set_display_visible(player_, true);
if (ret != PLAYER_ERROR_NONE) {
Expand Down Expand Up @@ -336,8 +337,15 @@ void VideoPlayer::SeekTo(int32_t position, SeekCompletedCallback callback) {
player_set_play_position(player_, position, true, OnSeekCompleted, this);
if (ret != PLAYER_ERROR_NONE) {
on_seek_completed_ = nullptr;
throw VideoPlayerError("player_set_play_position failed",
get_error_message(ret));
// TODO(jsuya):Live content does not provide a duration that allows
// SeekTo(), so we call Play() to start playback immediately from the
// current.
if (position == 0 && is_live_) {
Play();
} else {
throw VideoPlayerError("player_set_play_position failed",
get_error_message(ret));
}
}
}

Expand Down Expand Up @@ -442,6 +450,7 @@ void VideoPlayer::SendInitialized() {
SendError("player_get_duration failed", get_error_message(ret));
return;
}
duration_ = duration;
LOG_DEBUG("[VideoPlayer] Video duration: %d", duration);

int width = 0, height = 0;
Expand All @@ -465,21 +474,23 @@ void VideoPlayer::SendInitialized() {
}
}

// TODO(jsuya):Some streaming resources may have a duration of 0 during the
// initialization step. If the duration is 0, it may affect the progress of
// video_player and cause unnecessary errors. Therefore, set it to 1
// temporarily. In the future, It can be updated depending on
// the loading status.
if (width != 0 && height != 0 && duration == 0) {
duration = 1;
// TODO(jsuya):Tizen's player API returns duration as 0 for live
// streaming resources. If the duration is 0, it may affect the progress of
// video_player and cause unnecessary errors. Therefore, set it to 1.
if (uri_.substr(0, 4) == "http" && width != 0 && height != 0 &&
duration_ == 0) {
duration_ = 1;
is_live_ = true;
xiaowei-guan marked this conversation as resolved.
Show resolved Hide resolved
} else {
is_live_ = false;
}

is_initialized_ = true;
flutter::EncodableMap result = {
{flutter::EncodableValue("event"),
flutter::EncodableValue("initialized")},
{flutter::EncodableValue("duration"),
flutter::EncodableValue(duration)},
flutter::EncodableValue(duration_)},
{flutter::EncodableValue("width"), flutter::EncodableValue(width)},
{flutter::EncodableValue("height"), flutter::EncodableValue(height)},
};
Expand Down
3 changes: 3 additions & 0 deletions packages/video_player/tizen/src/video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ class VideoPlayer {

bool is_initialized_ = false;
bool is_rendering_ = false;
bool is_live_ = false;

std::unique_ptr<flutter::EventChannel<flutter::EncodableValue>>
event_channel_;
std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> event_sink_;

player_h player_ = nullptr;
int64_t texture_id_ = -1;
int32_t duration_ = 0;
std::string uri_;

flutter::TextureRegistrar *texture_registrar_;
std::unique_ptr<flutter::TextureVariant> texture_variant_;
Expand Down
Loading