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 {
60 playlistmodel.setSource(playlist)
61 playlistview.visible = false
64 onProcessPlaylistUpdate: {
66 playlist.addItems(mediaFiles)
68 playlistmodel.setSource(playlist)
69 playlistview.visible = bluetooth.connected == false
72 onProcessPlaylistHide: {
73 playlistview.visible = false
77 onProcessPlaylistShow: {
78 playlistview.visible = true
79 bluetooth.disableBluetooth()
82 onDisplayBluetoothMetadata: {
84 bluetooth.artist = avrcp_artist
86 bluetooth.title = avrcp_title
87 bluetooth.duration = avrcp_duration
88 bluetooth.pos_offset = 0
91 onUpdatePlayerStatus: {
92 bluetooth.connected = true
93 bluetooth.state = status
97 slider.value = current_position
98 bluetooth.position = current_position
104 audioRole: MediaPlayer.MusicRole
108 property bool is_bluetooth: false
109 function time2str(value) {
110 return Qt.formatTime(new Date(value), 'mm:ss')
112 onPositionChanged: slider.value = player.position
118 running: (bluetooth.connected && bluetooth.state == "playing")
121 bluetooth.position = dbus.getCurrentPosition() - bluetooth.pos_offset
122 slider.value = bluetooth.position
128 playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential
130 Component.onCompleted: {
131 playlist.addItems(mediaFiles)
139 Layout.fillWidth: true
140 Layout.fillHeight: true
141 Layout.preferredHeight: 1080
145 anchors.left: parent.left
146 anchors.right: parent.right
147 anchors.bottom: parent.bottom
148 height: sourceSize.height * width / sourceSize.width
149 fillMode: Image.PreserveAspectCrop
150 source: player.metaData.coverArtImage ? player.metaData.coverArtImage : ''
151 visible: bluetooth.connected == false
155 anchors.left: parent.left
156 anchors.right: parent.right
157 anchors.bottom: parent.bottom
167 anchors.margins: root.width * 0.02
169 Layout.fillWidth: true
170 Layout.fillHeight: true
175 visible: bluetooth.connected == false
176 offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
177 onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
181 visible: bluetooth.connected == false
182 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
183 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
190 Layout.alignment: Layout.Center
191 text: bluetooth.title ? bluetooth.title : (player.metaData.title ? player.metaData.title : '')
192 horizontalAlignment: Label.AlignHCenter
193 verticalAlignment: Label.AlignVCenter
196 Layout.alignment: Layout.Center
197 text: bluetooth.artist ? bluetooth.artist : (player.metaData.contributingArtist ? player.metaData.contributingArtist : '')
198 horizontalAlignment: Label.AlignHCenter
199 verticalAlignment: Label.AlignVCenter
200 font.pixelSize: title.font.pixelSize * 0.6
206 Layout.fillWidth: true
207 to: bluetooth.connected ? bluetooth.duration : player.duration
208 enabled: bluetooth.connected == false
209 function getPosition() {
210 if (bluetooth.connected && bluetooth.position) {
211 return player.time2str(bluetooth.position)
213 return player.time2str(player.position)
217 anchors.left: parent.left
218 anchors.bottom: parent.top
220 text: slider.getPosition()
224 anchors.right: parent.right
225 anchors.bottom: parent.top
227 text: bluetooth.connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
229 onPressedChanged: player.seek(value)
232 Layout.fillHeight: true
234 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
237 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
239 Item { Layout.fillWidth: true }
242 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
244 if (bluetooth.connected) {
245 bluetooth.pos_offset = dbus.getCurrentPosition()
246 dbus.processQMLEvent("Previous")
254 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
256 if (bluetooth.connected) {
257 dbus.processQMLEvent("Play")
264 when: player.playbackState === MediaPlayer.PlayingState
267 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
268 onClicked: player.pause()
272 when: bluetooth.connected && bluetooth.state == "playing"
275 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
276 onClicked: dbus.processQMLEvent("Pause")
284 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
286 if (bluetooth.connected) {
287 dbus.processQMLEvent("Next")
294 Item { Layout.fillWidth: true }
296 // source: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
299 // source: './images/AGL_MediaPlayer_Radio_Inactive.svg'
306 Layout.fillWidth: true
307 Layout.fillHeight: true
308 Layout.preferredHeight: 407
310 PlaylistWithMetadata {
325 currentIndex: playlist.currentIndex
327 delegate: MouseArea {
329 width: ListView.view.width
330 height: ListView.view.height / 4
333 anchors.leftMargin: 50
334 anchors.rightMargin: 50
336 source: model.coverArt
337 fillMode: Image.PreserveAspectFit
338 Layout.preferredWidth: delegate.height
339 Layout.preferredHeight: delegate.height
342 Layout.fillWidth: true
344 Layout.fillWidth: true
348 Layout.fillWidth: true
355 text: player.time2str(model.duration)
361 playlist.currentIndex = model.index
366 highlight: Rectangle {