@@ -17,7 +17,6 @@
17import QtQuick 2.0
17import QtQuick 2.0
18import QtMultimedia 5.0
18import QtMultimedia 5.0
19import Ubuntu.Components 0.1
19import Ubuntu.Components 0.1
20−import Ubuntu.Components.ListItems 0.1
22/*! \brief Preview widget for audio tracks.
21/*! \brief Preview widget for audio tracks.
@@ -35,7 +34,7 @@ import Ubuntu.Components.ListItems 0.1
36PreviewWidget {
35PreviewWidget {
38− implicitHeight: childrenRect.height
37+ height: childrenRect.height
40 onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
39 onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
@@ -47,24 +46,24 @@ PreviewWidget {
47 property Item playingItem
46 property Item playingItem
49 Component.onDestruction: {
48 Component.onDestruction: {
50− // destructing the component doesn't automatically send stop to the media service, probably a bug in QtMultimedia
49+ // destroying the component doesn't automatically send stop to the media service, probably a bug in QtMultimedia
51 audio.stop();
50 audio.stop();
54 onErrorStringChanged: console.warn("Audio player error:", errorString)
53 onErrorStringChanged: console.warn("Audio player error:", errorString)
56 function lengthToString(s) {
55 function lengthToString(s) {
57− if (s <= 0 || s === undefined) return ""
56+ if (typeof(s) !== "number" || s <= 0) return "";
59− var sec = "" + s % 60
58+ var sec = "" + s % 60;
60− if (sec.length == 1) sec = "0" + sec
59+ if (sec.length == 1) sec = "0" + sec;
61− var hour = Math.floor(s / 3600)
60+ var hour = Math.floor(s / 3600);
62 if (hour < 1) {
61 if (hour < 1) {
63− return Math.floor(s / 60) + ":" + sec
62+ return Math.floor(s / 60) + ":" + sec;
65− var min = "" + Math.floor(s / 60) % 60
64+ var min = "" + Math.floor(s / 60) % 60;
66− if (min.length == 1) min = "0" + min
65+ if (min.length == 1) min = "0" + min;
67− return hour + ":" + min + ":" + sec
66+ return hour + ":" + min + ":" + sec;
@@ -78,6 +77,15 @@ PreviewWidget {
78 objectName: "trackRepeater"
77 objectName: "trackRepeater"
79 model: root.widgetData["tracks"]
78 model: root.widgetData["tracks"]
80+ function play(item, source) {
82+ // Make sure we change the source, even if two items point to the same uri location
84+ audio.source = source;
85+ audio.playingItem = item;
81 delegate: Item {
89 delegate: Item {
82 id: trackItem
90 id: trackItem
83 objectName: "trackItem" + index
91 objectName: "trackItem" + index
@@ -87,15 +95,6 @@ PreviewWidget {
87 anchors { left: parent.left; right: parent.right }
95 anchors { left: parent.left; right: parent.right }
88 height: units.gu(5)
96 height: units.gu(5)
92− // Make sure we change the source, even if two items point to the same uri location
94− audio.source = modelData["source"];
95− audio.playingItem = trackItem;
100 id: trackRow
99 id: trackRow
@@ -121,11 +120,11 @@ PreviewWidget {
121 if (trackItem.isPlayingItem) {
120 if (trackItem.isPlayingItem) {
122 if (audio.playbackState == Audio.PlayingState) {
121 if (audio.playbackState == Audio.PlayingState) {
123 audio.pause();
122 audio.pause();
124− } else if (audio.playbackState == Audio.PausedState){
123+ } else if (audio.playbackState == Audio.PausedState) {
125 audio.play();
124 audio.play();
128− trackItem.play();
127+ trackRepeater.play(trackItem, modelData["source"]);
@@ -156,7 +155,7 @@ PreviewWidget {
156 color: Theme.palette.selected.backgroundText
155 color: Theme.palette.selected.backgroundText
157 fontSize: "small"
156 fontSize: "small"
158 horizontalAlignment: Text.AlignLeft
157 horizontalAlignment: Text.AlignLeft
159− text: modelData["subtitle"] !== undefined ? modelData["subtitle"] : ""
158+ text: modelData["subtitle"] || ""
160 elide: Text.ElideRight
159 elide: Text.ElideRight