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: "stopped"
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") {
109 player.status = "stopped"
112 bluetooth.connected = data.Connected == "True"
113 bluetooth.av_connected = data.AVPConnected == "True"
114 bluetooth.deviceAddress = data.Address
116 if ('Position' in metadata)
117 bluetooth.position = metadata.Position
119 if ('Duration' in metadata)
120 bluetooth.duration = metadata.Duration
122 if ('Status' in metadata)
123 bluetooth.state = metadata.Status
125 if ('Artist' in metadata)
126 bluetooth.artist = metadata.Artist
128 if ('Title' in metadata)
129 bluetooth.title = metadata.Title
137 player.title = metadata.title ? metadata.title : ""
138 player.album = metadata.album ? metadata.album : ""
139 player.artist = metadata.artist ? metadata.artist : ""
141 if (metadata.duration) {
142 player.duration = metadata.duration
145 if (metadata.position) {
146 player.position = metadata.position
149 if (metadata.status) {
150 player.status = metadata.status
153 if (metadata.image) {
154 player.cover_art = metadata.image
157 playlistview.currentIndex = metadata.index
164 running: (bluetooth.av_connected && bluetooth.state == "playing")
167 bluetooth.position = bluetooth.position + 250
174 Layout.fillWidth: true
175 Layout.fillHeight: true
176 Layout.preferredHeight: 1080
180 anchors.left: parent.left
181 anchors.right: parent.right
182 anchors.bottom: parent.bottom
183 height: sourceSize.height * width / sourceSize.width
184 fillMode: Image.PreserveAspectCrop
185 source: player.cover_art ? player.cover_art : ''
186 visible: bluetooth.av_connected == false
190 anchors.left: parent.left
191 anchors.right: parent.right
192 anchors.bottom: parent.bottom
202 anchors.margins: root.width * 0.02
204 Layout.fillWidth: true
205 Layout.fillHeight: true
210 // visible: bluetooth.connected == false
211 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
212 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
216 visible: bluetooth.connected == false
217 //checked: player.loop_state
218 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
219 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
220 onClicked: { mediaplayer.loop(checked) }
227 Layout.alignment: Layout.Center
228 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
229 horizontalAlignment: Label.AlignHCenter
230 verticalAlignment: Label.AlignVCenter
233 Layout.alignment: Layout.Center
234 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
235 horizontalAlignment: Label.AlignHCenter
236 verticalAlignment: Label.AlignVCenter
237 font.pixelSize: title.font.pixelSize * 0.6
243 Layout.fillWidth: true
244 to: bluetooth.av_connected ? bluetooth.duration : player.duration
245 enabled: bluetooth.av_connected == false
246 value: bluetooth.av_connected ? bluetooth.position : player.position
247 function getPosition() {
248 if (bluetooth.av_connected) {
249 return player.time2str(bluetooth.position)
251 return player.time2str(player.position)
255 anchors.left: parent.left
256 anchors.bottom: parent.top
258 text: slider.getPosition()
262 anchors.right: parent.right
263 anchors.bottom: parent.top
265 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
267 onPressedChanged: mediaplayer.seek(value)
270 Layout.fillHeight: true
272 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
275 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
277 Item { Layout.fillWidth: true }
280 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
282 if (bluetooth.av_connected) {
283 bluetooth.set_avrcp_controls("Previous")
284 bluetooth.position = 0
286 mediaplayer.previous()
294 when: !bluetooth.av_connected && player.status == "playing"
297 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
299 player.status = "stopped"
305 when: bluetooth.av_connected && bluetooth.state == "playing"
308 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
309 onClicked: bluetooth.set_avrcp_controls("Pause")
313 when: !bluetooth.av_connected && player.status != "playing"
316 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
317 onClicked: mediaplayer.play()
321 when: bluetooth.av_connected && bluetooth.state != "playing"
324 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
325 onClicked: bluetooth.set_avrcp_controls("Play")
332 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
334 if (bluetooth.av_connected) {
335 bluetooth.set_avrcp_controls("Next")
342 Item { Layout.fillWidth: true }
345 visible: bluetooth.connected
346 checked: bluetooth.av_connected
347 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
348 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
351 if (bluetooth.av_connected) {
352 bluetooth.disconnect_profiles()
354 bluetooth.connect_profiles()
363 Layout.fillWidth: true
364 Layout.fillHeight: true
365 Layout.preferredHeight: 407
370 visible: bluetooth.av_connected == false
377 model: MediaplayerModel
380 delegate: MouseArea {
382 width: ListView.view.width
383 height: ListView.view.height / 4
386 anchors.leftMargin: 50
387 anchors.rightMargin: 50
389 Layout.fillWidth: true
391 Layout.fillWidth: true
395 Layout.fillWidth: true
402 // text: player.time2str(model.duration)
404 // font.pixelSize: 32
408 mediaplayer.picktrack(playlistview.model[index].index)
412 highlight: Rectangle {