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