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: ""
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")
111 bluetooth.connected = data.Connected == "True"
112 bluetooth.av_connected = data.AVPConnected == "True"
113 bluetooth.deviceAddress = data.Address
115 if ('Position' in metadata)
116 bluetooth.position = metadata.Position
118 if ('Duration' in metadata)
119 bluetooth.duration = metadata.Duration
121 if ('Status' in metadata)
122 bluetooth.state = metadata.Status
124 if ('Artist' in metadata)
125 bluetooth.artist = metadata.Artist
127 if ('Title' in metadata)
128 bluetooth.title = metadata.Title
136 playlist_model.clear();
138 for (var i = 0; i < playlist.list.length; i++) {
139 var item = playlist.list[i]
141 playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' })
144 playlistview.currentIndex = i
150 player.title = metadata.title
151 player.album = metadata.album
152 player.artist = metadata.artist
154 if (metadata.duration) {
155 player.duration = metadata.duration
158 if (metadata.position) {
159 player.position = metadata.position
162 if (metadata.status) {
163 player.status = metadata.status
166 if (metadata.image) {
167 player.cover_art = metadata.image
170 playlistview.currentIndex = metadata.index
177 running: (bluetooth.av_connected && bluetooth.state == "playing")
180 bluetooth.position = bluetooth.position + 250
191 Layout.fillWidth: true
192 Layout.fillHeight: true
193 Layout.preferredHeight: 1080
197 anchors.left: parent.left
198 anchors.right: parent.right
199 anchors.bottom: parent.bottom
200 height: sourceSize.height * width / sourceSize.width
201 fillMode: Image.PreserveAspectCrop
202 source: player.cover_art ? player.cover_art : ''
203 visible: bluetooth.av_connected == false
207 anchors.left: parent.left
208 anchors.right: parent.right
209 anchors.bottom: parent.bottom
219 anchors.margins: root.width * 0.02
221 Layout.fillWidth: true
222 Layout.fillHeight: true
227 // visible: bluetooth.connected == false
228 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
229 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
233 visible: bluetooth.connected == false
234 //checked: player.loop_state
235 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
236 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
237 onClicked: { mediaplayer.loop(checked) }
244 Layout.alignment: Layout.Center
245 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
246 horizontalAlignment: Label.AlignHCenter
247 verticalAlignment: Label.AlignVCenter
250 Layout.alignment: Layout.Center
251 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
252 horizontalAlignment: Label.AlignHCenter
253 verticalAlignment: Label.AlignVCenter
254 font.pixelSize: title.font.pixelSize * 0.6
260 Layout.fillWidth: true
261 to: bluetooth.av_connected ? bluetooth.duration : player.duration
262 enabled: bluetooth.av_connected == false
263 value: bluetooth.av_connected ? bluetooth.position : player.position
264 function getPosition() {
265 if (bluetooth.av_connected) {
266 return player.time2str(bluetooth.position)
268 return player.time2str(player.position)
272 anchors.left: parent.left
273 anchors.bottom: parent.top
275 text: slider.getPosition()
279 anchors.right: parent.right
280 anchors.bottom: parent.top
282 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
284 onPressedChanged: mediaplayer.seek(value)
287 Layout.fillHeight: true
289 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
292 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
294 Item { Layout.fillWidth: true }
297 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
299 if (bluetooth.av_connected) {
300 bluetooth.set_avrcp_controls("Previous")
301 bluetooth.position = 0
303 mediaplayer.previous()
309 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
311 if (bluetooth.av_connected) {
312 bluetooth.set_avrcp_controls("Play")
319 when: player.status == "playing"
322 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
330 when: bluetooth.av_connected && bluetooth.state == "playing"
333 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
334 onClicked: bluetooth.set_avrcp_controls("Pause")
342 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
344 if (bluetooth.av_connected) {
345 bluetooth.set_avrcp_controls("Next")
352 Item { Layout.fillWidth: true }
355 visible: bluetooth.connected
356 checked: bluetooth.av_connected
357 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
358 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
361 if (bluetooth.av_connected) {
362 bluetooth.disconnect_profiles()
364 bluetooth.connect_profiles()
373 Layout.fillWidth: true
374 Layout.fillHeight: true
375 Layout.preferredHeight: 407
380 visible: bluetooth.av_connected == false
387 model: playlist_model
390 delegate: MouseArea {
392 width: ListView.view.width
393 height: ListView.view.height / 4
396 anchors.leftMargin: 50
397 anchors.rightMargin: 50
399 Layout.fillWidth: true
401 Layout.fillWidth: true
405 Layout.fillWidth: true
412 // text: player.time2str(model.duration)
414 // font.pixelSize: 32
418 mediaplayer.picktrack(playlistview.model.get(index).index)
422 highlight: Rectangle {