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
22 import MediaPlayer 1.0
30 property bool connected: false
33 property string artist
35 property int duration: 0
36 property int position: 0
37 property int pos_offset: 0
39 function disableBluetooth() {
42 bluetooth.duration = 0
43 bluetooth.position = 0
44 bluetooth.pos_offset = 0
45 bluetooth.connected = false
49 API.LightMediaScanner {
57 onProcessPlaylistHide: {
58 playlistview.visible = false
62 onProcessPlaylistShow: {
63 playlistview.visible = true
64 bluetooth.disableBluetooth()
67 onDisplayBluetoothMetadata: {
69 bluetooth.artist = avrcp_artist
71 bluetooth.title = avrcp_title
72 bluetooth.duration = avrcp_duration
73 bluetooth.pos_offset = 0
76 onUpdatePlayerStatus: {
77 bluetooth.connected = true
78 bluetooth.state = status
82 slider.value = current_position
83 bluetooth.position = current_position
89 audioRole: MediaPlayer.MusicRole
93 property bool is_bluetooth: false
94 function time2str(value) {
95 return Qt.formatTime(new Date(value), 'mm:ss')
97 onPositionChanged: slider.value = player.position
103 running: (bluetooth.connected && bluetooth.state == "playing")
106 bluetooth.position = dbus.getCurrentPosition() - bluetooth.pos_offset
107 slider.value = bluetooth.position
113 playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential
120 Layout.fillWidth: true
121 Layout.fillHeight: true
122 Layout.preferredHeight: 1080
126 anchors.left: parent.left
127 anchors.right: parent.right
128 anchors.bottom: parent.bottom
129 height: sourceSize.height * width / sourceSize.width
130 fillMode: Image.PreserveAspectCrop
131 source: player.metaData.coverArtImage ? player.metaData.coverArtImage : ''
132 visible: bluetooth.connected == false
136 anchors.left: parent.left
137 anchors.right: parent.right
138 anchors.bottom: parent.bottom
148 anchors.margins: root.width * 0.02
150 Layout.fillWidth: true
151 Layout.fillHeight: true
156 visible: bluetooth.connected == false
157 offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
158 onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
162 visible: bluetooth.connected == false
163 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
164 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
171 Layout.alignment: Layout.Center
172 text: bluetooth.title ? bluetooth.title : (player.metaData.title ? player.metaData.title : '')
173 horizontalAlignment: Label.AlignHCenter
174 verticalAlignment: Label.AlignVCenter
177 Layout.alignment: Layout.Center
178 text: bluetooth.artist ? bluetooth.artist : (player.metaData.contributingArtist ? player.metaData.contributingArtist : '')
179 horizontalAlignment: Label.AlignHCenter
180 verticalAlignment: Label.AlignVCenter
181 font.pixelSize: title.font.pixelSize * 0.6
187 Layout.fillWidth: true
188 to: bluetooth.connected ? bluetooth.duration : player.duration
189 enabled: bluetooth.connected == false
190 function getPosition() {
191 if (bluetooth.connected && bluetooth.position) {
192 return player.time2str(bluetooth.position)
194 return player.time2str(player.position)
198 anchors.left: parent.left
199 anchors.bottom: parent.top
201 text: slider.getPosition()
205 anchors.right: parent.right
206 anchors.bottom: parent.top
208 text: bluetooth.connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
210 onPressedChanged: player.seek(value)
213 Layout.fillHeight: true
215 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
218 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
220 Item { Layout.fillWidth: true }
223 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
225 if (bluetooth.connected) {
226 bluetooth.pos_offset = dbus.getCurrentPosition()
227 dbus.processQMLEvent("Previous")
235 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
237 if (bluetooth.connected) {
238 dbus.processQMLEvent("Play")
245 when: player.playbackState === MediaPlayer.PlayingState
248 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
249 onClicked: player.pause()
253 when: bluetooth.connected && bluetooth.state == "playing"
256 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
257 onClicked: dbus.processQMLEvent("Pause")
265 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
267 if (bluetooth.connected) {
268 dbus.processQMLEvent("Next")
275 Item { Layout.fillWidth: true }
279 checked: bluetooth.connected
280 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
281 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
288 Layout.fillWidth: true
289 Layout.fillHeight: true
290 Layout.preferredHeight: 407
292 PlaylistWithMetadata {
307 currentIndex: playlist.currentIndex
309 delegate: MouseArea {
311 width: ListView.view.width
312 height: ListView.view.height / 4
315 anchors.leftMargin: 50
316 anchors.rightMargin: 50
318 source: model.coverArt
319 fillMode: Image.PreserveAspectFit
320 Layout.preferredWidth: delegate.height
321 Layout.preferredHeight: delegate.height
324 Layout.fillWidth: true
326 Layout.fillWidth: true
330 Layout.fillWidth: true
337 text: player.time2str(model.duration)
343 playlist.currentIndex = model.index
348 highlight: Rectangle {