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
52 playlistmodel.setSource(playlist)
53 playlistview.visible = false
56 onProcessPlaylistUpdate: {
58 playlist.addItems(mediaFiles)
60 playlistmodel.setSource(playlist)
61 playlistview.visible = bluetooth.connected == false
64 onProcessPlaylistHide: {
65 playlistview.visible = false
69 onProcessPlaylistShow: {
70 playlistview.visible = true
71 bluetooth.disableBluetooth()
74 onDisplayBluetoothMetadata: {
76 bluetooth.artist = avrcp_artist
78 bluetooth.title = avrcp_title
79 bluetooth.duration = avrcp_duration
82 onUpdatePlayerStatus: {
83 bluetooth.connected = true
84 bluetooth.state = status
88 slider.value = current_position
89 bluetooth.position = current_position
95 audioRole: MediaPlayer.MusicRole
99 property bool is_bluetooth: false
100 function time2str(value) {
101 return Qt.formatTime(new Date(value), 'mm:ss')
103 onPositionChanged: slider.value = player.position
109 running: (bluetooth.connected && bluetooth.state == "playing")
112 bluetooth.position = dbus.getCurrentPosition()
113 slider.value = bluetooth.position
119 playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential
121 Component.onCompleted: {
122 playlist.addItems(mediaFiles)
130 Layout.fillWidth: true
131 Layout.fillHeight: true
132 Layout.preferredHeight: 1080
136 anchors.left: parent.left
137 anchors.right: parent.right
138 anchors.bottom: parent.bottom
139 height: sourceSize.height * width / sourceSize.width
140 fillMode: Image.PreserveAspectCrop
141 source: player.metaData.coverArtImage ? player.metaData.coverArtImage : ''
142 visible: bluetooth.connected == false
146 anchors.left: parent.left
147 anchors.right: parent.right
148 anchors.bottom: parent.bottom
158 anchors.margins: root.width * 0.02
160 Layout.fillWidth: true
161 Layout.fillHeight: true
166 visible: bluetooth.connected == false
167 offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
168 onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
172 visible: bluetooth.connected == false
173 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
174 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
181 Layout.alignment: Layout.Center
182 text: bluetooth.title ? bluetooth.title : (player.metaData.title ? player.metaData.title : '')
183 horizontalAlignment: Label.AlignHCenter
184 verticalAlignment: Label.AlignVCenter
187 Layout.alignment: Layout.Center
188 text: bluetooth.artist ? bluetooth.artist : (player.metaData.contributingArtist ? player.metaData.contributingArtist : '')
189 horizontalAlignment: Label.AlignHCenter
190 verticalAlignment: Label.AlignVCenter
191 font.pixelSize: title.font.pixelSize * 0.6
197 Layout.fillWidth: true
198 to: bluetooth.connected ? bluetooth.duration : player.duration
199 enabled: bluetooth.connected == false
200 function getPosition() {
201 if (bluetooth.connected && bluetooth.position) {
202 return player.time2str(bluetooth.position)
204 return player.time2str(player.position)
208 anchors.left: parent.left
209 anchors.bottom: parent.top
211 text: slider.getPosition()
215 anchors.right: parent.right
216 anchors.bottom: parent.top
218 text: bluetooth.connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
220 onPressedChanged: player.seek(value)
223 Layout.fillHeight: true
225 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
228 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
230 Item { Layout.fillWidth: true }
233 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
235 if (bluetooth.connected) {
236 dbus.processQMLEvent("Previous")
244 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
246 if (bluetooth.connected) {
247 dbus.processQMLEvent("Play")
254 when: player.playbackState === MediaPlayer.PlayingState
257 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
258 onClicked: player.pause()
262 when: bluetooth.connected && bluetooth.state == "playing"
265 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
266 onClicked: dbus.processQMLEvent("Pause")
274 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
276 if (bluetooth.connected) {
277 dbus.processQMLEvent("Next")
284 Item { Layout.fillWidth: true }
286 // source: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
289 // source: './images/AGL_MediaPlayer_Radio_Inactive.svg'
296 Layout.fillWidth: true
297 Layout.fillHeight: true
298 Layout.preferredHeight: 407
300 PlaylistWithMetadata {
315 currentIndex: playlist.currentIndex
317 delegate: MouseArea {
319 width: ListView.view.width
320 height: ListView.view.height / 4
323 anchors.leftMargin: 50
324 anchors.rightMargin: 50
326 source: model.coverArt
327 fillMode: Image.PreserveAspectFit
328 Layout.preferredWidth: delegate.height
329 Layout.preferredHeight: delegate.height
332 Layout.fillWidth: true
334 Layout.fillWidth: true
338 Layout.fillWidth: true
345 text: player.time2str(model.duration)
351 playlist.currentIndex = model.index
356 highlight: Rectangle {