Add VIS vehicle signal support
[apps/mediaplayer.git] / app / MediaPlayer.qml
index 177fe36..95bc22b 100644 (file)
@@ -49,6 +49,8 @@ ApplicationWindow {
     Component.onCompleted : {
         // Let the mediaplayer backend know we're ready for metadata events
         mediaplayer.start()
+
+        VehicleSignals.connect()
     }
 
     Connections {
@@ -86,6 +88,33 @@ ApplicationWindow {
         }
     }
 
+    Connections {
+        target: VehicleSignals
+
+        onConnected: {
+           VehicleSignals.authorize()
+        }
+
+        onAuthorized: {
+           VehicleSignals.subscribe("Vehicle.Cabin.Infotainment.Media.Action")
+       }
+
+        onSignalNotification: {
+            if (path === "Vehicle.Cabin.Infotainment.Media.Action") {
+                if (value == "SkipForward") {
+                    mediaplayer.next()
+                } else if (value == "SkipBackward") {
+                    mediaplayer.previous()
+                } else if (value == "NextSource") {
+                    if (player.av_connected)
+                        mediaplayer.connect()
+                    else
+                        mediaplayer.disconnect()
+                }
+            }
+        }
+    }
+
     Timer {
         id: timer
         interval: 250