2 * Copyright (C) 2015 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/>.
19 import QtMultimedia 5.6
23 readonly property real progress: audio.position / audio.duration
24 readonly property bool playing: audio.playbackState === Audio.PlayingState
25 readonly property bool paused: audio.playbackState === Audio.PausedState
26 readonly property bool stopped: audio.playbackState === Audio.StoppedState
27 readonly property alias position: audio.position
28 readonly property url currentSource: audio.playlist.currentItemSource
30 function playSource(newSource, newPlaylist) {
32 audio.playlist.clear();
34 // Look for newSource in newPlaylist
36 for (var i in newPlaylist) {
37 if (AudioUrlComparer.compare(newSource, newPlaylist[i])) {
43 if (sourceIndex === -1 && newSource != "") {
44 // If the playing song is not in the playlist, add it
48 for (var i in newPlaylist) {
49 urls.push(newPlaylist[i]);
51 audio.playlist.addItems(urls);
52 audio.playlist.currentIndex = sourceIndex;
54 audio.playlist.addItem(newSource);
55 audio.playlist.currentIndex = 0;
72 property QtObject audio: Audio {
76 objectName: "playlist"
79 onErrorStringChanged: console.warn("Dash Audio player error:", errorString)
82 function lengthToString(s) {
83 if (typeof(s) !== "number" || s < 0) return "";
85 var sec = "" + s % 60;
86 if (sec.length == 1) sec = "0" + sec;
87 var hour = Math.floor(s / 3600);
89 return Math.floor(s / 60) + ":" + sec;
91 var min = "" + Math.floor(s / 60) % 60;
92 if (min.length == 1) min = "0" + min;
93 return hour + ":" + min + ":" + sec;