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 bluetooth.connected = data.Connected == "True"
108 bluetooth.av_connected = data.AVPConnected == "True"
109 bluetooth.deviceAddress = data.Address
111 if ('Position' in metadata)
112 bluetooth.position = metadata.Position
114 if ('Duration' in metadata)
115 bluetooth.duration = metadata.Duration
117 if ('Status' in metadata)
118 bluetooth.state = metadata.Status
120 if ('Artist' in metadata)
121 bluetooth.artist = metadata.Artist
123 if ('Title' in metadata)
124 bluetooth.title = metadata.Title
132 playlist_model.clear();
134 for (var i = 0; i < playlist.list.length; i++) {
135 var item = playlist.list[i]
137 playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' })
140 playlistview.currentIndex = i
146 player.title = metadata.title
147 player.album = metadata.album
148 player.artist = metadata.artist
150 if (metadata.duration) {
151 player.duration = metadata.duration
154 if (metadata.position) {
155 player.position = metadata.position
158 if (metadata.status) {
159 player.status = metadata.status
162 if (metadata.image) {
163 player.cover_art = metadata.image
166 playlistview.currentIndex = metadata.index
173 running: (bluetooth.av_connected && bluetooth.state == "playing")
176 bluetooth.position = bluetooth.position + 250
187 Layout.fillWidth: true
188 Layout.fillHeight: true
189 Layout.preferredHeight: 1080
193 anchors.left: parent.left
194 anchors.right: parent.right
195 anchors.bottom: parent.bottom
196 height: sourceSize.height * width / sourceSize.width
197 fillMode: Image.PreserveAspectCrop
198 source: player.cover_art ? player.cover_art : ''
199 visible: bluetooth.av_connected == false
203 anchors.left: parent.left
204 anchors.right: parent.right
205 anchors.bottom: parent.bottom
215 anchors.margins: root.width * 0.02
217 Layout.fillWidth: true
218 Layout.fillHeight: true
223 // visible: bluetooth.connected == false
224 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
225 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
229 visible: bluetooth.connected == false
230 //checked: player.loop_state
231 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
232 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
233 onClicked: { mediaplayer.loop(checked) }
240 Layout.alignment: Layout.Center
241 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
242 horizontalAlignment: Label.AlignHCenter
243 verticalAlignment: Label.AlignVCenter
246 Layout.alignment: Layout.Center
247 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
248 horizontalAlignment: Label.AlignHCenter
249 verticalAlignment: Label.AlignVCenter
250 font.pixelSize: title.font.pixelSize * 0.6
256 Layout.fillWidth: true
257 to: bluetooth.av_connected ? bluetooth.duration : player.duration
258 enabled: bluetooth.av_connected == false
259 value: bluetooth.av_connected ? bluetooth.position : player.position
260 function getPosition() {
261 if (bluetooth.av_connected) {
262 return player.time2str(bluetooth.position)
264 return player.time2str(player.position)
268 anchors.left: parent.left
269 anchors.bottom: parent.top
271 text: slider.getPosition()
275 anchors.right: parent.right
276 anchors.bottom: parent.top
278 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
280 onPressedChanged: mediaplayer.seek(value)
283 Layout.fillHeight: true
285 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
288 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
290 Item { Layout.fillWidth: true }
293 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
295 if (bluetooth.av_connected) {
296 bluetooth.set_avrcp_controls("Previous")
297 bluetooth.position = 0
299 mediaplayer.previous()
305 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
307 if (bluetooth.av_connected) {
308 bluetooth.set_avrcp_controls("Play")
315 when: player.status == "playing"
318 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
326 when: bluetooth.av_connected && bluetooth.state == "playing"
329 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
330 onClicked: bluetooth.set_avrcp_controls("Pause")
338 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
340 if (bluetooth.av_connected) {
341 bluetooth.set_avrcp_controls("Next")
348 Item { Layout.fillWidth: true }
351 visible: bluetooth.connected
352 checked: bluetooth.av_connected
353 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
354 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
357 if (bluetooth.av_connected) {
358 bluetooth.disconnect_profiles()
360 bluetooth.connect_profiles()
369 Layout.fillWidth: true
370 Layout.fillHeight: true
371 Layout.preferredHeight: 407
376 visible: bluetooth.av_connected == false
383 model: playlist_model
386 delegate: MouseArea {
388 width: ListView.view.width
389 height: ListView.view.height / 4
392 anchors.leftMargin: 50
393 anchors.rightMargin: 50
395 Layout.fillWidth: true
397 Layout.fillWidth: true
401 Layout.fillWidth: true
408 // text: player.time2str(model.duration)
410 // font.pixelSize: 32
414 mediaplayer.picktrack(playlistview.model.get(index).index)
418 highlight: Rectangle {