on xenial help sign in
Merge
commit8486b8a79b07bdb6b89a671db548ee3ce8c174f2 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateThu 6 Feb 2014, 16:45 (13 years ago) parent1200739dfc8753
3 files changed+25−25
qml/Dash/Previews/PreviewAudioPlayback.qml+22−23 qml/Dash/Previews/PreviewWidget.qml+2−2 tests/qmltests/Dash/Previews/tst_PreviewAudioPlayback.qml+1
qml/Dash/Previews/PreviewAudioPlayback.qml+22−23
@@ -17,7 +17,6 @@
1717import QtQuick 2.0
1818import QtMultimedia 5.0
1919import Ubuntu.Components 0.1
20−import Ubuntu.Components.ListItems 0.1
2120
2221/*! \brief Preview widget for audio tracks.
2322
@@ -35,7 +34,7 @@ import Ubuntu.Components.ListItems 0.1
3534
3635PreviewWidget {
3736 id: root
38− implicitHeight: childrenRect.height
37+ height: childrenRect.height
3938
4039 onIsCurrentPreviewChanged: if (!isCurrentPreview) audio.stop()
4140
@@ -47,24 +46,24 @@ PreviewWidget {
4746 property Item playingItem
4847
4948 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
5150 audio.stop();
5251 }
5352
5453 onErrorStringChanged: console.warn("Audio player error:", errorString)
5554
5655 function lengthToString(s) {
57− if (s <= 0 || s === undefined) return ""
56+ if (typeof(s) !== "number" || s <= 0) return "";
5857
59− var sec = "" + s % 60
60− if (sec.length == 1) sec = "0" + sec
61− var hour = Math.floor(s / 3600)
58+ var sec = "" + s % 60;
59+ if (sec.length == 1) sec = "0" + sec;
60+ var hour = Math.floor(s / 3600);
6261 if (hour < 1) {
63− return Math.floor(s / 60) + ":" + sec
62+ return Math.floor(s / 60) + ":" + sec;
6463 } else {
65− var min = "" + Math.floor(s / 60) % 60
66− if (min.length == 1) min = "0" + min
67− return hour + ":" + min + ":" + sec
64+ var min = "" + Math.floor(s / 60) % 60;
65+ if (min.length == 1) min = "0" + min;
66+ return hour + ":" + min + ":" + sec;
6867 }
6968 }
7069 }
@@ -78,6 +77,15 @@ PreviewWidget {
7877 objectName: "trackRepeater"
7978 model: root.widgetData["tracks"]
8079
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+
8189 delegate: Item {
8290 id: trackItem
8391 objectName: "trackItem" + index
@@ -87,15 +95,6 @@ PreviewWidget {
8795 anchors { left: parent.left; right: parent.right }
8896 height: units.gu(5)
8997
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−
9998 Row {
10099 id: trackRow
101100
@@ -121,11 +120,11 @@ PreviewWidget {
121120 if (trackItem.isPlayingItem) {
122121 if (audio.playbackState == Audio.PlayingState) {
123122 audio.pause();
124− } else if (audio.playbackState == Audio.PausedState){
123+ } else if (audio.playbackState == Audio.PausedState) {
125124 audio.play();
126125 }
127126 } else {
128− trackItem.play();
127+ trackRepeater.play(trackItem, modelData["source"]);
129128 }
130129 }
131130 }
@@ -156,7 +155,7 @@ PreviewWidget {
156155 color: Theme.palette.selected.backgroundText
157156 fontSize: "small"
158157 horizontalAlignment: Text.AlignLeft
159− text: modelData["subtitle"] !== undefined ? modelData["subtitle"] : ""
158+ text: modelData["subtitle"] || ""
160159 elide: Text.ElideRight
161160 }
162161
qml/Dash/Previews/PreviewWidget.qml+2−2
@@ -19,9 +19,9 @@ import QtQuick 2.0
1919/*! Interface for preview widgets. */
2020
2121Item {
22− /// type:bool Specifies the preview widget being currently used or not
22+ //! Specifies the preview widget being currently used or not
2323 property bool isCurrentPreview: true
2424
25− /// Variable used to contain widget's data
25+ //! Variable used to contain widget's data
2626 property var widgetData
2727}
tests/qmltests/Dash/Previews/tst_PreviewAudioPlayback.qml+1
@@ -57,6 +57,7 @@ Rectangle {
5757
5858 function test_time_formatter_data() {
5959 return [
60+ { tag: "NaN", value: "not a number", result: "" },
6061 { tag: "0", value: 0, result: "" },
6162 { tag: "-1", value: -1, result: "" },
6263 { tag: "30", value: 30, result: "0:30" },