on xenial help sign in
Initial Audio Player preview widget
commitedb5cde243c5071605606c9f493c7ce5333a9f31 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateMon 27 Jan 2014, 17:00 (13 years ago) parent2308f33
3 files changed+133−88
qml/Dash/Music/MusicPreview.qml+10−88 qml/Dash/Previews/AudioPlayer.qml+123 qml/Dash/Music/graphics/music_progress_bg.png → qml/Dash/Previews/graphics/music_progress_bg.png
qml/Dash/Music/MusicPreview.qml+10−88
@@ -93,14 +93,19 @@ GenericPreview {
9393
9494 model: previewData.tracks
9595
96− delegate: Item {
96+ delegate: AudioPlayer {
9797 id: trackItem
9898 objectName: "trackItem" + index
9999 anchors { left: parent.left; right: parent.right }
100100 height: units.gu(5)
101− property bool isPlayingItem: audioPlayer.playingItem == trackItem
102101
103− function play() {
102+ isPlayingItem: audioPlayer.playingItem == trackItem
103+ playbackState: audioPlayer.playbackState
104+ progress: audioPlayer.progress
105+ title: model.title
106+ length: model.length
107+
108+ onPlay: {
104109 audioPlayer.stop();
105110 // Make sure we change the source, even if two items point to the same uri location
106111 audioPlayer.source = "";
@@ -109,91 +114,8 @@ GenericPreview {
109114 audioPlayer.play();
110115 }
111116
112− Row {
113− id: trackRow
114− width: parent.width
115− spacing: units.gu(1)
116− property int column1Width: units.gu(3)
117− property int column2Width: width - (2 * spacing) - column1Width - column3Width
118− property int column3Width: units.gu(4)
119− anchors.verticalCenter: parent.verticalCenter
120−
121− Button {
122− objectName: "playButton"
123− width: trackRow.column1Width
124− height: width
125− iconSource: audioPlayer.playbackState == Audio.PlayingState && trackItem.isPlayingItem ? "image://theme/media-playback-pause" : "image://theme/media-playback-start"
126−
127− // Can't be "transparent" or "#00xxxxxx" as the button optimizes away the surrounding shape
128− // FIXME when this is resolved: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1251685
129− color: "#01000000"
130−
131− onClicked: {
132− if (trackItem.isPlayingItem) {
133− if (audioPlayer.playbackState == Audio.PlayingState) {
134− audioPlayer.pause();
135− } else if (audioPlayer.playbackState == Audio.PausedState){
136− audioPlayer.play();
137− }
138− } else {
139− trackItem.play();
140− }
141− }
142− }
143−
144− Label {
145− objectName: "trackTitleLabel"
146− fontSize: "small"
147− opacity: 0.9
148− color: "white"
149− horizontalAlignment: Text.AlignLeft
150− anchors.verticalCenter: parent.verticalCenter
151− width: parent.column2Width
152− text: title
153− style: Text.Raised
154− styleColor: "black"
155− elide: Text.ElideRight
156−
157− UbuntuShape {
158− id: progressBarFill
159− objectName: "progressBarFill"
160− color: UbuntuColors.orange
161− anchors.left: progressBarImage.left
162− anchors.right: progressBarImage.right
163− anchors.verticalCenter: progressBarImage.verticalCenter
164− height: units.dp(2)
165− anchors.margins: units.dp(2)
166− anchors.rightMargin: maxWidth - (maxWidth * audioPlayer.progress) + units.dp(2)
167− visible: progressBarImage.visible
168− property int maxWidth: progressBarImage.width - units.dp(4)
169− }
170−
171− Image {
172− id: progressBarImage
173− anchors { left: parent.left; top: parent.bottom; right: parent.right }
174− height: units.dp(6)
175− visible: audioPlayer.playbackState != Audio.StoppedState && trackItem.isPlayingItem && model.length.length > 0
176− source: "graphics/music_progress_bg.png"
177− }
178− }
179−
180− Label {
181− id: valueLabel
182− objectName: "timeLabel"
183− fontSize: "small"
184− opacity: 0.9
185− color: "white"
186− anchors.verticalCenter: parent.verticalCenter
187− horizontalAlignment: Text.AlignRight
188− width: parent.column3Width
189− text: length
190− style: Text.Raised
191− styleColor: "black"
192− }
193− }
194−
195− ThinDivider {
196− anchors { left: parent.left; bottom: parent.bottom; right: parent.right }
117+ onPause: {
118+ audioPlayer.stop()
197119 }
198120 }
199121 }
qml/Dash/Previews/AudioPlayer.qmlnew file+123
@@ -0,0 +1,123 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtMultimedia 5.0
19+import Ubuntu.Components 0.1
20+import Ubuntu.Components.ListItems 0.1
21+
22+Item {
23+ id: trackItem
24+ implicitHeight: units.gu(5)
25+
26+ property bool isPlayingItem
27+ property int playbackState
28+ property real progress: 0
29+ property string title
30+ property string length
31+
32+ signal play()
33+
34+ signal pause()
35+
36+ Row {
37+ id: trackRow
38+ width: parent.width
39+ spacing: units.gu(1)
40+ property int column1Width: units.gu(3)
41+ property int column2Width: width - (2 * spacing) - column1Width - column3Width
42+ property int column3Width: units.gu(4)
43+ anchors.verticalCenter: parent.verticalCenter
44+
45+ Button {
46+ objectName: "playButton"
47+ width: trackRow.column1Width
48+ height: width
49+ iconSource: trackItem.playbackState == Audio.PlayingState && trackItem.isPlayingItem ? "image://theme/media-playback-pause" : "image://theme/media-playback-start"
50+
51+ // Can't be "transparent" or "#00xxxxxx" as the button optimizes away the surrounding shape
52+ // FIXME when this is resolved: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1251685
53+ color: "#01000000"
54+
55+ onClicked: {
56+ if (trackItem.isPlayingItem) {
57+ if (trackItem.playbackState == Audio.PlayingState) {
58+ trackItem.pause();
59+ } else if (audioPlayer.playbackState == Audio.PausedState){
60+ trackItem.play();
61+ }
62+ } else {
63+ trackItem.play();
64+ }
65+ }
66+ }
67+
68+ Label {
69+ objectName: "trackTitleLabel"
70+ fontSize: "small"
71+ opacity: 0.9
72+ color: "white"
73+ horizontalAlignment: Text.AlignLeft
74+ anchors.verticalCenter: parent.verticalCenter
75+ width: parent.column2Width
76+ text: title
77+ style: Text.Raised
78+ styleColor: "black"
79+ elide: Text.ElideRight
80+
81+ UbuntuShape {
82+ id: progressBarFill
83+ objectName: "progressBarFill"
84+ color: UbuntuColors.orange
85+ anchors.left: progressBarImage.left
86+ anchors.right: progressBarImage.right
87+ anchors.verticalCenter: progressBarImage.verticalCenter
88+ height: units.dp(2)
89+ anchors.margins: units.dp(2)
90+ anchors.rightMargin: maxWidth - (maxWidth * progress) + units.dp(2)
91+ visible: progressBarImage.visible
92+
93+ property int maxWidth: progressBarImage.width - units.dp(4)
94+ }
95+
96+ Image {
97+ id: progressBarImage
98+ anchors { left: parent.left; top: parent.bottom; right: parent.right }
99+ height: units.dp(6)
100+ visible: trackItem.playbackState != Audio.StoppedState && trackItem.isPlayingItem && length.length > 0
101+ source: "graphics/music_progress_bg.png"
102+ }
103+ }
104+
105+ Label {
106+ id: valueLabel
107+ objectName: "timeLabel"
108+ fontSize: "small"
109+ opacity: 0.9
110+ color: "white"
111+ anchors.verticalCenter: parent.verticalCenter
112+ horizontalAlignment: Text.AlignRight
113+ width: parent.column3Width
114+ text: length
115+ style: Text.Raised
116+ styleColor: "black"
117+ }
118+ }
119+
120+ ThinDivider {
121+ anchors { left: parent.left; bottom: parent.bottom; right: parent.right }
122+ }
123+}
qml/Dash/Music/graphics/music_progress_bg.png → qml/Dash/Previews/graphics/music_progress_bg.pngrenamed

Binary file not shown.