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: ""
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")
110 bluetooth.connected = data.Connected == "True"
111 bluetooth.av_connected = data.AVPConnected == "True"
112 bluetooth.deviceAddress = data.Address
114 if ('Position' in metadata)
115 bluetooth.position = metadata.Position
117 if ('Duration' in metadata)
118 bluetooth.duration = metadata.Duration
120 if ('Status' in metadata)
121 bluetooth.state = metadata.Status
123 if ('Artist' in metadata)
124 bluetooth.artist = metadata.Artist
126 if ('Title' in metadata)
127 bluetooth.title = metadata.Title
135 playlist_model.clear();
137 for (var i = 0; i < playlist.list.length; i++) {
138 var item = playlist.list[i]
140 playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' })
143 playlistview.currentIndex = i
149 player.title = metadata.title
150 player.album = metadata.album
151 player.artist = metadata.artist
153 if (metadata.duration) {
154 player.duration = metadata.duration
157 if (metadata.position) {
158 player.position = metadata.position
161 if (metadata.status) {
162 player.status = metadata.status
165 if (metadata.image) {
166 player.cover_art = metadata.image
169 playlistview.currentIndex = metadata.index
176 running: (bluetooth.av_connected && bluetooth.state == "playing")
179 bluetooth.position = bluetooth.position + 250
190 Layout.fillWidth: true
191 Layout.fillHeight: true
192 Layout.preferredHeight: 1080
196 anchors.left: parent.left
197 anchors.right: parent.right
198 anchors.bottom: parent.bottom
199 height: sourceSize.height * width / sourceSize.width
200 fillMode: Image.PreserveAspectCrop
201 source: player.cover_art ? player.cover_art : ''
202 visible: bluetooth.av_connected == false
206 anchors.left: parent.left
207 anchors.right: parent.right
208 anchors.bottom: parent.bottom
218 anchors.margins: root.width * 0.02
220 Layout.fillWidth: true
221 Layout.fillHeight: true
226 // visible: bluetooth.connected == false
227 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
228 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
232 visible: bluetooth.connected == false
233 //checked: player.loop_state
234 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
235 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
236 onClicked: { mediaplayer.loop(checked) }
243 Layout.alignment: Layout.Center
244 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
245 horizontalAlignment: Label.AlignHCenter
246 verticalAlignment: Label.AlignVCenter
249 Layout.alignment: Layout.Center
250 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
251 horizontalAlignment: Label.AlignHCenter
252 verticalAlignment: Label.AlignVCenter
253 font.pixelSize: title.font.pixelSize * 0.6
259 Layout.fillWidth: true
260 to: bluetooth.av_connected ? bluetooth.duration : player.duration
261 enabled: bluetooth.av_connected == false
262 value: bluetooth.av_connected ? bluetooth.position : player.position
263 function getPosition() {
264 if (bluetooth.av_connected) {
265 return player.time2str(bluetooth.position)
267 return player.time2str(player.position)
271 anchors.left: parent.left
272 anchors.bottom: parent.top
274 text: slider.getPosition()
278 anchors.right: parent.right
279 anchors.bottom: parent.top
281 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
283 onPressedChanged: mediaplayer.seek(value)
286 Layout.fillHeight: true
288 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
291 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
293 Item { Layout.fillWidth: true }
296 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
298 if (bluetooth.av_connected) {
299 bluetooth.set_avrcp_controls("Previous")
300 bluetooth.position = 0
302 mediaplayer.previous()
308 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
310 if (bluetooth.av_connected) {
311 bluetooth.set_avrcp_controls("Play")
318 when: player.status == "playing"
321 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
329 when: bluetooth.av_connected && bluetooth.state == "playing"
332 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
333 onClicked: bluetooth.set_avrcp_controls("Pause")
341 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
343 if (bluetooth.av_connected) {
344 bluetooth.set_avrcp_controls("Next")
351 Item { Layout.fillWidth: true }
354 visible: bluetooth.connected
355 checked: bluetooth.av_connected
356 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
357 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
360 if (bluetooth.av_connected) {
361 bluetooth.disconnect_profiles()
363 bluetooth.connect_profiles()
372 Layout.fillWidth: true
373 Layout.fillHeight: true
374 Layout.preferredHeight: 407
379 visible: bluetooth.av_connected == false
386 model: playlist_model
389 delegate: MouseArea {
391 width: ListView.view.width
392 height: ListView.view.height / 4
395 anchors.leftMargin: 50
396 anchors.rightMargin: 50
398 Layout.fillWidth: true
400 Layout.fillWidth: true
404 Layout.fillWidth: true
411 // text: player.time2str(model.duration)
413 // font.pixelSize: 32
417 mediaplayer.picktrack(playlistview.model.get(index).index)
421 highlight: Rectangle {