| 1 |
/* |
| 2 |
* Copyright (C) 2013 Canonical, Ltd. |
| 3 |
* |
| 4 |
* Authors: |
| 5 |
* Renato Araujo Oliveira Filho <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; version 3. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
import QtQuick 2.4 |
| 21 |
import QtMultimedia 5.0 |
| 22 |
import Lomiri.Components 1.3 |
| 23 |
import "../sdk" |
| 24 |
|
| 25 |
Slider { |
| 26 |
id: _slider |
| 27 |
objectName: "TimeLine.Slider" |
| 28 |
|
| 29 |
readonly property alias liveValue: _slider.value |
| 30 |
property real videoPosition: -1 |
| 31 |
property int playerStatus: MediaPlayer.NoMedia |
| 32 |
property string currentTime |
| 33 |
property string remainingTime |
| 34 |
property int finalSeekPosition: -1 |
| 35 |
|
| 36 |
signal clicked(bool insideThumb) |
| 37 |
|
| 38 |
function formatProgress(time) { |
| 39 |
var hour = 0 |
| 40 |
var min = 0 |
| 41 |
var secs = 0 |
| 42 |
time = Math.floor(time) |
| 43 |
|
| 44 |
secs = time % 60 |
| 45 |
time = Math.floor(time / 60) |
| 46 |
min = time % 60 |
| 47 |
hour = Math.floor(time / 60) |
| 48 |
|
| 49 |
if (secs < 10) secs = "0%1".arg(secs) |
| 50 |
if (min < 10) min = "0%1".arg(min) |
| 51 |
if (hour < 10) hour = "0%1".arg(hour) |
| 52 |
|
| 53 |
// TRANSLATORS: this refers to a duration/remaining time of the video, of which you can change the order. |
| 54 |
// %1 refers to hours, %2 refers to minutes and %3 refers to seconds. |
| 55 |
return i18n.tr("%1:%2:%3").arg(hour).arg(min).arg(secs) |
| 56 |
} |
| 57 |
|
| 58 |
style: VideoSlider {property Item item: _slider} |
| 59 |
minimumValue: 0 |
| 60 |
maximumValue: 1000 |
| 61 |
live: true |
| 62 |
|
| 63 |
onFinalSeekPosition: _slider.value = _slider.finalSeekPosition / 1000 |
| 64 |
|
| 65 |
onVideoPositionChanged: { |
| 66 |
if (_slider.playerStatus == MediaPlayer.EndOfMedia) |
| 67 |
{ |
| 68 |
// On EndOfMedia status, make sure the slider returns to the beginning |
| 69 |
_slider.value = 0 |
| 70 |
} else if (!_slider.pressed){ |
| 71 |
// Else, pass all new positions through to the slider UI |
| 72 |
if (_slider.videoPosition >= _slider.finalSeekPosition / 1000 || _slider.videoPosition == 0) { |
| 73 |
_slider.value = _slider.videoPosition |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
onValueChanged: { |
| 79 |
if (value >= 0) { |
| 80 |
_slider.currentTime = formatProgress(value) |
| 81 |
if (_slider.maximumValue > 0) { |
| 82 |
_slider.remainingTime = formatProgress(_slider.maximumValue - value) |
| 83 |
} else { |
| 84 |
// TRANSLATORS: this refers to an unknown duration. |
| 85 |
_slider.remainingTime = i18n.tr("unknown") |
| 86 |
} |
| 87 |
} else { |
| 88 |
_slider.currentTime = i18n.tr("0:00:00") |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
onTouched: { |
| 93 |
_slider.clicked(onThumb) |
| 94 |
} |
| 95 |
} |