2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2017 Toyota Motor Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 import QtQuick.Layouts 1.1
20 import QtQuick.Controls 2.0
21 import QtMultimedia 5.6
22 import AGL.Demo.Controls 1.0
23 import MediaPlayer 1.0
24 import QtQml.StateMachine 1.0 as MPSM
30 property int sourceID: 0
31 property int connectionID
32 property int sourceIndex
34 signal playMediaplayer
35 signal stopMediaplayer
40 API.LightMediaScanner {
45 API.BluetoothManager {
52 audioRole: MediaPlayer.MusicRole
56 function time2str(value) {
57 return Qt.formatTime(new Date(value), 'mm:ss')
67 MPSM.SignalTransition{
71 MPSM.SignalTransition{
75 MPSM.SignalTransition{
77 signal: playMediaplayer
80 console.log("enter haveSoundRight")
88 MPSM.SignalTransition{
89 targetState: haveSoundRight
93 console.log("enter stop state")
101 MPSM.SignalTransition{
102 targetState: haveSoundRight
105 MPSM.SignalTransition{
110 console.log("enter pause state")
118 MPSM.SignalTransition{
119 targetState: haveSoundRight
120 signal: stopMediaplayer
122 MPSM.SignalTransition{
123 targetState: lostSoundRight
127 console.log("enter playing state")
136 MPSM.SignalTransition{
141 console.log("enter lostSoundRight")
147 id: temporaryLostSoundRight
148 MPSM.SignalTransition{
152 MPSM.SignalTransition{
153 targetState: lostSoundRight
157 console.log("enter lostSoundRight")
164 function slotReply(msg){
165 var jstr = JSON.stringify(msg)
166 var content = JSON.parse(jstr);
167 var verb = content.response.verb
168 var err = content.response.error
173 connectionID = content.response.mainConnectionID
176 case "registerSource":
178 sourceID = content.response.sourceID
183 function slotEvent(event,msg){
184 var jstr = JSON.stringify(msg)
185 var content = JSON.parse(jstr);
186 var eventName = content.event
189 case "soundmanager\/asyncSetSourceState":
190 // This event doesn't come for now
191 if(sourceID == content.data.sourceID){
192 console.log("mediaplayer: call ackSetSourceState")
193 smw.ackSetSourceState(content.data.handle, 0)
194 switch(content.data.sourceState){
217 running: (bluetooth.av_connected && bluetooth.state == "playing")
220 bluetooth.position = bluetooth.position + 250
221 slider.value = bluetooth.position
227 playbackMode: random.checked ? Playlist.Random : loop.checked ? Playlist.Loop : Playlist.Sequential
234 Layout.fillWidth: true
235 Layout.fillHeight: true
236 Layout.preferredHeight: 1080
240 anchors.left: parent.left
241 anchors.right: parent.right
242 anchors.bottom: parent.bottom
243 height: sourceSize.height * width / sourceSize.width
244 fillMode: Image.PreserveAspectCrop
245 source: player.metaData.coverArtImage ? player.metaData.coverArtImage : ''
246 visible: bluetooth.av_connected == false
250 anchors.left: parent.left
251 anchors.right: parent.right
252 anchors.bottom: parent.bottom
262 anchors.margins: root.width * 0.02
264 Layout.fillWidth: true
265 Layout.fillHeight: true
270 visible: bluetooth.connected == false
271 offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
272 onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
276 visible: bluetooth.connected == false
277 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
278 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
285 Layout.alignment: Layout.Center
286 text: bluetooth.av_connected ? bluetooth.title : (player.metaData.title ? player.metaData.title : '')
287 horizontalAlignment: Label.AlignHCenter
288 verticalAlignment: Label.AlignVCenter
291 Layout.alignment: Layout.Center
292 text: bluetooth.av_connected ? bluetooth.artist : (player.metaData.contributingArtist ? player.metaData.contributingArtist : '')
293 horizontalAlignment: Label.AlignHCenter
294 verticalAlignment: Label.AlignVCenter
295 font.pixelSize: title.font.pixelSize * 0.6
301 Layout.fillWidth: true
302 to: bluetooth.av_connected ? bluetooth.duration : player.duration
303 enabled: bluetooth.av_connected == false
304 value: bluetooth.av_connected ? bluetooth.position : player.position
305 function getPosition() {
306 if (bluetooth.av_connected) {
307 return player.time2str(bluetooth.position)
309 return player.time2str(player.position)
313 anchors.left: parent.left
314 anchors.bottom: parent.top
316 text: slider.getPosition()
320 anchors.right: parent.right
321 anchors.bottom: parent.top
323 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
325 onPressedChanged: player.seek(value)
328 Layout.fillHeight: true
330 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
333 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
335 Item { Layout.fillWidth: true }
338 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
340 if (bluetooth.av_connected) {
341 bluetooth.sendMediaCommand("Previous")
342 bluetooth.position = 0
350 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
352 if (bluetooth.av_connected) {
353 bluetooth.sendMediaCommand("Play")
360 when: player.playbackState === MediaPlayer.PlayingState
363 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
370 when: bluetooth.av_connected && bluetooth.state == "playing"
373 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
374 onClicked: bluetooth.sendMediaCommand("Pause")
382 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
384 if (bluetooth.av_connected) {
385 bluetooth.sendMediaCommand("Next")
392 Item { Layout.fillWidth: true }
395 visible: bluetooth.connected
396 checked: bluetooth.av_connected
397 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
398 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
401 if (bluetooth.av_connected) {
402 bluetooth.disconnect_profiles()
404 bluetooth.connect_profiles()
413 Layout.fillWidth: true
414 Layout.fillHeight: true
415 Layout.preferredHeight: 407
417 PlaylistWithMetadata {
425 visible: bluetooth.av_connected == false
433 currentIndex: playlist.currentIndex
435 delegate: MouseArea {
437 width: ListView.view.width
438 height: ListView.view.height / 4
441 anchors.leftMargin: 50
442 anchors.rightMargin: 50
444 source: model.coverArt
445 fillMode: Image.PreserveAspectFit
446 Layout.preferredWidth: delegate.height
447 Layout.preferredHeight: delegate.height
450 Layout.fillWidth: true
452 Layout.fillWidth: true
456 Layout.fillWidth: true
463 text: player.time2str(model.duration)
469 playlist.currentIndex = model.index
470 sourceIndex = model.index;
471 console.log("mediaplayer: call connect")
476 highlight: Rectangle {
482 Component.onCompleted: {
483 smw.registerSource("mediaplayer")