on 02fa86a help sign in
unity8/qml/Components/MediaServices/VideoPlayerControls.qml
140 lines 4.3 kB history raw
1import QtQuick 2.0
2import QtQuick.Layouts 1.1
3import QtMultimedia 5.0
4import Ubuntu.Components 1.3
5import Ubuntu.Components.Themes 1.0
7MediaServicesControls {
8 id: root
9 readonly property alias mediaPlayer: _mediaPlayer
10 property bool interacting: false
12 QtObject {
13 id: priv
15 function formatProgress(time) {
16 time = Math.floor(time / 1000);
18 var secs = time % 60;
19 time = Math.floor(time / 60);
20 var min = time % 60;
21 var hour = Math.floor(time / 60);
23 if (secs < 10) secs = "0%1".arg(secs);
24 if (min < 10) min = "0%1".arg(min);
25 if (hour > 0) {
26 // TRANSLATORS: this refers to a duration/remaining time of the video in hours, minutes and seconds,
27 // of which you can change the order.
28 // %1 refers to hours, %2 refers to minutes and %3 refers to seconds.
29 return i18n.tr("%1:%2:%3").arg(hour).arg(min).arg(secs);
30 } else {
31 // TRANSLATORS: this refers to a duration/remaining time of the video in minutes and seconds,
32 // of which you can change the order.
33 // %1 refers to minutes and %2 refers to seconds.
34 return i18n.tr("%1:%2").arg(min).arg(secs);
35 }
36 }
37 }
39 component: Item {
40 Connections {
41 target: mediaPlayer
42 onPositionChanged: {
43 if (slider.valueGuard) return;
45 slider.valueGuard = true;
46 slider.value = mediaPlayer.position;
47 slider.valueGuard = false;
48 if (!slider.pressed) {
49 positionLabel.text = priv.formatProgress(mediaPlayer.position);
50 }
51 }
52 }
54 Binding {
55 target: root
56 property: "interacting"
57 value: slider.pressed
58 }
60 Label {
61 id: positionLabel
62 anchors {
63 left: parent.left
64 bottom: parent.bottom
65 bottomMargin: -units.dp(3)
66 }
67 verticalAlignment: Text.AlignBottom
68 fontSize: "x-small"
69 color: "#F3F3E7"
71 text: priv.formatProgress(mediaPlayer.position)
72 }
74 Slider {
75 id: slider
76 property bool valueGuard: false
78 anchors {
79 left: parent.left
80 right: parent.right
81 }
82 height: units.gu(2)
83 live: true
84 enabled: mediaPlayer.seekable && mediaPlayer.duration > 0
85 minimumValue: 0
86 maximumValue: mediaPlayer.duration > 0 ? mediaPlayer.duration : 1
87 value: mediaPlayer.position
88 theme: ThemeSettings {
89 palette: Palette {
90 normal.base: "#F3F3E7"
91 }
92 }
94 onValueChanged: {
95 if (!pressed) return;
96 if (slider.valueGuard) return;
98 slider.valueGuard = true;
99 mediaPlayer.seek(value);
100 slider.valueGuard = false;
101 }
103 property bool wasPlaying: mediaPlayer.playbackState === MediaPlayer.PlayingState
104 onPressedChanged: {
105 if (pressed) {
106 wasPlaying = mediaPlayer.playbackState === MediaPlayer.PlayingState
107 mediaPlayer.pause();
108 } else {
110 positionLabel.text = priv.formatProgress(mediaPlayer.position);
111 if (wasPlaying) {
112 mediaPlayer.play();
113 }
114 }
115 }
117 function formatValue(value) {
118 return priv.formatProgress(value);
119 }
120 }
122 Label {
123 anchors {
124 right: parent.right
125 bottom: parent.bottom
126 bottomMargin: -units.dp(3)
127 }
128 verticalAlignment: Text.AlignBottom
129 fontSize: "x-small"
130 color: "#F3F3E7"
132 text: priv.formatProgress(mediaPlayer.duration)
133 }
134 }
136 MediaPlayer {
137 id: _mediaPlayer
138 objectName: "mediaPlayer"
139 }