2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import QtMultimedia 5.0
19 import Ubuntu.Components 1.3
20 import Ubuntu.Thumbnailer 0.1
21 import "PreviewSingleton"
22 import "../../Components"
23 import "../../Components/MediaServices"
25 /*! \brief Preview widget for video.
27 This widget shows video contained in widgetData["source"],
28 with a placeholder screenshot specified by widgetData["screenshot"].
33 implicitWidth: units.gu(35)
34 implicitHeight: services.height
36 singleColumnMarginless: true
37 orientationLock: services.fullscreen
39 property alias rootItem: services.rootItem
40 readonly property string widgetExtraDataKey: services.source.toString()
42 onWidgetExtraDataKeyChanged: {
43 root.restorePlaybackState();
47 services.mediaPlayer.seek(services.initialPosition);
48 services.initialPosition = -1;
51 function storePlaybackState() {
52 if ((services.mediaPlayer.duration - services.mediaPlayer.position) < 1000) {
53 // we're at the end of the video
54 PreviewSingleton.widgetExtraData[widgetExtraDataKey] = 0;
56 PreviewSingleton.widgetExtraData[widgetExtraDataKey] = services.mediaPlayer.position;
60 function restorePlaybackState() {
61 if (PreviewSingleton.widgetExtraData[widgetExtraDataKey] > 0) {
62 services.initialPosition = PreviewSingleton.widgetExtraData[widgetExtraDataKey];
68 objectName: "services"
71 actions: sharingAction
73 sourceData: widgetData
75 maximumEmbeddedHeight: rootItem.height / 2
77 property int initialPosition: -1
79 readonly property var mediaPlayer: footer.mediaPlayer
80 readonly property url source: mediaPlayer.source
81 readonly property int position: mediaPlayer.position
83 onClose: fullscreen = false
86 if (mediaPlayer.playbackState === MediaPlayer.StoppedState) return;
87 root.storePlaybackState();
91 target: services.mediaPlayer
92 ignoreUnknownSignals: true
94 // at the first playback of the file, do a seek()
95 if (services.initialPosition > 0) root.seek();
102 visible: sharingPicker.active
103 onTriggered: sharingPicker.showPeerPicker()
109 objectName: "sharingPicker"
110 shareData: widgetData["share-data"]