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 bluetooth.connected = data.Connected == "True"
109 bluetooth.av_connected = data.AVPConnected == "True"
110 bluetooth.deviceAddress = data.Address
112 if ('Position' in metadata)
113 bluetooth.position = metadata.Position
115 if ('Duration' in metadata)
116 bluetooth.duration = metadata.Duration
118 if ('Status' in metadata)
119 bluetooth.state = metadata.Status
121 if ('Artist' in metadata)
122 bluetooth.artist = metadata.Artist
124 if ('Title' in metadata)
125 bluetooth.title = metadata.Title
135 for (var i = 0; i < playlist.list.length; i++) {
136 var item = playlist.list[i]
138 playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' })
141 playlistview.currentIndex = i
147 player.title = metadata.title
148 player.album = metadata.album
149 player.artist = metadata.artist
151 if (metadata.duration) {
152 player.duration = metadata.duration
155 if (metadata.position) {
156 player.position = metadata.position
159 if (metadata.status) {
160 player.status = metadata.status
163 if (metadata.image) {
164 player.cover_art = metadata.image
167 playlistview.currentIndex = metadata.index
174 running: (bluetooth.av_connected && bluetooth.state == "playing")
177 bluetooth.position = bluetooth.position + 250
188 Layout.fillWidth: true
189 Layout.fillHeight: true
190 Layout.preferredHeight: 1080
194 anchors.left: parent.left
195 anchors.right: parent.right
196 anchors.bottom: parent.bottom
197 height: sourceSize.height * width / sourceSize.width
198 fillMode: Image.PreserveAspectCrop
199 source: player.cover_art ? player.cover_art : ''
200 visible: bluetooth.av_connected == false
204 anchors.left: parent.left
205 anchors.right: parent.right
206 anchors.bottom: parent.bottom
216 anchors.margins: root.width * 0.02
218 Layout.fillWidth: true
219 Layout.fillHeight: true
224 // visible: bluetooth.connected == false
225 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
226 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
230 visible: bluetooth.connected == false
231 //checked: player.loop_state
232 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
233 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
234 onClicked: { mediaplayer.loop(checked) }
241 Layout.alignment: Layout.Center
242 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
243 horizontalAlignment: Label.AlignHCenter
244 verticalAlignment: Label.AlignVCenter
247 Layout.alignment: Layout.Center
248 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
249 horizontalAlignment: Label.AlignHCenter
250 verticalAlignment: Label.AlignVCenter
251 font.pixelSize: title.font.pixelSize * 0.6
257 Layout.fillWidth: true
258 to: bluetooth.av_connected ? bluetooth.duration : player.duration
259 enabled: bluetooth.av_connected == false
260 value: bluetooth.av_connected ? bluetooth.position : player.position
261 function getPosition() {
262 if (bluetooth.av_connected) {
263 return player.time2str(bluetooth.position)
265 return player.time2str(player.position)
269 anchors.left: parent.left
270 anchors.bottom: parent.top
272 text: slider.getPosition()
276 anchors.right: parent.right
277 anchors.bottom: parent.top
279 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
281 onPressedChanged: mediaplayer.seek(value)
284 Layout.fillHeight: true
286 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
289 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
291 Item { Layout.fillWidth: true }
294 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
296 if (bluetooth.av_connected) {
297 bluetooth.set_avrcp_controls("Previous")
298 bluetooth.position = 0
300 mediaplayer.previous()
306 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
308 if (bluetooth.av_connected) {
309 bluetooth.set_avrcp_controls("Play")
316 when: player.status == "playing"
319 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
327 when: bluetooth.av_connected && bluetooth.state == "playing"
330 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
331 onClicked: bluetooth.set_avrcp_controls("Pause")
339 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
341 if (bluetooth.av_connected) {
342 bluetooth.set_avrcp_controls("Next")
349 Item { Layout.fillWidth: true }
352 visible: bluetooth.connected
353 checked: bluetooth.av_connected
354 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
355 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
358 if (bluetooth.av_connected) {
359 bluetooth.disconnect_profiles()
361 bluetooth.connect_profiles()
370 Layout.fillWidth: true
371 Layout.fillHeight: true
372 Layout.preferredHeight: 407
377 visible: bluetooth.av_connected == false
384 model: playlist_model
387 delegate: MouseArea {
389 width: ListView.view.width
390 height: ListView.view.height / 4
393 anchors.leftMargin: 50
394 anchors.rightMargin: 50
396 Layout.fillWidth: true
398 Layout.fillWidth: true
402 Layout.fillWidth: true
409 // text: player.time2str(model.duration)
411 // font.pixelSize: 32
415 mediaplayer.picktrack(playlistview.model.get(index).index)
419 highlight: Rectangle {