From dab599910891f8df50879465b7747741efbd5d82 Mon Sep 17 00:00:00 2001 From: John Hu Date: Tue, 26 Nov 2013 11:11:26 -0600 Subject: [PATCH] Bug 938967 - [fugu][hamachi]The video had be sought to 00:00 could not be played from background to foreground --- apps/video/js/video.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/video/js/video.js b/apps/video/js/video.js index c965fe82832a..8da009938544 100644 --- a/apps/video/js/video.js +++ b/apps/video/js/video.js @@ -75,7 +75,7 @@ var pendingPick; // But Camera and Gallery also need to use that hardware, and those three apps // may only have one video playing at a time among them. So we need to be // careful to relinquish the hardware when we are not visible. -var restoreTime; +var restoreTime = null; // Videos recorded by our own camera have filenames of this form var FROMCAMERA = /DCIM\/\d{3}MZLLA\/VID_\d{4}\.3gp$/; @@ -982,12 +982,22 @@ function releaseVideo() { // Call this when the app becomes visible again function restoreVideo() { - if (!restoreTime) { - return; - } + // When restoreVideo is called, we assume we have currentVideo because the + // playerShowing is true. setVideoUrl(dom.player, currentVideo, function() { setPlayerSize(); - dom.player.currentTime = restoreTime; + // Everything is ready, start to restore last playing time. + if (restoreTime !== null) { + // restore to the last time when we have a valid restoreTime. + dom.player.currentTime = restoreTime; + } else { + // When we don't have valid restoreTime, we need to restore to the last + // viewing position from metadata. When user taps on a unwatched video and + // presses home quickly, the dom.player may not finish the loading of + // video and the restoreTime is null. At the same case, the currentTime of + // metadata is still undefined because we haven't updateMetadata. + dom.player.currentTime = currentVideo.metadata.currentTime || 0; + } }); }