@@ -15,8 +15,8 @@
17import QtQuick 2.0
17import QtQuick 2.0
18−import QtMultimedia 5.0
19import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19+import "../DashAudioPlayer"
21/*! \brief Preview widget for audio tracks.
21/*! \brief Preview widget for audio tracks.
@@ -36,38 +36,6 @@ PreviewWidget {
37 height: childrenRect.height
37 height: childrenRect.height
39− onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
45− property real progress: audio.position / audio.duration
46− property Item playingItem
48− Component.onDestruction: {
49− // destroying the component doesn't automatically send stop to the media service, probably a bug in QtMultimedia
53− onErrorStringChanged: console.warn("Audio player error:", errorString)
55− function lengthToString(s) {
56− if (typeof(s) !== "number" || s <= 0) return "";
58− var sec = "" + s % 60;
59− if (sec.length == 1) sec = "0" + sec;
60− var hour = Math.floor(s / 3600);
62− return Math.floor(s / 60) + ":" + sec;
64− var min = "" + Math.floor(s / 60) % 60;
65− if (min.length == 1) min = "0" + min;
66− return hour + ":" + min + ":" + sec;
72 anchors { left: parent.left; right: parent.right }
40 anchors { left: parent.left; right: parent.right }
73 visible: trackRepeater.count > 0
41 visible: trackRepeater.count > 0
@@ -78,19 +46,19 @@ PreviewWidget {
78 model: root.widgetData["tracks"]
46 model: root.widgetData["tracks"]
80 function play(item, source) {
48 function play(item, source) {
81− audio.stop();
49+ DashAudioPlayer.stop();
82 // Make sure we change the source, even if two items point to the same uri location
50 // Make sure we change the source, even if two items point to the same uri location
83− audio.source = "";
51+ DashAudioPlayer.source = "";
84− audio.source = source;
52+ DashAudioPlayer.source = source;
85− audio.playingItem = item;
53+ DashAudioPlayer.play();
89 delegate: Item {
56 delegate: Item {
90 id: trackItem
57 id: trackItem
91 objectName: "trackItem" + index
58 objectName: "trackItem" + index
60+ readonly property url sourceUrl: modelData["source"]
93− property bool isPlayingItem: audio.playingItem == trackItem
61+ readonly property bool isPlayingItem: DashAudioPlayer.source == sourceUrl
95 anchors { left: parent.left; right: parent.right }
63 anchors { left: parent.left; right: parent.right }
96 height: units.gu(5)
64 height: units.gu(5)
@@ -98,9 +66,9 @@ PreviewWidget {
99 id: trackRow
67 id: trackRow
101− property int column1Width: units.gu(3)
69+ readonly property int column1Width: units.gu(3)
102− property int column2Width: width - (2 * spacing) - column1Width - column3Width
70+ readonly property int column2Width: width - (2 * spacing) - column1Width - column3Width
103− property int column3Width: units.gu(4)
71+ readonly property int column3Width: units.gu(4)
105 anchors.verticalCenter: parent.verticalCenter
73 anchors.verticalCenter: parent.verticalCenter
106 width: parent.width
74 width: parent.width
@@ -110,7 +78,7 @@ PreviewWidget {
110 objectName: "playButton"
78 objectName: "playButton"
111 width: trackRow.column1Width
79 width: trackRow.column1Width
112 height: width
80 height: width
113− iconSource: audio.playbackState == Audio.PlayingState && trackItem.isPlayingItem ? "image://theme/media-playback-pause" : "image://theme/media-playback-start"
81+ iconSource: DashAudioPlayer.playing && trackItem.isPlayingItem ? "image://theme/media-playback-pause" : "image://theme/media-playback-start"
115 // Can't be "transparent" or "#00xxxxxx" as the button optimizes away the surrounding shape
83 // Can't be "transparent" or "#00xxxxxx" as the button optimizes away the surrounding shape
116 // FIXME when this is resolved: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1251685
84 // FIXME when this is resolved: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1251685
@@ -118,13 +86,13 @@ PreviewWidget {
119 onClicked: {
87 onClicked: {
120 if (trackItem.isPlayingItem) {
88 if (trackItem.isPlayingItem) {
121− if (audio.playbackState == Audio.PlayingState) {
89+ if (DashAudioPlayer.playing) {
122− audio.pause();
90+ DashAudioPlayer.pause();
123− } else if (audio.playbackState == Audio.PausedState) {
91+ } else if (DashAudioPlayer.paused) {
124− audio.play();
92+ DashAudioPlayer.play();
127− trackRepeater.play(trackItem, modelData["source"]);
95+ trackRepeater.play(trackItem, sourceUrl);
@@ -164,14 +132,14 @@ PreviewWidget {
164 id: progressBarFill
132 id: progressBarFill
165 objectName: "progressBarFill"
133 objectName: "progressBarFill"
167− property int maxWidth: progressBarImage.width - units.dp(4)
135+ readonly property int maxWidth: progressBarImage.width - units.dp(4)
169 anchors {
137 anchors {
170 left: progressBarImage.left
138 left: progressBarImage.left
171 right: progressBarImage.right
139 right: progressBarImage.right
172 verticalCenter: progressBarImage.verticalCenter
140 verticalCenter: progressBarImage.verticalCenter
173 margins: units.dp(2)
141 margins: units.dp(2)
174− rightMargin: maxWidth - (maxWidth * audio.progress) + units.dp(2)
142+ rightMargin: maxWidth - (maxWidth * DashAudioPlayer.progress) + units.dp(2)
176 height: units.dp(2)
144 height: units.dp(2)
177 visible: progressBarImage.visible
145 visible: progressBarImage.visible
@@ -182,7 +150,7 @@ PreviewWidget {
182 id: progressBarImage
150 id: progressBarImage
183 anchors { left: parent.left; top: parent.bottom; right: parent.right }
151 anchors { left: parent.left; top: parent.bottom; right: parent.right }
184 height: units.dp(6)
152 height: units.dp(6)
185− visible: audio.playbackState != Audio.StoppedState && trackItem.isPlayingItem && modelData["length"] > 0
153+ visible: !DashAudioPlayer.stopped && trackItem.isPlayingItem && modelData["length"] > 0
186 source: "graphics/music_progress_bg.png"
154 source: "graphics/music_progress_bg.png"
@@ -196,7 +164,7 @@ PreviewWidget {
196 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
164 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
197 fontSize: "small"
165 fontSize: "small"
198 horizontalAlignment: Text.AlignRight
166 horizontalAlignment: Text.AlignRight
199− text: audio.lengthToString(modelData["length"])
167+ text: DashAudioPlayer.lengthToString(modelData["length"])