summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-11-07 17:48:38 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-11-07 18:12:02 +0900
commit7ad0e32937b67ee4c4e77f3374c47bc7966fe514 (patch)
treebf69b8e3b0950dbaf7af0ea075efe87ef97870e7
parentaddf2b6d6a9d97ccf1fe267a1e6767fac9466202 (diff)
Adopt statemachine class to manage sound right
Change-Id: Id43ee7e08381c77c9ee581a0dceb4bac04126830 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r--app/MediaPlayer.qml175
-rw-r--r--app/app.pri6
-rw-r--r--app/app.pro2
3 files changed, 172 insertions, 11 deletions
diff --git a/app/MediaPlayer.qml b/app/MediaPlayer.qml
index a297162..a9e44e0 100644
--- a/app/MediaPlayer.qml
+++ b/app/MediaPlayer.qml
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 The Qt Company Ltd.
+ * Copyright (C) 2017 Toyota Motor Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,11 +20,19 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
import QtMultimedia 5.6
import AGL.Demo.Controls 1.0
+import QtQml.StateMachine 1.0 as MPSM
import 'api' as API
ApplicationWindow {
id: root
-
+
+ property int sourceID: 0
+ property int connectionID
+ signal playMediaplayer
+ signal stopMediaplayer
+ signal disconnected
+ signal paused
+ signal connected
API.MediaPlayer {
id: player
url: bindingAddress
@@ -34,6 +43,159 @@ ApplicationWindow {
url: bindingAddress
}
+ MPSM.StateMachine{
+ id: mediaplayerState
+ initialState: stop
+ running: true
+ MPSM.State{
+ id: haveSoundRight
+ MPSM.SignalTransition{
+ targetState: stop
+ signal: disconnected
+ }
+ MPSM.SignalTransition{
+ targetState: pause
+ signal: paused
+ }
+ MPSM.SignalTransition{
+ targetState: playing
+ signal: playMediaplayer
+ }
+ onEntered: {
+ console.log("enter haveSoundRight")
+ }
+ onExited : {
+ // Nothing to do
+ }
+ }
+ MPSM.State{
+ id: stop
+ MPSM.SignalTransition{
+ targetState: haveSoundRight
+ signal: connected
+ }
+ onEntered: {
+ console.log("enter stop state")
+ }
+ onExited : {
+ // Nothing to do
+ }
+ }
+ MPSM.State{
+ id: pause
+ MPSM.SignalTransition{
+ targetState: haveSoundRight
+ signal: connected
+ }
+ MPSM.SignalTransition{
+ targetState: stop
+ signal: disconnected
+ }
+ onEntered: {
+ console.log("enter pause state")
+ }
+ onExited : {
+ // Nothing to do
+ }
+ }
+ MPSM.State{
+ id: playing
+ MPSM.SignalTransition{
+ targetState: haveSoundRight
+ signal: stopMediaplayer
+ }
+ MPSM.SignalTransition{
+ targetState: lostSoundRight
+ signal: disconnected
+ }
+ onEntered: {
+ console.log("enter playing state")
+ player.play()
+ }
+ onExited : {
+ player.pause()
+ }
+ }
+ MPSM.State{
+ id: lostSoundRight
+ MPSM.SignalTransition{
+ targetState: playing
+ signal: connected
+ }
+ onEntered: {
+ console.log("enter lostSoundRight")
+ }
+ onExited : {
+ }
+ }
+ MPSM.State{
+ id: temporaryLostSoundRight
+ MPSM.SignalTransition{
+ targetState: playing
+ signal: connected
+ }
+ MPSM.SignalTransition{
+ targetState: lostSoundRight
+ signal: disconnected
+ }
+ onEntered: {
+ console.log("enter lostSoundRight")
+ }
+ onExited : {
+ }
+ }
+ }
+
+ function slotReply(msg){
+ var jstr = JSON.stringify(msg)
+ var content = JSON.parse(jstr);
+ var verb = content.response.verb
+ var err = content.response.error
+ switch(verb)
+ {
+ case "connect":
+ if(err == 0){
+ connectionID = content.response.mainConnectionID
+ }
+ break;
+ case "registerSource":
+ if(err == 0){
+ sourceID = content.response.sourceID
+ }
+ }
+ }
+
+ function slotEvent(event,msg){
+ var jstr = JSON.stringify(msg)
+ var content = JSON.parse(jstr);
+ var eventName = content.event
+ switch(eventName)
+ {
+ case "soundmanager\/asyncSetSourceState":
+ // This event doesn't come for now
+ if(sourceID == content.data.sourceID){
+ console.log("mediaplayer: call ackSetSourceState")
+ smw.ackSetSourceState(content.data.handle, 0)
+ switch(content.data.sourceState){
+ case "on":
+ connected()
+ break;
+ case "off":
+ disconnected()
+ break;
+ case "paused":
+ paused()
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
Timer {
id: timer
interval: 250
@@ -175,7 +337,7 @@ ApplicationWindow {
if (bluetooth.av_connected) {
bluetooth.sendMediaCommand("Play")
} else {
- player.play()
+ playMediaplayer()
}
}
states: [
@@ -184,7 +346,9 @@ ApplicationWindow {
PropertyChanges {
target: play
offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
- onClicked: player.pause()
+ onClicked: {
+ stopMediaplayer()
+ }
}
},
State {
@@ -277,7 +441,7 @@ ApplicationWindow {
}
onClicked: {
player.pick_track(playlistview.model.get(index).index)
- player.play()
+ playMediaplayer()
}
}
@@ -287,5 +451,8 @@ ApplicationWindow {
}
}
}
+ Component.onCompleted: {
+ smw.registerSource("mediaplayer")
+ }
}
}
diff --git a/app/app.pri b/app/app.pri
index df50dea..8326056 100644
--- a/app/app.pri
+++ b/app/app.pri
@@ -4,12 +4,6 @@ QMAKE_LFLAGS += "-Wl,--hash-style=gnu -Wl,--as-needed"
load(configure)
qtCompileTest(libhomescreen)
-config_libhomescreen {
- CONFIG += link_pkgconfig
- PKGCONFIG += homescreen
- DEFINES += HAVE_LIBHOMESCREEN
-}
-
packagesExist(sqlite3 lightmediascanner) {
DEFINES += HAVE_LIGHTMEDIASCANNER
}
diff --git a/app/app.pro b/app/app.pro
index 5a0280e..bc070f8 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -1,5 +1,5 @@
TARGET = mediaplayer
-QT = quickcontrols2
+QT = quickcontrols2 qml
HEADERS = qlibwindowmanager.h qlibsoundmanager.h
SOURCES = main.cpp qlibwindowmanager.cpp qlibsoundmanager.cpp