2 * Copyright (C) 2016 The Qt Company Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 import QtQuick.Layouts 1.1
19 import QtQuick.Controls 2.0
20 import QtMultimedia 5.6
21 import AGL.Demo.Controls 1.0
29 property string title: ""
30 property string album: ""
31 property string artist: ""
33 property int duration: 0
34 property int position: 0
36 property string cover_art: ""
37 property string status: "stopped"
39 function time2str(value) {
40 return Qt.formatTime(new Date(value), 'mm:ss')
47 property string deviceAddress: ""
48 property bool connected: false
49 property bool av_connected: false
51 property int position: 0
52 property int duration: 0
54 property string artist: ""
55 property string title: ""
56 property string state: "stopped"
59 property string avrcp_uuid: "0000110e-0000-1000-8000-00805f9b34fb"
61 function connect_profiles() {
62 var address = bluetooth.deviceAddress;
63 bluetooth_connection.connect(address, "a2dp")
64 bluetooth_connection.connect(address, "avrcp")
67 function disconnect_profiles() {
68 var address = bluetooth.deviceAddress;
69 bluetooth_connection.disconnect(address, "a2dp")
70 bluetooth_connection.disconnect(address, "avrcp")
73 function set_avrcp_controls(cmd) {
74 bluetooth_connection.set_avrcp_controls(bluetooth.deviceAddress, cmd)
79 target: bluetooth_connection
83 for (var i = 0; i < data.list.length; i++) {
84 var item = data.list[i]
85 if (item.Connected == "True" && item.UUIDs.indexOf(bluetooth.avrcp_uuid) >= 0) {
86 address = item.Address
88 bluetooth.connected = true
91 //NOTE: This hack is here for when MediaPlayer is started
92 // with an existing connection.
93 bluetooth.av_connected = item.AVPConnected == "True"
97 bluetooth.connected = false
99 bluetooth.deviceAddress = address
102 onDeviceUpdatedEvent: {
103 var metadata = data.Metadata
105 if (data.Connected == "False")
108 if (!bluetooth.av_connected && data.AVPConnected == "True") {
110 player.status = "stopped"
113 bluetooth.connected = data.Connected == "True"
114 bluetooth.av_connected = data.AVPConnected == "True"
115 bluetooth.deviceAddress = data.Address
117 if ('Position' in metadata)
118 bluetooth.position = metadata.Position
120 if ('Duration' in metadata)
121 bluetooth.duration = metadata.Duration
123 if ('Status' in metadata)
124 bluetooth.state = metadata.Status
126 if ('Artist' in metadata)
127 bluetooth.artist = metadata.Artist
129 if ('Title' in metadata)
130 bluetooth.title = metadata.Title
138 playlist_model.clear();
140 for (var i = 0; i < playlist.list.length; i++) {
141 var item = playlist.list[i]
143 playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' })
146 playlistview.currentIndex = i
152 player.title = metadata.title
153 player.album = metadata.album
154 player.artist = metadata.artist
156 if (metadata.duration) {
157 player.duration = metadata.duration
160 if (metadata.position) {
161 player.position = metadata.position
164 if (metadata.status) {
165 player.status = metadata.status
168 if (metadata.image) {
169 player.cover_art = metadata.image
172 playlistview.currentIndex = metadata.index
179 running: (bluetooth.av_connected && bluetooth.state == "playing")
182 bluetooth.position = bluetooth.position + 250
193 Layout.fillWidth: true
194 Layout.fillHeight: true
195 Layout.preferredHeight: 1080
199 anchors.left: parent.left
200 anchors.right: parent.right
201 anchors.bottom: parent.bottom
202 height: sourceSize.height * width / sourceSize.width
203 fillMode: Image.PreserveAspectCrop
204 source: player.cover_art ? player.cover_art : ''
205 visible: bluetooth.av_connected == false
209 anchors.left: parent.left
210 anchors.right: parent.right
211 anchors.bottom: parent.bottom
221 anchors.margins: root.width * 0.02
223 Layout.fillWidth: true
224 Layout.fillHeight: true
229 // visible: bluetooth.connected == false
230 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
231 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
235 visible: bluetooth.connected == false
236 //checked: player.loop_state
237 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
238 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
239 onClicked: { mediaplayer.loop(checked) }
246 Layout.alignment: Layout.Center
247 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
248 horizontalAlignment: Label.AlignHCenter
249 verticalAlignment: Label.AlignVCenter
252 Layout.alignment: Layout.Center
253 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
254 horizontalAlignment: Label.AlignHCenter
255 verticalAlignment: Label.AlignVCenter
256 font.pixelSize: title.font.pixelSize * 0.6
262 Layout.fillWidth: true
263 to: bluetooth.av_connected ? bluetooth.duration : player.duration
264 enabled: bluetooth.av_connected == false
265 value: bluetooth.av_connected ? bluetooth.position : player.position
266 function getPosition() {
267 if (bluetooth.av_connected) {
268 return player.time2str(bluetooth.position)
270 return player.time2str(player.position)
274 anchors.left: parent.left
275 anchors.bottom: parent.top
277 text: slider.getPosition()
281 anchors.right: parent.right
282 anchors.bottom: parent.top
284 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
286 onPressedChanged: mediaplayer.seek(value)
289 Layout.fillHeight: true
291 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
294 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
296 Item { Layout.fillWidth: true }
299 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
301 if (bluetooth.av_connected) {
302 bluetooth.set_avrcp_controls("Previous")
303 bluetooth.position = 0
305 mediaplayer.previous()
313 when: !bluetooth.av_connected && player.status == "playing"
316 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
318 player.status = "stopped"
324 when: bluetooth.av_connected && bluetooth.state == "playing"
327 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
328 onClicked: bluetooth.set_avrcp_controls("Pause")
332 when: !bluetooth.av_connected && player.status != "playing"
335 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
336 onClicked: mediaplayer.play()
340 when: bluetooth.av_connected && bluetooth.state != "playing"
343 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
344 onClicked: bluetooth.set_avrcp_controls("Play")
351 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
353 if (bluetooth.av_connected) {
354 bluetooth.set_avrcp_controls("Next")
361 Item { Layout.fillWidth: true }
364 visible: bluetooth.connected
365 checked: bluetooth.av_connected
366 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
367 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
370 if (bluetooth.av_connected) {
371 bluetooth.disconnect_profiles()
373 bluetooth.connect_profiles()
382 Layout.fillWidth: true
383 Layout.fillHeight: true
384 Layout.preferredHeight: 407
389 visible: bluetooth.av_connected == false
396 model: playlist_model
399 delegate: MouseArea {
401 width: ListView.view.width
402 height: ListView.view.height / 4
405 anchors.leftMargin: 50
406 anchors.rightMargin: 50
408 Layout.fillWidth: true
410 Layout.fillWidth: true
414 Layout.fillWidth: true
421 // text: player.time2str(model.duration)
423 // font.pixelSize: 32
427 mediaplayer.picktrack(playlistview.model.get(index).index)
431 highlight: Rectangle {