mediaplayer: qml: remove shuffle option temporarily
[apps/mediaplayer.git] / app / MediaPlayer.qml
1 /*
2  * Copyright (C) 2016 The Qt Company Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import QtQuick 2.6
18 import QtQuick.Layouts 1.1
19 import QtQuick.Controls 2.0
20 import QtMultimedia 5.6
21 import AGL.Demo.Controls 1.0
22 import 'api' as API
23
24 ApplicationWindow {
25     id: root
26
27     API.MediaPlayer {
28         id: player
29         url: bindingAddress
30     }
31
32     API.BluetoothManager {
33         id: bluetooth
34         url: bindingAddress
35     }
36
37     Timer {
38         id: timer
39         interval: 250
40         running: (bluetooth.av_connected && bluetooth.state == "playing")
41         repeat: true
42         onTriggered: {
43             bluetooth.position = bluetooth.position + 250
44             slider.value = bluetooth.position
45         }
46     }
47
48     ListModel {
49         id: playlist
50     }
51
52     ColumnLayout {
53         anchors.fill: parent
54         Item {
55             Layout.fillWidth: true
56             Layout.fillHeight: true
57             Layout.preferredHeight: 1080
58             clip: true
59             Image {
60                 id: albumart
61                 anchors.left: parent.left
62                 anchors.right: parent.right
63                 anchors.bottom: parent.bottom
64                 height: sourceSize.height * width / sourceSize.width
65                 fillMode: Image.PreserveAspectCrop
66                 source: player.cover_art ? player.cover_art : ''
67                 visible: bluetooth.av_connected == false
68             }
69
70             Item {
71                 anchors.left: parent.left
72                 anchors.right: parent.right
73                 anchors.bottom: parent.bottom
74                 height :307
75                 Rectangle {
76                     anchors.fill: parent
77                     color: 'black'
78                     opacity: 0.75
79                 }
80
81                 ColumnLayout {
82                     anchors.fill: parent
83                     anchors.margins: root.width * 0.02
84                     Item {
85                         Layout.fillWidth: true
86                         Layout.fillHeight: true
87                         Row {
88                             spacing: 20
89                             //ToggleButton {
90                             //    id: random
91                             //    visible: bluetooth.connected == false
92                             //    offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
93                             //    onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
94                             //}
95                             ToggleButton {
96                                 id: loop
97                                 visible: bluetooth.connected == false
98                                 checked: player.loop_state
99                                 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
100                                 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
101                                 onClicked: { player.loop(checked) }
102                             }
103                         }
104                         ColumnLayout {
105                             anchors.fill: parent
106                             Label {
107                                 id: title
108                                 Layout.alignment: Layout.Center
109                                 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
110                                 horizontalAlignment: Label.AlignHCenter
111                                 verticalAlignment: Label.AlignVCenter
112                             }
113                             Label {
114                                 Layout.alignment: Layout.Center
115                                 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
116                                 horizontalAlignment: Label.AlignHCenter
117                                 verticalAlignment: Label.AlignVCenter
118                                 font.pixelSize: title.font.pixelSize * 0.6
119                             }
120                         }
121                     }
122                     Slider {
123                         id: slider
124                         Layout.fillWidth: true
125                         to: bluetooth.av_connected ? bluetooth.duration : player.duration
126                         enabled: bluetooth.av_connected == false
127                         value: bluetooth.av_connected ? bluetooth.position : player.position
128                         function getPosition() {
129                             if (bluetooth.av_connected) {
130                                 return player.time2str(bluetooth.position)
131                             }
132                             return player.time2str(player.position)
133                         }
134                         Label {
135                             id: position
136                             anchors.left: parent.left
137                             anchors.bottom: parent.top
138                             font.pixelSize: 32
139                             text: slider.getPosition()
140                         }
141                         Label {
142                             id: duration
143                             anchors.right: parent.right
144                             anchors.bottom: parent.top
145                             font.pixelSize: 32
146                             text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
147                         }
148                         onPressedChanged: player.seek(value)
149                     }
150                     RowLayout {
151                         Layout.fillHeight: true
152 //                        Image {
153 //                            source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
154 //                        }
155 //                        Image {
156 //                            source: './images/AGL_MediaPlayer_CD_Inactive.svg'
157 //                        }
158                         Item { Layout.fillWidth: true }
159                         ImageButton {
160                             id: previous
161                             offImage: './images/AGL_MediaPlayer_BackArrow.svg'
162                             onClicked: {
163                                 if (bluetooth.av_connected) {
164                                     bluetooth.sendMediaCommand("Previous")
165                                     bluetooth.position = 0
166                                 } else {
167                                     player.previous()
168                                 }
169                             }
170                         }
171                         ImageButton {
172                             id: play
173                             offImage: './images/AGL_MediaPlayer_Player_Play.svg'
174                             onClicked: {
175                                 if (bluetooth.av_connected) {
176                                     bluetooth.sendMediaCommand("Play")
177                                 } else {
178                                     player.play()
179                                 }
180                             }
181                             states: [
182                                 State {
183                                     when: player.running === true
184                                     PropertyChanges {
185                                         target: play
186                                         offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
187                                         onClicked: player.pause()
188                                     }
189                                 },
190                                 State {
191                                     when: bluetooth.av_connected && bluetooth.state == "playing"
192                                     PropertyChanges {
193                                         target: play
194                                         offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
195                                         onClicked: bluetooth.sendMediaCommand("Pause")
196                                     }
197                                 }
198
199                             ]
200                         }
201                         ImageButton {
202                             id: forward
203                             offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
204                             onClicked: {
205                                 if (bluetooth.av_connected) {
206                                     bluetooth.sendMediaCommand("Next")
207                                 } else {
208                                     player.next()
209                                 }
210                             }
211                         }
212
213                         Item { Layout.fillWidth: true }
214  
215                         ToggleButton {
216                               visible: bluetooth.connected
217                               checked: bluetooth.av_connected
218                               offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
219                               onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
220
221                               onClicked: {
222                                   if (bluetooth.av_connected) {
223                                       bluetooth.disconnect_profiles()
224                                   } else {
225                                       bluetooth.connect_profiles()
226                                   }
227                               }
228                         }
229                     }
230                 }
231             }
232         }
233         Item {
234             Layout.fillWidth: true
235             Layout.fillHeight: true
236             Layout.preferredHeight: 407
237
238             ListView {
239                 anchors.fill: parent
240                 id: playlistview
241                 visible: bluetooth.av_connected == false
242                 clip: true
243                 header: Label {
244                     x: 50
245                     text: 'PLAYLIST'
246                     opacity: 0.5
247                 }
248                 model: playlist
249                 currentIndex: -1
250
251                 delegate: MouseArea {
252                     id: delegate
253                     width: ListView.view.width
254                     height: ListView.view.height / 4
255                     RowLayout {
256                         anchors.fill: parent
257                         anchors.leftMargin: 50
258                         anchors.rightMargin: 50
259                         ColumnLayout {
260                             Layout.fillWidth: true
261                             Label {
262                                 Layout.fillWidth: true
263                                 text: model.title
264                             }
265                             Label {
266                                 Layout.fillWidth: true
267                                 text: model.artist
268                                 color: '#66FF99'
269                                 font.pixelSize: 32
270                             }
271                         }
272                         //Label {
273                         //    text: player.time2str(model.duration)
274                         //    color: '#66FF99'
275                         //    font.pixelSize: 32
276                         //}
277                     }
278                     onClicked: {
279                         player.pick_track(playlistview.model.get(index).index)
280                         player.play()
281                     }
282                 }
283
284                 highlight: Rectangle {
285                     color: 'white'
286                     opacity: 0.25
287                 }
288             }
289         }
290     }
291 }