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
25 width: container.width * container.scale
26 height: container.height * container.scale
31 property string title: ""
32 property string album: ""
33 property string artist: ""
35 property int duration: 0
36 property int position: 0
38 property string cover_art: ""
39 property string status: "stopped"
41 function time2str(value) {
42 return Qt.formatTime(new Date(value), 'mm:ss')
49 property string deviceAddress: ""
50 property bool connected: false
51 property bool av_connected: false
53 property int position: 0
54 property int duration: 0
56 property string artist: ""
57 property string title: ""
58 property string state: "stopped"
61 property string avrcp_uuid: "0000110e-0000-1000-8000-00805f9b34fb"
63 function connect_profiles() {
64 var address = bluetooth.deviceAddress;
65 bluetooth_connection.connect(address, "a2dp")
66 bluetooth_connection.connect(address, "avrcp")
69 function disconnect_profiles() {
70 var address = bluetooth.deviceAddress;
71 bluetooth_connection.disconnect(address, "a2dp")
72 bluetooth_connection.disconnect(address, "avrcp")
75 function set_avrcp_controls(cmd) {
76 bluetooth_connection.set_avrcp_controls(bluetooth.deviceAddress, cmd)
81 target: bluetooth_connection
85 for (var i = 0; i < data.list.length; i++) {
86 var item = data.list[i]
87 if (item.Connected == "True" && item.UUIDs.indexOf(bluetooth.avrcp_uuid) >= 0) {
88 address = item.Address
90 bluetooth.connected = true
93 //NOTE: This hack is here for when MediaPlayer is started
94 // with an existing connection.
95 bluetooth.av_connected = item.AVPConnected == "True"
99 bluetooth.connected = false
101 bluetooth.deviceAddress = address
104 onDeviceUpdatedEvent: {
105 var metadata = data.Metadata
107 if (data.Connected == "False")
110 if (!bluetooth.av_connected && data.AVPConnected == "True") {
112 player.status = "stopped"
115 bluetooth.connected = data.Connected == "True"
116 bluetooth.av_connected = data.AVPConnected == "True"
117 bluetooth.deviceAddress = data.Address
119 if ('Position' in metadata)
120 bluetooth.position = metadata.Position
122 if ('Duration' in metadata)
123 bluetooth.duration = metadata.Duration
125 if ('Status' in metadata)
126 bluetooth.state = metadata.Status
128 if ('Artist' in metadata)
129 bluetooth.artist = metadata.Artist
131 if ('Title' in metadata)
132 bluetooth.title = metadata.Title
140 player.title = metadata.title
141 player.album = metadata.album
142 player.artist = metadata.artist
144 if (metadata.duration) {
145 player.duration = metadata.duration
148 if (metadata.position) {
149 player.position = metadata.position
152 if (metadata.status) {
153 player.status = metadata.status
156 if (metadata.image) {
157 player.cover_art = metadata.image
160 playlistview.currentIndex = metadata.index
167 running: (bluetooth.av_connected && bluetooth.state == "playing")
170 bluetooth.position = bluetooth.position + 250
176 anchors.centerIn: parent
179 scale: screenInfo.scale_factor()
184 Layout.fillWidth: true
185 Layout.fillHeight: true
186 Layout.preferredHeight: 1080
190 anchors.left: parent.left
191 anchors.right: parent.right
192 anchors.bottom: parent.bottom
193 height: sourceSize.height * width / sourceSize.width
194 fillMode: Image.PreserveAspectCrop
195 source: player.cover_art ? player.cover_art : ''
196 visible: bluetooth.av_connected == false
200 anchors.left: parent.left
201 anchors.right: parent.right
202 anchors.bottom: parent.bottom
212 anchors.margins: root.width * 0.02
214 Layout.fillWidth: true
215 Layout.fillHeight: true
220 // visible: bluetooth.connected == false
221 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
222 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
226 visible: bluetooth.connected == false
227 //checked: player.loop_state
228 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
229 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
230 onClicked: { mediaplayer.loop(checked) }
237 Layout.alignment: Layout.Center
238 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
239 horizontalAlignment: Label.AlignHCenter
240 verticalAlignment: Label.AlignVCenter
243 Layout.alignment: Layout.Center
244 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
245 horizontalAlignment: Label.AlignHCenter
246 verticalAlignment: Label.AlignVCenter
247 font.pixelSize: title.font.pixelSize * 0.6
253 Layout.fillWidth: true
254 to: bluetooth.av_connected ? bluetooth.duration : player.duration
255 enabled: bluetooth.av_connected == false
256 value: bluetooth.av_connected ? bluetooth.position : player.position
257 function getPosition() {
258 if (bluetooth.av_connected) {
259 return player.time2str(bluetooth.position)
261 return player.time2str(player.position)
265 anchors.left: parent.left
266 anchors.bottom: parent.top
268 text: slider.getPosition()
272 anchors.right: parent.right
273 anchors.bottom: parent.top
275 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
277 onPressedChanged: mediaplayer.seek(value)
280 Layout.fillHeight: true
282 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
285 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
287 Item { Layout.fillWidth: true }
290 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
292 if (bluetooth.av_connected) {
293 bluetooth.set_avrcp_controls("Previous")
294 bluetooth.position = 0
296 mediaplayer.previous()
304 when: !bluetooth.av_connected && player.status == "playing"
307 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
309 player.status = "stopped"
315 when: bluetooth.av_connected && bluetooth.state == "playing"
318 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
319 onClicked: bluetooth.set_avrcp_controls("Pause")
323 when: !bluetooth.av_connected && player.status != "playing"
326 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
327 onClicked: mediaplayer.play()
331 when: bluetooth.av_connected && bluetooth.state != "playing"
334 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
335 onClicked: bluetooth.set_avrcp_controls("Play")
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: MediaplayerModel
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[index].index)
422 highlight: Rectangle {