@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import QtMultimedia 5.0
1919import Ubuntu.Components 1.3
2020import Ubuntu.Thumbnailer 0.1
21+import "PreviewSingleton"
2122import "../../Components"
2223import "../../Components/MediaServices"
2324
@@ -36,9 +37,35 @@ PreviewWidget {
3637 orientationLock: services.fullscreen
3738
3839 property alias rootItem: services.rootItem
40+ readonly property string widgetExtraDataKey: services.source.toString()
41+
42+ onWidgetExtraDataKeyChanged: {
43+ root.restorePlaybackState();
44+ }
45+
46+ function seek() {
47+ services.mediaPlayer.seek(services.initialPosition);
48+ services.initialPosition = -1;
49+ }
50+
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;
55+ } else {
56+ PreviewSingleton.widgetExtraData[widgetExtraDataKey] = services.mediaPlayer.position;
57+ }
58+ }
59+
60+ function restorePlaybackState() {
61+ if (PreviewSingleton.widgetExtraData[widgetExtraDataKey] > 0) {
62+ services.initialPosition = PreviewSingleton.widgetExtraData[widgetExtraDataKey];
63+ }
64+ }
3965
4066 MediaServices {
4167 id: services
68+ objectName: "services"
4269 width: parent.width
4370
4471 actions: sharingAction
@@ -47,8 +74,28 @@ PreviewWidget {
4774 fullscreen: false
4875 maximumEmbeddedHeight: rootItem.height / 2
4976
77+ property int initialPosition: -1
78+
79+ readonly property var mediaPlayer: footer.mediaPlayer
80+ readonly property url source: mediaPlayer.source
81+ readonly property int position: mediaPlayer.position
82+
5083 onClose: fullscreen = false
5184
85+ onPositionChanged: {
86+ if (mediaPlayer.playbackState === MediaPlayer.StoppedState) return;
87+ root.storePlaybackState();
88+ }
89+
90+ Connections {
91+ target: services.mediaPlayer
92+ ignoreUnknownSignals: true
93+ onPlaying: {
94+ // at the first playback of the file, do a seek()
95+ if (services.initialPosition > 0) root.seek();
96+ }
97+ }
98+
5299 Action {
53100 id: sharingAction
54101 iconName: "share"