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 QtQml.StateMachine 1.0 as MPSM
29 property int sourceID: 0
30 property int connectionID
31 signal playMediaplayer
32 signal stopMediaplayer
41 API.BluetoothManager {
52 MPSM.SignalTransition{
56 MPSM.SignalTransition{
60 MPSM.SignalTransition{
62 signal: playMediaplayer
65 console.log("enter haveSoundRight")
73 MPSM.SignalTransition{
74 targetState: haveSoundRight
78 console.log("enter stop state")
86 MPSM.SignalTransition{
87 targetState: haveSoundRight
90 MPSM.SignalTransition{
95 console.log("enter pause state")
103 MPSM.SignalTransition{
104 targetState: haveSoundRight
105 signal: stopMediaplayer
107 MPSM.SignalTransition{
108 targetState: lostSoundRight
112 console.log("enter playing state")
121 MPSM.SignalTransition{
126 console.log("enter lostSoundRight")
132 id: temporaryLostSoundRight
133 MPSM.SignalTransition{
137 MPSM.SignalTransition{
138 targetState: lostSoundRight
142 console.log("enter lostSoundRight")
149 function slotReply(msg){
150 var jstr = JSON.stringify(msg)
151 var content = JSON.parse(jstr);
152 var verb = content.response.verb
153 var err = content.response.error
158 connectionID = content.response.mainConnectionID
161 case "registerSource":
163 sourceID = content.response.sourceID
168 function slotEvent(event,msg){
169 var jstr = JSON.stringify(msg)
170 var content = JSON.parse(jstr);
171 var eventName = content.event
174 case "soundmanager\/asyncSetSourceState":
175 // This event doesn't come for now
176 if(sourceID == content.data.sourceID){
177 console.log("mediaplayer: call ackSetSourceState")
178 smw.ackSetSourceState(content.data.handle, 0)
179 switch(content.data.sourceState){
202 running: (bluetooth.av_connected && bluetooth.state == "playing")
205 bluetooth.position = bluetooth.position + 250
206 slider.value = bluetooth.position
217 Layout.fillWidth: true
218 Layout.fillHeight: true
219 Layout.preferredHeight: 1080
223 anchors.left: parent.left
224 anchors.right: parent.right
225 anchors.bottom: parent.bottom
226 height: sourceSize.height * width / sourceSize.width
227 fillMode: Image.PreserveAspectCrop
228 source: player.cover_art ? player.cover_art : ''
229 visible: bluetooth.av_connected == false
233 anchors.left: parent.left
234 anchors.right: parent.right
235 anchors.bottom: parent.bottom
245 anchors.margins: root.width * 0.02
247 Layout.fillWidth: true
248 Layout.fillHeight: true
253 // visible: bluetooth.connected == false
254 // offImage: './images/AGL_MediaPlayer_Shuffle_Inactive.svg'
255 // onImage: './images/AGL_MediaPlayer_Shuffle_Active.svg'
259 visible: bluetooth.connected == false
260 checked: player.loop_state
261 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
262 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
263 onClicked: { player.loop(checked) }
270 Layout.alignment: Layout.Center
271 text: bluetooth.av_connected ? bluetooth.title : (player.title ? player.title : '')
272 horizontalAlignment: Label.AlignHCenter
273 verticalAlignment: Label.AlignVCenter
276 Layout.alignment: Layout.Center
277 text: bluetooth.av_connected ? bluetooth.artist : (player.artist ? player.artist : '')
278 horizontalAlignment: Label.AlignHCenter
279 verticalAlignment: Label.AlignVCenter
280 font.pixelSize: title.font.pixelSize * 0.6
286 Layout.fillWidth: true
287 to: bluetooth.av_connected ? bluetooth.duration : player.duration
288 enabled: bluetooth.av_connected == false
289 value: bluetooth.av_connected ? bluetooth.position : player.position
290 function getPosition() {
291 if (bluetooth.av_connected) {
292 return player.time2str(bluetooth.position)
294 return player.time2str(player.position)
298 anchors.left: parent.left
299 anchors.bottom: parent.top
301 text: slider.getPosition()
305 anchors.right: parent.right
306 anchors.bottom: parent.top
308 text: bluetooth.av_connected ? player.time2str(bluetooth.duration) : player.time2str(player.duration)
310 onPressedChanged: player.seek(value)
313 Layout.fillHeight: true
315 // source: './images/AGL_MediaPlayer_Playlist_Inactive.svg'
318 // source: './images/AGL_MediaPlayer_CD_Inactive.svg'
320 Item { Layout.fillWidth: true }
323 offImage: './images/AGL_MediaPlayer_BackArrow.svg'
325 if (bluetooth.av_connected) {
326 bluetooth.sendMediaCommand("Previous")
327 bluetooth.position = 0
335 offImage: './images/AGL_MediaPlayer_Player_Play.svg'
337 if (bluetooth.av_connected) {
338 bluetooth.sendMediaCommand("Play")
345 when: player.running === true
348 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
355 when: bluetooth.av_connected && bluetooth.state == "playing"
358 offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
359 onClicked: bluetooth.sendMediaCommand("Pause")
367 offImage: './images/AGL_MediaPlayer_ForwardArrow.svg'
369 if (bluetooth.av_connected) {
370 bluetooth.sendMediaCommand("Next")
377 Item { Layout.fillWidth: true }
380 visible: bluetooth.connected
381 checked: bluetooth.av_connected
382 offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
383 onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
386 if (bluetooth.av_connected) {
387 bluetooth.disconnect_profiles()
389 bluetooth.connect_profiles()
398 Layout.fillWidth: true
399 Layout.fillHeight: true
400 Layout.preferredHeight: 407
405 visible: bluetooth.av_connected == false
415 delegate: MouseArea {
417 width: ListView.view.width
418 height: ListView.view.height / 4
421 anchors.leftMargin: 50
422 anchors.rightMargin: 50
424 Layout.fillWidth: true
426 Layout.fillWidth: true
430 Layout.fillWidth: true
437 // text: player.time2str(model.duration)
439 // font.pixelSize: 32
443 player.pick_track(playlistview.model.get(index).index)
448 highlight: Rectangle {
454 Component.onCompleted: {
455 smw.registerSource("mediaplayer")