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
37 function disableBluetooth() {
40 bluetooth.duration = 0
41 bluetooth.position = 0
42 bluetooth.connected = false
49 onProcessPlaylistUpdate: {
51 playlist.addItems(mediaFiles)
53 playlistmodel.setSource(playlist)
54 playlistview.visible = bluetooth.connected == false
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
75 onUpdatePlayerStatus: {
76 bluetooth.connected = true
77 bluetooth.state = status
81 slider.value = current_position
82 bluetooth.position = current_position
88 audioRole: MediaPlayer.MusicRole
92 property bool is_bluetooth: false
93 function time2str(value) {
94 return Qt.formatTime(new Date(value), 'mm:ss')
96 onPositionChanged: slider.value = player.position
102 running: (bluetooth.connected && bluetooth.state == "playing")
105 bluetooth.position = dbus.getCurrentPosition()
106 slider.value = bluetooth.position
112 playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential
114 Component.onCompleted: {
115 playlist.addItems(mediaFiles)
123 Layout.fillWidth: true
124 Layout.fillHeight: true
125 Layout.preferredHeight: 1080
129 anchors.left: parent.left
130 anchors.right: parent.right
131 anchors.bottom: parent.bottom
132 height: sourceSize.height * width / sourceSize.width
133 fillMode: Image.PreserveAspectCrop
134 source: player.metaData.coverArtImage ? player.metaData.coverArtImage : ''
135 visible: bluetooth.connected == false
139 anchors.left: parent.left
140 anchors.right: parent.right
141 anchors.bottom: parent.bottom
151 anchors.margins: root.width * 0.02
153 Layout.fillWidth: true
154 Layout.fillHeight: true
159 visible: bluetooth.connected == false
160 offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
161 onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
165 visible: bluetooth.connected == false
166 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
167 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
174 Layout.alignment: Layout.Center
175 text: bluetooth.title ? bluetooth.title : (player.metaData.title ? player.metaData.title : '')
176 horizontalAlignment: Label.AlignHCenter
177 verticalAlignment: Label.AlignVCenter
180 Layout.alignment: Layout.Center
181 text: bluetooth.artist ? bluetooth.artist : (player.metaData.contributingArtist ? player.metaData.contributingArtist : '')
182 horizontalAlignment: Label.AlignHCenter
183 verticalAlignment: Label.AlignVCenter
184 font.pixelSize: title.font.pixelSize * 0.6
190 Layout.fillWidth: true
191 to: bluetooth.connected ? bluetooth.duration : player.duration
192 enabled: bluetooth.connected == false
193 function getPosition() {
194 if (bluetooth.connected && bluetooth.position) {
195 return player.time2str(bluetooth.position)
197 return player.time2str(player.position)
201 anchors.left: parent.left
202 anchors.bottom: parent.top
204 text: slider.getPosition()
208 anchors.right: parent.right
209 anchors.bottom: parent.top
211 text: bluetooth.connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
213 onPressedChanged: player.seek(value)
216 Layout.fillHeight: true
218 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
221 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
223 Item { Layout.fillWidth: true }
226 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
228 if (bluetooth.connected) {
229 dbus.processQMLEvent("Previous")
237 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
239 if (bluetooth.connected) {
240 dbus.processQMLEvent("Play")
247 when: player.playbackState === MediaPlayer.PlayingState
250 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
251 onClicked: player.pause()
255 when: bluetooth.connected && bluetooth.state == "playing"
258 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
259 onClicked: dbus.processQMLEvent("Pause")
267 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
269 if (bluetooth.connected) {
270 dbus.processQMLEvent("Next")
277 Item { Layout.fillWidth: true }
279 // source: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
282 // source: './images/AGL_MediaPlayer_Radio_Inactive.svg'
289 Layout.fillWidth: true
290 Layout.fillHeight: true
291 Layout.preferredHeight: 407
293 PlaylistWithMetadata {
308 currentIndex: playlist.currentIndex
310 delegate: MouseArea {
312 width: ListView.view.width
313 height: ListView.view.height / 4
316 anchors.leftMargin: 50
317 anchors.rightMargin: 50
319 source: model.coverArt
320 fillMode: Image.PreserveAspectFit
321 Layout.preferredWidth: delegate.height
322 Layout.preferredHeight: delegate.height
325 Layout.fillWidth: true
327 Layout.fillWidth: true
331 Layout.fillWidth: true
338 text: player.time2str(model.duration)
344 playlist.currentIndex = model.index
349 highlight: Rectangle {