Added the ability to control playback volume from post capture
[harmattan/cameraplus] / qml / VideoPlayerPage.qml
index 490e6b6..8d78df3 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-import QtQuick 1.1
-import com.nokia.meego 1.1
-import QtMultimediaKit 1.1
+import QtQuick 2.0
 import CameraPlus 1.0
-
-// TODO: error reporting
+import QtCamera 1.0
+import QtCameraExtras 1.0
 
 Item {
     id: page
@@ -34,7 +32,11 @@ Item {
     property alias source: video.source
 
     function play() {
-        video.play()
+        return video.play()
+    }
+
+    function stop() {
+        return video.stop()
     }
 
     MouseArea {
@@ -53,19 +55,63 @@ Item {
         onTriggered: toolBar.show = false
     }
 
-    Video {
+    DeviceKeys {
+        id: zoomKeys
+        active: Qt.application.active && pipelineManager.scaleAcquired
+        repeat: true
+
+        onVolumeUpPressed: {
+            timer.restart()
+            video.volume = Math.min(video.volume + 2, 100)
+        }
+
+        onVolumeDownPressed: {
+            timer.restart()
+            video.volume = Math.max(video.volume - 2, 0)
+        }
+    }
+
+    VideoPlayer {
+        Rectangle {
+            id: volumeControl
+            anchors.top: parent.top
+            anchors.left: parent.left
+            width: (parent.width * video.volume) / 100
+            color: "blue"
+            border.color: "black"
+            height: 25
+            opacity: timer.running ? 1.0 : 0.0
+
+            Behavior on opacity {
+                NumberAnimation { duration: 250 }
+            }
+
+            Timer {
+                id: timer
+                interval: 500
+                repeat: false
+            }
+        }
+
         id: video
         anchors.fill: parent
+        cameraConfig: camera.cameraConfig
+
+        onError: showError(qsTr("Error playing video. Please try again or restart the application"))
 
         function toggle() {
-            if (!video.paused) {
+            if (state != VideoPlayer.StatePaused) {
                 video.pause()
             } else {
                 page.play()
             }
         }
 
-        onStopped: page.finished()
+        onStateChanged: {
+            if (state == VideoPlayer.StateStopped) {
+                page.finished()
+            }
+        }
     }
 
     Connections {
@@ -82,32 +128,32 @@ Item {
 
         property bool show: true
 
-        manualBack: true
+        hideBack: true
         expanded: true
         anchors.bottom: parent.bottom
-        anchors.bottomMargin: show ? 20 : -1 * (height + 20)
+        anchors.bottomMargin: 20
         anchors.left: parent.left
         anchors.leftMargin: 20
-        opacity: 0.5
+        opacity: show ? 0.8 : 0.0
+        visible: opacity > 0
 
-        Behavior on anchors.bottomMargin {
+        Behavior on opacity {
             PropertyAnimation { duration: 200; }
         }
 
-        items: [
-            ToolIcon {
-                iconId: "icon-m-toolbar-mediacontrol-stop-white"
+        tools: CameraToolBarTools {
+            CameraToolIcon {
+                iconSource: cameraTheme.videoStopIconId
                 onClicked: video.stop()
-            },
-            Slider {
+            }
+
+            CameraSlider {
                 id: slider
                 height: toolBar.height
                 anchors.verticalCenter: parent.verticalCenter
 
-                platformStyle: SliderStyle {
-                    handleBackground: ""
-                    handleBackgroundPressed: ""
-                }
+                handleBackground: ""
+                handleBackgroundPressed: ""
 
                 minimumValue: 0
                 maximumValue: video.duration
@@ -121,15 +167,16 @@ Item {
 
                     hideTimer.restart()
                 }
-            },
-            ToolIcon {
+            }
+
+            CameraToolIcon {
                 id: control
-                iconId: !video.paused ? "icon-m-toolbar-mediacontrol-pause-white" : "icon-m-toolbar-mediacontrol-play-white"
+                iconSource: video.state != VideoPlayer.StatePaused ? cameraTheme.videoPauseIconId : cameraTheme.videoPlayIconId
                 onClicked: {
                     video.toggle()
                     hideTimer.restart()
                 }
             }
-        ]
+        }
     }
 }