on xenial help sign in
Merge
8486b8aAndrea Cimitan
qml/Dash/Previews/PreviewAudioPlayback.qml+22−23
@@ -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
21
20
22/*! \brief Preview widget for audio tracks.
21/*! \brief Preview widget for audio tracks.
23
22
@@ -35,7 +34,7 @@ import Ubuntu.Components.ListItems 0.1
35
34
36PreviewWidget {
35PreviewWidget {
37 id: root
36 id: root
38− implicitHeight: childrenRect.height
37+ height: childrenRect.height
39
38
40 onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
39 onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
41
40
@@ -47,24 +46,24 @@ PreviewWidget {
47 property Item playingItem
46 property Item playingItem
48
47
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();
52 }
51 }
53
52
54 onErrorStringChanged: console.warn("Audio player error:", errorString)
53 onErrorStringChanged: console.warn("Audio player error:", errorString)
55
54
56 function lengthToString(s) {
55 function lengthToString(s) {
57− if (s <= 0 || s === undefined) return ""
56+ if (typeof(s) !== "number" || s <= 0) return "";
58
57
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;
64 } else {
63 } else {
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;
68 }
67 }
69 }
68 }
70 }
69 }
@@ -78,6 +77,15 @@ PreviewWidget {
78 objectName: "trackRepeater"
77 objectName: "trackRepeater"
79 model: root.widgetData["tracks"]
78 model: root.widgetData["tracks"]
80
79
80+ function play(item, source) {
81+ audio.stop();
82+ // 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();
87+ }
88+
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)
89
97
90− function play() {
91− audio.stop();
92− // Make sure we change the source, even if two items point to the same uri location
93− audio.source = "";
94− audio.source = modelData["source"];
95− audio.playingItem = trackItem;
96− audio.play();
97− }
98−
99 Row {
98 Row {
100 id: trackRow
99 id: trackRow
101
100
@@ -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();
126 }
125 }
127 } else {
126 } else {
128− trackItem.play();
127+ trackRepeater.play(trackItem, modelData["source"]);
129 }
128 }
130 }
129 }
131 }
130 }
@@ -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
161 }
160 }
162
161
qml/Dash/Previews/PreviewWidget.qml+2−2
@@ -19,9 +19,9 @@ import QtQuick 2.0
19/*! Interface for preview widgets. */
19/*! Interface for preview widgets. */
20
20
21Item {
21Item {
22− /// type:bool Specifies the preview widget being currently used or not
22+ //! Specifies the preview widget being currently used or not
23 property bool isCurrentPreview: true
23 property bool isCurrentPreview: true
24
24
25− /// Variable used to contain widget's data
25+ //! Variable used to contain widget's data
26 property var widgetData
26 property var widgetData
27}
27}
tests/qmltests/Dash/Previews/tst_PreviewAudioPlayback.qml+1
@@ -57,6 +57,7 @@ Rectangle {
57
57
58 function test_time_formatter_data() {
58 function test_time_formatter_data() {
59 return [
59 return [
60+ { tag: "NaN", value: "not a number", result: "" },
60 { tag: "0", value: 0, result: "" },
61 { tag: "0", value: 0, result: "" },
61 { tag: "-1", value: -1, result: "" },
62 { tag: "-1", value: -1, result: "" },
62 { tag: "30", value: 30, result: "0:30" },
63 { tag: "30", value: 30, result: "0:30" },