@@ -15,8 +15,8 @@
1515 */
1616
1717import QtQuick 2.0
18−import QtMultimedia 5.0
1918import Ubuntu.Components 0.1
19+import "../DashAudioPlayer"
2020
2121/*! \brief Preview widget for audio tracks.
2222
@@ -36,38 +36,6 @@ PreviewWidget {
3636 id: root
3737 height: childrenRect.height
3838
39− onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
40−
41− Audio {
42− id: audio
43− objectName: "audio"
44−
45− property real progress: audio.position / audio.duration
46− property Item playingItem
47−
48− Component.onDestruction: {
49− // destroying the component doesn't automatically send stop to the media service, probably a bug in QtMultimedia
50− audio.stop();
51− }
52−
53− onErrorStringChanged: console.warn("Audio player error:", errorString)
54−
55− function lengthToString(s) {
56− if (typeof(s) !== "number" || s <= 0) return "";
57−
58− var sec = "" + s % 60;
59− if (sec.length == 1) sec = "0" + sec;
60− var hour = Math.floor(s / 3600);
61− if (hour < 1) {
62− return Math.floor(s / 60) + ":" + sec;
63− } else {
64− var min = "" + Math.floor(s / 60) % 60;
65− if (min.length == 1) min = "0" + min;
66− return hour + ":" + min + ":" + sec;
67− }
68− }
69− }
70−
7139 Column {
7240 anchors { left: parent.left; right: parent.right }
7341 visible: trackRepeater.count > 0
@@ -78,19 +46,19 @@ PreviewWidget {
7846 model: root.widgetData["tracks"]
7947
8048 function play(item, source) {
81− audio.stop();
49+ DashAudioPlayer.stop();
8250 // Make sure we change the source, even if two items point to the same uri location
83− audio.source = "";
84− audio.source = source;
85− audio.playingItem = item;
86− audio.play();
51+ DashAudioPlayer.source = "";
52+ DashAudioPlayer.source = source;
53+ DashAudioPlayer.play();
8754 }
8855
8956 delegate: Item {
9057 id: trackItem
9158 objectName: "trackItem" + index
9259
93− property bool isPlayingItem: audio.playingItem == trackItem
60+ readonly property url sourceUrl: modelData["source"]
61+ readonly property bool isPlayingItem: DashAudioPlayer.source == sourceUrl
9462
9563 anchors { left: parent.left; right: parent.right }
9664 height: units.gu(5)
@@ -98,9 +66,9 @@ PreviewWidget {
9866 Row {
9967 id: trackRow
10068
101− property int column1Width: units.gu(3)
102− property int column2Width: width - (2 * spacing) - column1Width - column3Width
103− property int column3Width: units.gu(4)
69+ readonly property int column1Width: units.gu(3)
70+ readonly property int column2Width: width - (2 * spacing) - column1Width - column3Width
71+ readonly property int column3Width: units.gu(4)
10472
10573 anchors.verticalCenter: parent.verticalCenter
10674 width: parent.width
@@ -110,7 +78,7 @@ PreviewWidget {
11078 objectName: "playButton"
11179 width: trackRow.column1Width
11280 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"
11482
11583 // Can't be "transparent" or "#00xxxxxx" as the button optimizes away the surrounding shape
11684 // FIXME when this is resolved: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1251685
@@ -118,13 +86,13 @@ PreviewWidget {
11886
11987 onClicked: {
12088 if (trackItem.isPlayingItem) {
121− if (audio.playbackState == Audio.PlayingState) {
122− audio.pause();
123− } else if (audio.playbackState == Audio.PausedState) {
124− audio.play();
89+ if (DashAudioPlayer.playing) {
90+ DashAudioPlayer.pause();
91+ } else if (DashAudioPlayer.paused) {
92+ DashAudioPlayer.play();
12593 }
12694 } else {
127− trackRepeater.play(trackItem, modelData["source"]);
95+ trackRepeater.play(trackItem, sourceUrl);
12896 }
12997 }
13098 }
@@ -164,14 +132,14 @@ PreviewWidget {
164132 id: progressBarFill
165133 objectName: "progressBarFill"
166134
167− property int maxWidth: progressBarImage.width - units.dp(4)
135+ readonly property int maxWidth: progressBarImage.width - units.dp(4)
168136
169137 anchors {
170138 left: progressBarImage.left
171139 right: progressBarImage.right
172140 verticalCenter: progressBarImage.verticalCenter
173141 margins: units.dp(2)
174− rightMargin: maxWidth - (maxWidth * audio.progress) + units.dp(2)
142+ rightMargin: maxWidth - (maxWidth * DashAudioPlayer.progress) + units.dp(2)
175143 }
176144 height: units.dp(2)
177145 visible: progressBarImage.visible
@@ -182,7 +150,7 @@ PreviewWidget {
182150 id: progressBarImage
183151 anchors { left: parent.left; top: parent.bottom; right: parent.right }
184152 height: units.dp(6)
185− visible: audio.playbackState != Audio.StoppedState && trackItem.isPlayingItem && modelData["length"] > 0
153+ visible: !DashAudioPlayer.stopped && trackItem.isPlayingItem && modelData["length"] > 0
186154 source: "graphics/music_progress_bg.png"
187155 }
188156 }
@@ -196,7 +164,7 @@ PreviewWidget {
196164 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
197165 fontSize: "small"
198166 horizontalAlignment: Text.AlignRight
199− text: audio.lengthToString(modelData["length"])
167+ text: DashAudioPlayer.lengthToString(modelData["length"])
200168 }
201169 }
202170 }