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
29 property bool connected: false
32 property string artist
34 property int duration: 0
35 property int position: 0
36 property int pos_offset: 0
38 function disableBluetooth() {
41 bluetooth.duration = 0
42 bluetooth.position = 0
43 bluetooth.pos_offset = 0
44 bluetooth.connected = false
54 playlistmodel.setSource(playlist)
55 playlistview.visible = false
58 onProcessPlaylistUpdate: {
60 playlist.addItems(mediaFiles)
62 playlistmodel.setSource(playlist)
63 playlistview.visible = bluetooth.connected == false
66 onProcessPlaylistHide: {
67 playlistview.visible = false
71 onProcessPlaylistShow: {
72 playlistview.visible = true
73 bluetooth.disableBluetooth()
76 onDisplayBluetoothMetadata: {
78 bluetooth.artist = avrcp_artist
80 bluetooth.title = avrcp_title
81 bluetooth.duration = avrcp_duration
82 bluetooth.pos_offset = 0
85 onUpdatePlayerStatus: {
86 bluetooth.connected = true
87 bluetooth.state = status
91 slider.value = current_position
92 bluetooth.position = current_position
98 audioRole: MediaPlayer.MusicRole
102 property bool is_bluetooth: false
103 function time2str(value) {
104 return Qt.formatTime(new Date(value), 'mm:ss')
106 onPositionChanged: slider.value = player.position
112 running: (bluetooth.connected && bluetooth.state == "playing")
115 bluetooth.position = dbus.getCurrentPosition() - bluetooth.pos_offset
116 slider.value = bluetooth.position
122 playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential
124 Component.onCompleted: {
125 playlist.addItems(mediaFiles)
133 Layout.fillWidth: true
134 Layout.fillHeight: true
135 Layout.preferredHeight: 1080
139 anchors.left: parent.left
140 anchors.right: parent.right
141 anchors.bottom: parent.bottom
142 height: sourceSize.height * width / sourceSize.width
143 fillMode: Image.PreserveAspectCrop
144 source: player.metaData.coverArtImage ? player.metaData.coverArtImage : ''
145 visible: bluetooth.connected == false
149 anchors.left: parent.left
150 anchors.right: parent.right
151 anchors.bottom: parent.bottom
161 anchors.margins: root.width * 0.02
163 Layout.fillWidth: true
164 Layout.fillHeight: true
169 visible: bluetooth.connected == false
170 offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
171 onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
175 visible: bluetooth.connected == false
176 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
177 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
184 Layout.alignment: Layout.Center
185 text: bluetooth.title ? bluetooth.title : (player.metaData.title ? player.metaData.title : '')
186 horizontalAlignment: Label.AlignHCenter
187 verticalAlignment: Label.AlignVCenter
190 Layout.alignment: Layout.Center
191 text: bluetooth.artist ? bluetooth.artist : (player.metaData.contributingArtist ? player.metaData.contributingArtist : '')
192 horizontalAlignment: Label.AlignHCenter
193 verticalAlignment: Label.AlignVCenter
194 font.pixelSize: title.font.pixelSize * 0.6
200 Layout.fillWidth: true
201 to: bluetooth.connected ? bluetooth.duration : player.duration
202 enabled: bluetooth.connected == false
203 function getPosition() {
204 if (bluetooth.connected && bluetooth.position) {
205 return player.time2str(bluetooth.position)
207 return player.time2str(player.position)
211 anchors.left: parent.left
212 anchors.bottom: parent.top
214 text: slider.getPosition()
218 anchors.right: parent.right
219 anchors.bottom: parent.top
221 text: bluetooth.connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
223 onPressedChanged: player.seek(value)
226 Layout.fillHeight: true
228 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
231 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
233 Item { Layout.fillWidth: true }
236 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
238 if (bluetooth.connected) {
239 bluetooth.pos_offset = dbus.getCurrentPosition()
240 dbus.processQMLEvent("Previous")
248 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
250 if (bluetooth.connected) {
251 dbus.processQMLEvent("Play")
258 when: player.playbackState === MediaPlayer.PlayingState
261 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
262 onClicked: player.pause()
266 when: bluetooth.connected && bluetooth.state == "playing"
269 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
270 onClicked: dbus.processQMLEvent("Pause")
278 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
280 if (bluetooth.connected) {
281 dbus.processQMLEvent("Next")
288 Item { Layout.fillWidth: true }
290 // source: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
293 // source: './images/AGL_MediaPlayer_Radio_Inactive.svg'
300 Layout.fillWidth: true
301 Layout.fillHeight: true
302 Layout.preferredHeight: 407
304 PlaylistWithMetadata {
319 currentIndex: playlist.currentIndex
321 delegate: MouseArea {
323 width: ListView.view.width
324 height: ListView.view.height / 4
327 anchors.leftMargin: 50
328 anchors.rightMargin: 50
330 source: model.coverArt
331 fillMode: Image.PreserveAspectFit
332 Layout.preferredWidth: delegate.height
333 Layout.preferredHeight: delegate.height
336 Layout.fillWidth: true
338 Layout.fillWidth: true
342 Layout.fillWidth: true
349 text: player.time2str(model.duration)
355 playlist.currentIndex = model.index
360 highlight: Rectangle {