Update VIS vehicle signal support
[apps/mediaplayer.git] / app / MediaPlayer.qml
index 7cca337..03c85c4 100644 (file)
  * limitations under the License.
  */
 
-import QtQuick 2.6
-import QtQuick.Layouts 1.1
-import QtQuick.Controls 2.0
+import QtQuick 2.11
+import QtQuick.Layouts 1.11
+import QtQuick.Controls 2.4
+import QtQuick.Window 2.13
+
 import AGL.Demo.Controls 1.0
 
 ApplicationWindow {
@@ -37,14 +39,20 @@ ApplicationWindow {
         property int duration: 0
         property int position: 0
 
-        property string cover_art: ""
         property string status: "stopped"
 
         function time2str(value) {
-            return Qt.formatTime(new Date(value), 'mm:ss')
+            return Qt.formatTime(new Date(value), (value > 3600000) ? 'hh:mm:ss' : 'mm:ss')
         }
     }
 
+    Component.onCompleted : {
+        // Let the mediaplayer backend know we're ready for metadata events
+        mediaplayer.start()
+
+        VehicleSignals.connect()
+    }
+
     Connections {
         target: mediaplayer
 
@@ -59,24 +67,51 @@ ApplicationWindow {
                 player.av_connected = metadata.connected
             }
 
-            if ('position' in metadata) {
-                player.position = metadata.position
-            }
-
             if (track) {
-                if ('image' in track) {
-                     player.cover_art = track.image
-                }
-
+                if ('image' in track)
+                     return
                 player.title = track.title
                 player.album = track.album
                 player.artist = track.artist
-                player.duration = track.duration
+
+                if ('duration' in track)
+                     player.duration = track.duration
 
                 if ('index' in track) {
                      playlistview.currentIndex = track.index
                 }
             }
+
+            if ('position' in metadata) {
+                player.position = metadata.position
+            }
+        }
+    }
+
+    Connections {
+        target: VehicleSignals
+
+        onConnected: {
+           VehicleSignals.authorize()
+        }
+
+        onAuthorized: {
+           VehicleSignals.subscribe("Vehicle.Cabin.SteeringWheel.Switches.Next")
+           VehicleSignals.subscribe("Vehicle.Cabin.SteeringWheel.Switches.Previous")
+           VehicleSignals.subscribe("Vehicle.Cabin.SteeringWheel.Switches.Mode")
+       }
+
+        onSignalNotification: {
+            if (path === "Vehicle.Cabin.SteeringWheel.Switches.Next" && value === "true") {
+                mediaplayer.next()
+            } else if (path === "Vehicle.Cabin.SteeringWheel.Switches.Previous" && value === "true") {
+                mediaplayer.previous()
+            } else if (path === "Vehicle.Cabin.SteeringWheel.Switches.Mode" && value === "true") {
+                if (player.av_connected)
+                    mediaplayer.connect()
+                else
+                    mediaplayer.disconnect()
+            }
         }
     }
 
@@ -93,9 +128,10 @@ ApplicationWindow {
     Item {
         id: container
         anchors.centerIn: parent
-        width: 1080
-        height: 1487
-        scale: screenInfo.scale_factor()
+        width: Window.width
+       height: Window.height
+        //scale: screenInfo.scale_factor()
+        scale: 1
 
     ColumnLayout {
         anchors.fill: parent
@@ -105,13 +141,12 @@ ApplicationWindow {
             Layout.preferredHeight: 1080
             clip: true
             Image {
-                id: albumart
                 anchors.left: parent.left
                 anchors.right: parent.right
                 anchors.bottom: parent.bottom
                 height: sourceSize.height * width / sourceSize.width
                 fillMode: Image.PreserveAspectCrop
-                source: player.cover_art ? player.cover_art : ''
+                source: AlbumArt
                 visible: player.av_connected === false
             }
 
@@ -145,7 +180,7 @@ ApplicationWindow {
                                 visible: player.av_connected === false
                                 offImage: './images/AGL_MediaPlayer_Loop_Inactive.svg'
                                 onImage: './images/AGL_MediaPlayer_Loop_Active.svg'
-                                onClicked: { mediaplayer.loop(checked) }
+                                onClicked: { mediaplayer.loop(checked ? "playlist" : "off") }
                             }
                         }
                         ColumnLayout {
@@ -213,7 +248,6 @@ ApplicationWindow {
                                         target: play
                                         offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
                                         onClicked: {
-                                            player.status = "stopped"
                                             mediaplayer.pause()
                                         }
                                     }
@@ -247,8 +281,9 @@ ApplicationWindow {
                                 else
                                         mediaplayer.disconnect()
                               }
-                              offImage: './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
-                              onImage: './images/AGL_MediaPlayer_Bluetooth_Active.svg'
+                              contentItem: Image {
+                                source: player.av_connected ? './images/AGL_MediaPlayer_Bluetooth_Active.svg' : './images/AGL_MediaPlayer_Bluetooth_Inactive.svg'
+                              }
                         }
                     }
                 }