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
30 property string title: ""
31 property string album: ""
32 property string artist: ""
34 property int duration: 0
35 property int position: 0
37 property string cover_art: ""
38 property string status: ""
40 function time2str(value) {
41 return Qt.formatTime(new Date(value), 'mm:ss')
49 playlist_model.clear();
51 for (var i = 0; i < playlist.list.length; i++) {
52 var item = playlist.list[i]
54 playlist_model.append({ "index": item.index, "artist": item.artist ? item.artist : '', "title": item.title ? item.title : '' })
57 playlistview.currentIndex = i
63 player.title = metadata.title
64 player.album = metadata.album
65 player.artist = metadata.artist
67 if (metadata.duration) {
68 player.duration = metadata.duration
71 if (metadata.position) {
72 player.position = metadata.position
75 if (metadata.status) {
76 player.status = metadata.status
80 player.cover_art = metadata.image
83 playlistview.currentIndex = metadata.index
87 API.BluetoothManager {
95 running: (bluetooth.av_connected && bluetooth.state == "playing")
98 bluetooth.position = bluetooth.position + 250
109 Layout.fillWidth: true
110 Layout.fillHeight: true
111 Layout.preferredHeight: 1080
115 anchors.left: parent.left
116 anchors.right: parent.right
117 anchors.bottom: parent.bottom
118 height: sourceSize.height * width / sourceSize.width
119 fillMode: Image.PreserveAspectCrop
120 source: player.cover_art ? player.cover_art : ''
121 visible: bluetooth.av_connected == false
125 anchors.left: parent.left
126 anchors.right: parent.right
127 anchors.bottom: parent.bottom
137 anchors.margins: root.width * 0.02
139 Layout.fillWidth: true
140 Layout.fillHeight: true
145 // visible: bluetooth.connected == false
146 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
147 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
151 visible: bluetooth.connected == false
152 //checked: player.loop_state
153 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
154 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
155 onClicked: { mediaplayer.loop(checked) }
162 Layout.alignment: Layout.Center
163 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
164 horizontalAlignment: Label.AlignHCenter
165 verticalAlignment: Label.AlignVCenter
168 Layout.alignment: Layout.Center
169 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
170 horizontalAlignment: Label.AlignHCenter
171 verticalAlignment: Label.AlignVCenter
172 font.pixelSize: title.font.pixelSize * 0.6
178 Layout.fillWidth: true
179 to: bluetooth.av_connected ? bluetooth.duration : player.duration
180 enabled: bluetooth.av_connected == false
181 value: bluetooth.av_connected ? bluetooth.position : player.position
182 function getPosition() {
183 if (bluetooth.av_connected) {
184 return player.time2str(bluetooth.position)
186 return player.time2str(player.position)
190 anchors.left: parent.left
191 anchors.bottom: parent.top
193 text: slider.getPosition()
197 anchors.right: parent.right
198 anchors.bottom: parent.top
200 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
202 onPressedChanged: mediaplayer.seek(value)
205 Layout.fillHeight: true
207 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
210 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
212 Item { Layout.fillWidth: true }
215 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
217 if (bluetooth.av_connected) {
218 bluetooth.sendMediaCommand("Previous")
219 bluetooth.position = 0
221 mediaplayer.previous()
227 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
229 if (bluetooth.av_connected) {
230 bluetooth.sendMediaCommand("Play")
237 when: player.status == "playing"
240 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
248 when: bluetooth.av_connected && bluetooth.state == "playing"
251 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
252 onClicked: bluetooth.sendMediaCommand("Pause")
260 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
262 if (bluetooth.av_connected) {
263 bluetooth.sendMediaCommand("Next")
270 Item { Layout.fillWidth: true }
273 visible: bluetooth.connected
274 checked: bluetooth.av_connected
275 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
276 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
279 if (bluetooth.av_connected) {
280 bluetooth.disconnect_profiles()
282 bluetooth.connect_profiles()
291 Layout.fillWidth: true
292 Layout.fillHeight: true
293 Layout.preferredHeight: 407
298 visible: bluetooth.av_connected == false
305 model: playlist_model
308 delegate: MouseArea {
310 width: ListView.view.width
311 height: ListView.view.height / 4
314 anchors.leftMargin: 50
315 anchors.rightMargin: 50
317 Layout.fillWidth: true
319 Layout.fillWidth: true
323 Layout.fillWidth: true
330 // text: player.time2str(model.duration)
332 // font.pixelSize: 32
336 mediaplayer.picktrack(playlistview.model.get(index).index)
340 highlight: Rectangle {