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 AGL.Demo.Controls 1.0
28 property string title: ""
29 property string album: ""
30 property string artist: ""
32 property int duration: 0
33 property int position: 0
35 property string cover_art: ""
36 property string status: "stopped"
38 function time2str(value) {
39 return Qt.formatTime(new Date(value), 'mm:ss')
46 property string deviceAddress: ""
47 property bool connected: false
48 property bool av_connected: false
50 property int position: 0
51 property int duration: 0
53 property string artist: ""
54 property string title: ""
55 property string state: "stopped"
58 property string avrcp_uuid: "0000110e-0000-1000-8000-00805f9b34fb"
60 function connect_profiles() {
61 var address = bluetooth.deviceAddress;
62 bluetooth_connection.connect(address, "a2dp")
63 bluetooth_connection.connect(address, "avrcp")
66 function disconnect_profiles() {
67 var address = bluetooth.deviceAddress;
68 bluetooth_connection.disconnect(address, "a2dp")
69 bluetooth_connection.disconnect(address, "avrcp")
72 function set_avrcp_controls(cmd) {
73 bluetooth_connection.set_avrcp_controls(bluetooth.deviceAddress, cmd)
78 target: bluetooth_connection
82 for (var i = 0; i < data.list.length; i++) {
83 var item = data.list[i]
84 if (item.Connected == "True" && item.UUIDs.indexOf(bluetooth.avrcp_uuid) >= 0) {
85 address = item.Address
87 bluetooth.connected = true
90 //NOTE: This hack is here for when MediaPlayer is started
91 // with an existing connection.
92 bluetooth.av_connected = item.AVPConnected == "True"
96 bluetooth.connected = false
98 bluetooth.deviceAddress = address
101 onDeviceUpdatedEvent: {
102 var metadata = data.Metadata
104 if (data.Connected == "False")
107 if (!bluetooth.av_connected && data.AVPConnected == "True") {
109 player.status = "stopped"
112 bluetooth.connected = data.Connected == "True"
113 bluetooth.av_connected = data.AVPConnected == "True"
114 bluetooth.deviceAddress = data.Address
116 if ('Position' in metadata)
117 bluetooth.position = metadata.Position
119 if ('Duration' in metadata)
120 bluetooth.duration = metadata.Duration
122 if ('Status' in metadata)
123 bluetooth.state = metadata.Status
125 if ('Artist' in metadata)
126 bluetooth.artist = metadata.Artist
128 if ('Title' in metadata)
129 bluetooth.title = metadata.Title
137 playlist_model.clear();
139 for (var i = 0; i < playlist.list.length; i++) {
140 var item = playlist.list[i]
142 playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' })
145 playlistview.currentIndex = i
151 player.title = metadata.title
152 player.album = metadata.album
153 player.artist = metadata.artist
155 if (metadata.duration) {
156 player.duration = metadata.duration
159 if (metadata.position) {
160 player.position = metadata.position
163 if (metadata.status) {
164 player.status = metadata.status
167 if (metadata.image) {
168 player.cover_art = metadata.image
171 playlistview.currentIndex = metadata.index
178 running: (bluetooth.av_connected && bluetooth.state == "playing")
181 bluetooth.position = bluetooth.position + 250
192 Layout.fillWidth: true
193 Layout.fillHeight: true
194 Layout.preferredHeight: 1080
198 anchors.left: parent.left
199 anchors.right: parent.right
200 anchors.bottom: parent.bottom
201 height: sourceSize.height * width / sourceSize.width
202 fillMode: Image.PreserveAspectCrop
203 source: player.cover_art ? player.cover_art : ''
204 visible: bluetooth.av_connected == false
208 anchors.left: parent.left
209 anchors.right: parent.right
210 anchors.bottom: parent.bottom
220 anchors.margins: root.width * 0.02
222 Layout.fillWidth: true
223 Layout.fillHeight: true
228 // visible: bluetooth.connected == false
229 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
230 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
234 visible: bluetooth.connected == false
235 //checked: player.loop_state
236 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
237 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
238 onClicked: { mediaplayer.loop(checked) }
245 Layout.alignment: Layout.Center
246 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
247 horizontalAlignment: Label.AlignHCenter
248 verticalAlignment: Label.AlignVCenter
251 Layout.alignment: Layout.Center
252 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
253 horizontalAlignment: Label.AlignHCenter
254 verticalAlignment: Label.AlignVCenter
255 font.pixelSize: title.font.pixelSize * 0.6
261 Layout.fillWidth: true
262 to: bluetooth.av_connected ? bluetooth.duration : player.duration
263 enabled: bluetooth.av_connected == false
264 value: bluetooth.av_connected ? bluetooth.position : player.position
265 function getPosition() {
266 if (bluetooth.av_connected) {
267 return player.time2str(bluetooth.position)
269 return player.time2str(player.position)
273 anchors.left: parent.left
274 anchors.bottom: parent.top
276 text: slider.getPosition()
280 anchors.right: parent.right
281 anchors.bottom: parent.top
283 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
285 onPressedChanged: mediaplayer.seek(value)
288 Layout.fillHeight: true
290 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
293 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
295 Item { Layout.fillWidth: true }
298 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
300 if (bluetooth.av_connected) {
301 bluetooth.set_avrcp_controls("Previous")
302 bluetooth.position = 0
304 mediaplayer.previous()
312 when: !bluetooth.av_connected && player.status == "playing"
315 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
317 player.status = "stopped"
323 when: bluetooth.av_connected && bluetooth.state == "playing"
326 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
327 onClicked: bluetooth.set_avrcp_controls("Pause")
331 when: !bluetooth.av_connected && player.status != "playing"
334 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
335 onClicked: mediaplayer.play()
339 when: bluetooth.av_connected && bluetooth.state != "playing"
342 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
343 onClicked: bluetooth.set_avrcp_controls("Play")
350 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
352 if (bluetooth.av_connected) {
353 bluetooth.set_avrcp_controls("Next")
360 Item { Layout.fillWidth: true }
363 visible: bluetooth.connected
364 checked: bluetooth.av_connected
365 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
366 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
369 if (bluetooth.av_connected) {
370 bluetooth.disconnect_profiles()
372 bluetooth.connect_profiles()
381 Layout.fillWidth: true
382 Layout.fillHeight: true
383 Layout.preferredHeight: 407
388 visible: bluetooth.av_connected == false
395 model: playlist_model
398 delegate: MouseArea {
400 width: ListView.view.width
401 height: ListView.view.height / 4
404 anchors.leftMargin: 50
405 anchors.rightMargin: 50
407 Layout.fillWidth: true
409 Layout.fillWidth: true
413 Layout.fillWidth: true
420 // text: player.time2str(model.duration)
422 // font.pixelSize: 32
426 mediaplayer.picktrack(playlistview.model.get(index).index)
430 highlight: Rectangle {