summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/video/mediaplayer
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-07-28 09:55:48 +0200
committerLars Knoll <lars.knoll@qt.io>2021-07-30 09:54:16 +0200
commit82367bd22c3d6c793bf05d91b641a3356f687d5b (patch)
tree1f9a51406d197ad3f3d16a9b95c870b565bb8ce5 /examples/multimedia/video/mediaplayer
parenta0deb18c401971b58d2581e9431c6d976d926063 (diff)
Fix media player position handling after seeking on gstreamer
After calling setPosition() while being paused, gst_element_query_position() can return false while the pipeline is still prerolling the new position. So simply return the last position in that case instead of 0. Also moved some methods that are only used on the pipeline from QGstElement to QGstPipeline so that we can cache the position there without having to add data to every element. Fixes: QTBUG-95251 Change-Id: Ice56975fcf7d519f0dd54db75103b97b025cd085 Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples/multimedia/video/mediaplayer')
-rw-r--r--examples/multimedia/video/mediaplayer/PlaybackSeekControl.qml26
1 files changed, 6 insertions, 20 deletions
diff --git a/examples/multimedia/video/mediaplayer/PlaybackSeekControl.qml b/examples/multimedia/video/mediaplayer/PlaybackSeekControl.qml
index 9907f7c8a..5c04d1848 100644
--- a/examples/multimedia/video/mediaplayer/PlaybackSeekControl.qml
+++ b/examples/multimedia/video/mediaplayer/PlaybackSeekControl.qml
@@ -69,7 +69,11 @@ Item {
Layout.minimumWidth: 50
Layout.minimumHeight: 18
horizontalAlignment: Text.AlignRight
- text: "0:00.0"
+ text: {
+ var m = Math.floor(mediaPlayer.position / 60000)
+ var ms = (mediaPlayer.position / 1000 - m * 60).toFixed(1)
+ return `${m}:${ms.padStart(4, 0)}`
+ }
}
Slider {
@@ -77,27 +81,9 @@ Item {
Layout.fillWidth: true
enabled: mediaPlayer.seekable
to: 1.0
- value: 0.0
+ value: mediaPlayer.position / mediaPlayer.duration
onMoved: mediaPlayer.setPosition(value * mediaPlayer.duration)
}
}
-
- Timer {
- interval: 100; repeat: true; running: true;
- onTriggered: {
- if (mediaPlayerState != MediaPlayer.StoppedState) {
- mediaSlider.value = mediaPlayer.position / mediaPlayer.duration
- mediaTime.text = function(){
- var m = Math.floor(mediaPlayer.position / 60000)
- var ms = (mediaPlayer.position / 1000 - m * 60).toFixed(1)
- return `${m}:${ms.padStart(4, 0)}`
- }()
- } else {
- mediaSlider.value = 0.0
- mediaTime.text = "0:00.0"
- }
-
- }
- }
}