[video_player] Improve error handling (#23)
Improved an error handling when getting current position.
This commit is contained in:
committed by
GitHub
parent
971dd0e2c1
commit
dd294a8803
@@ -96,9 +96,14 @@ bool GstVideoPlayer::SetPlaybackRate(double rate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto position = GetCurrentPosition();
|
||||
if (position < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!gst_element_seek(gst_.pipeline, rate, GST_FORMAT_TIME,
|
||||
GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET,
|
||||
GetCurrentPosition() * GST_MSECOND, GST_SEEK_TYPE_SET,
|
||||
position * GST_MSECOND, GST_SEEK_TYPE_SET,
|
||||
GST_CLOCK_TIME_NONE)) {
|
||||
std::cerr << "Failed to set playback rate to " << rate
|
||||
<< " (gst_element_seek failed)" << std::endl;
|
||||
@@ -138,8 +143,11 @@ int64_t GstVideoPlayer::GetDuration() {
|
||||
|
||||
int64_t GstVideoPlayer::GetCurrentPosition() {
|
||||
gint64 position = 0;
|
||||
|
||||
// Sometimes we get an error when playing streaming videos.
|
||||
if (!gst_element_query_position(gst_.pipeline, GST_FORMAT_TIME, &position)) {
|
||||
std::cerr << "Failed to get current position" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: We need to handle this code in the proper plase.
|
||||
|
||||
@@ -484,12 +484,19 @@ void VideoPlayerPlugin::HandlePositionMethodCall(
|
||||
flutter::EncodableMap result;
|
||||
|
||||
if (players_.find(texture_id) != players_.end()) {
|
||||
PositionMessage send_message;
|
||||
send_message.SetTextureId(texture_id);
|
||||
send_message.SetPosition(
|
||||
players_[texture_id]->player->GetCurrentPosition());
|
||||
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
|
||||
send_message.ToMap());
|
||||
auto position = players_[texture_id]->player->GetCurrentPosition();
|
||||
if (position < 0) {
|
||||
auto error_message = "Failed to get current position with texture id: " +
|
||||
std::to_string(texture_id);
|
||||
result.emplace(flutter::EncodableValue(kEncodableMapkeyError),
|
||||
flutter::EncodableValue(WrapError(error_message)));
|
||||
} else {
|
||||
PositionMessage send_message;
|
||||
send_message.SetTextureId(texture_id);
|
||||
send_message.SetPosition(position);
|
||||
result.emplace(flutter::EncodableValue(kEncodableMapkeyResult),
|
||||
send_message.ToMap());
|
||||
}
|
||||
} else {
|
||||
auto error_message = "Couldn't find the player with texture id: " +
|
||||
std::to_string(texture_id);
|
||||
|
||||
Reference in New Issue
Block a user