Initial implementation of our own VideoPlayer declarative item
[harmattan/cameraplus] / qml / VideoPlayerPage.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 import QtQuick 1.1
24 import com.nokia.meego 1.1
25 import CameraPlus 1.0
26 import QtCamera 1.0
27 import QtCameraExtras 1.0
28
29 // TODO: error reporting
30
31 Item {
32     id: page
33
34     signal finished
35     property alias source: video.source
36
37     function play() {
38         return video.play()
39     }
40
41     MouseArea {
42         anchors.top: parent.top
43         anchors.bottom: toolBar.top
44         anchors.left: parent.left
45         anchors.right: parent.right
46
47         onClicked: toolBar.show = !toolBar.show
48     }
49
50     Timer {
51         id: hideTimer
52         running: toolBar.show
53         interval: 3000
54         onTriggered: toolBar.show = false
55     }
56
57     VideoPlayer {
58         id: video
59         anchors.fill: parent
60         cameraConfig: cam.cameraConfig
61
62         function toggle() {
63             if (!video.paused) {
64                 video.pause()
65             } else {
66                 page.play()
67             }
68         }
69
70         onStateChanged: {
71             if (state == VideoPlayer.StateStopped) {
72                 page.finished()
73             }
74         }
75     }
76
77     Connections {
78         target: Qt.application
79         onActiveChanged: {
80             if (!Qt.application.active) {
81                 video.stop()
82             }
83         }
84     }
85
86     CameraToolBar {
87         id: toolBar
88
89         property bool show: true
90
91         hideBack: true
92         expanded: true
93         anchors.bottom: parent.bottom
94         anchors.bottomMargin: show ? 20 : -1 * (height + 20)
95         anchors.left: parent.left
96         anchors.leftMargin: 20
97         opacity: 0.5
98
99         Behavior on anchors.bottomMargin {
100             PropertyAnimation { duration: 200; }
101         }
102
103         items: [
104             ToolIcon {
105                 iconId: "icon-m-toolbar-mediacontrol-stop-white"
106                 onClicked: video.stop()
107             },
108             Slider {
109                 id: slider
110                 height: toolBar.height
111                 anchors.verticalCenter: parent.verticalCenter
112
113                 platformStyle: SliderStyle {
114                     handleBackground: ""
115                     handleBackgroundPressed: ""
116                 }
117
118                 minimumValue: 0
119                 maximumValue: video.duration
120                 value: video.position
121                 orientation: Qt.Horizontal
122
123                 onPressedChanged: {
124                     if (!slider.pressed) {
125                         video.position = slider.value
126                     }
127
128                     hideTimer.restart()
129                 }
130             },
131             ToolIcon {
132                 id: control
133                 iconId: !video.paused ? "icon-m-toolbar-mediacontrol-pause-white"
134                     : "icon-m-toolbar-mediacontrol-play-white"
135                 onClicked: {
136                     video.toggle()
137                     hideTimer.restart()
138                 }
139             }
140         ]
141     }
142 }