2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
import QtQuick.Layouts 1.1
19
import QtMultimedia 5.0
20
import Ubuntu.Components 1.3
22
MediaServicesControls {
24
readonly property alias mediaPlayer: _mediaPlayer
25
property bool interacting: false
30
function formatProgress(time) {
31
time = Math.floor(time / 1000);
34
time = Math.floor(time / 60);
36
var hour = Math.floor(time / 60);
38
if (secs < 10) secs = "0%1".arg(secs);
39
if (min < 10) min = "0%1".arg(min);
41
// TRANSLATORS: this refers to a duration/remaining time of the video in hours, minutes and seconds,
42
// of which you can change the order.
43
// %1 refers to hours, %2 refers to minutes and %3 refers to seconds.
44
return i18n.tr("%1:%2:%3").arg(hour).arg(min).arg(secs);
46
// TRANSLATORS: this refers to a duration/remaining time of the video in minutes and seconds,
47
// of which you can change the order.
48
// %1 refers to minutes and %2 refers to seconds.
49
return i18n.tr("%1:%2").arg(min).arg(secs);
58
if (slider.valueGuard) return;
60
slider.valueGuard = true;
61
slider.value = mediaPlayer.position;
62
slider.valueGuard = false;
63
if (!slider.pressed) {
64
positionLabel.text = priv.formatProgress(mediaPlayer.position);
71
property: "interacting"
80
bottomMargin: -units.dp(3)
82
verticalAlignment: Text.AlignBottom
86
text: priv.formatProgress(mediaPlayer.position)
91
property bool valueGuard: false
99
enabled: mediaPlayer.seekable && mediaPlayer.duration > 0
101
maximumValue: mediaPlayer.duration > 0 ? mediaPlayer.duration : 1
102
value: mediaPlayer.position
104
onStyleInstanceChanged: {
105
if (__styleInstance) __styleInstance.backgroundColor = root.iconColor;
109
if (!pressed || slider.valueGuard) return;
111
slider.valueGuard = true;
112
mediaPlayer.seek(value);
113
slider.valueGuard = false;
116
property bool wasPlaying: mediaPlayer.playbackState === MediaPlayer.PlayingState
119
wasPlaying = mediaPlayer.playbackState === MediaPlayer.PlayingState
122
positionLabel.text = priv.formatProgress(mediaPlayer.position);
129
function formatValue(value) {
130
return priv.formatProgress(value);
137
bottom: parent.bottom
138
bottomMargin: -units.dp(3)
140
verticalAlignment: Text.AlignBottom
142
color: root.iconColor
144
text: priv.formatProgress(mediaPlayer.duration)
150
objectName: "mediaPlayer"
153
if (error !== MediaPlayer.NoError) {