Image player will now remember what image it was last on 84/10884/1 accepted/tizen/20131015.161745 submit/tizen/20131015.010041
authorbrianjjones <brian.j.jones@intel.com>
Tue, 15 Oct 2013 00:51:33 +0000 (17:51 -0700)
committerbrianjjones <brian.j.jones@intel.com>
Tue, 15 Oct 2013 00:52:41 +0000 (17:52 -0700)
Change-Id: Ie43bf070f70aefe85e1d4d8a7caf641398e47f1c

js/audioPlayer.js
js/imagePlayer.js
js/main.js
js/videoPlayer.js
packaging/MediaPlayer.changes

index 49e30f0..c4b2089 100644 (file)
@@ -35,10 +35,6 @@ AudioPlayer.prototype.play = function()
                                this.clearAudioTimeInterval = setInterval(timeoutFunction.bind(this),500);
                        }
                }
-               else
-               {
-                       this.pause();
-               }
        }
        else
                console.log(this.content[this.listIndex].artists[0] + " : " + this.content[this.listIndex].title + " can't play yet, it hasn't loaded");
@@ -92,7 +88,8 @@ AudioPlayer.prototype.load = function(index, play)
        this.updateMediaName(this.content[this.listIndex].artists[0], this.content[this.listIndex].title, this.content[this.listIndex].coverArt);
        $("#audioSrc").attr("src", this.content[this.listIndex].contentURI);
 
-       if (!this.content[this.listIndex].remoteFile)
+       //Only store track to localStorage if it's a local file, and current menu is the Audio menu
+       if (!this.content[this.listIndex].remoteFile && localStorage.prevMenu === "mainMusicButton")
        {
                localStorage.prevAudioTrack = this.content[this.listIndex].contentURI;
        }
@@ -265,18 +262,15 @@ AudioPlayer.prototype.onContentLoaded = function()
                                        this.listIndex = i;
                                        console.log("MediaPlayer: Previous audio found, loading " + this.content[this.listIndex].contentURI);
                                        this.loadPrevAudio = true;
-                                       $("#audioSrc").attr("src", this.content[this.listIndex].contentURI);
-                                       this.playerControls.load();
                                        this.fillMediaList();
+                                       this.load(i, true);
                                }
                        }
                }
                else
                {
                        console.log("MediaPlayer: No previous audio found, loading first");
-                       $("#audioSrc").attr("src", this.content[0].contentURI);
-                       localStorage.prevAudioTrack = this.content[0].contentURI;
-                       this.playerControls.load();
+                       this.load(0, false);
                        this.updateMediaName(this.content[this.listIndex].artists[0], this.content[this.listIndex].title, this.content[this.listIndex].coverArt);
 
                        if (currentMenu === "audio")
index 9733323..e5d4f59 100644 (file)
@@ -40,8 +40,7 @@ ImagePlayer.prototype.next = function()
                else
                        this.listIndex = 0;
 
-               $("#imagePlayer").css("background", "url(" + this.content[this.listIndex].contentURI + ") no-repeat center");
-               $("#imagePlayer").css("background-size", "contain");
+               this.load(this.listIndex);
        }
 }
 
@@ -54,8 +53,7 @@ ImagePlayer.prototype.previous = function()
                else
                        this.listIndex = this.content.length - 1;
 
-               $("#imagePlayer").css("background", "url(" + this.content[this.listIndex].contentURI + ") no-repeat center");
-               $("#imagePlayer").css("background-size", "contain");
+               this.load(this.listIndex);
        }
 }
 
@@ -63,8 +61,26 @@ ImagePlayer.prototype.onContentLoaded = function()
 {
        try
        {
-               $("#imagePlayer").css("background", "url(" + this.content[0].contentURI + ") no-repeat center");
-               $("#imagePlayer").css("background-size", "contain");
+               this.listIndex = 0;
+
+               if (localStorage.prevImage && localStorage.prevImage !== "undefined")
+               {
+                       for (var i = 0; i < this.content.length; i++)
+                       {
+                               if (this.content[i].contentURI === localStorage.prevImage)
+                               {
+                                       console.log("MediaPlayer: using previous image " + localStorage.prevImage);
+                                       this.listIndex = i;
+                                       this.fillMediaList();
+                                       this.load(i);
+                               }
+                       }
+               }
+               else
+               {
+                       console.log("MediaPlayer: using first image " + this.content[this.listIndex].contentURI);
+                       this.load(this.listIndex);
+               }
        }
 
        catch (err)
@@ -76,8 +92,18 @@ ImagePlayer.prototype.onContentLoaded = function()
 ImagePlayer.prototype.load = function(index)
 {
        this.listIndex = index;
-    $("#imagePlayer").css("background", "url(" + this.content[this.listIndex].contentURI + ") no-repeat center");
-    $("#imagePlayer").css("background-size", "contain");
+
+       if (!this.content[this.listIndex].remoteFile)
+       {
+               localStorage.prevImage = this.content[this.listIndex].contentURI;
+       }
+       else
+       {
+               localStorage.prevImage = undefined;
+       }
+
+       $("#imagePlayer").css("background", "url(" + this.content[this.listIndex].contentURI + ") no-repeat center");
+       $("#imagePlayer").css("background-size", "contain");
 }
 
 ImagePlayer.prototype.makeListItem = function(j, k)
index 5797327..d278d89 100644 (file)
@@ -286,7 +286,7 @@ function changeMenu(menuButtonId)
                        currentMediaList = $("#audioMediaList");
                        localStorage.prevMenu = "mainMusicButton";
 
-                       if (audioPlayer.currentAudioContent)
+                       if (audioPlayer.currentAudioContent && audioPlayer.currentAudioContent.contentURI)
                        {
                                localStorage.prevAudioTrack = audioPlayer.currentAudioContent.contentURI
                                localStorage.prevAudioTime = audioPlayer.playerControls.currentTime;
@@ -307,6 +307,13 @@ function changeMenu(menuButtonId)
                        currentPlayer = videoPlayer;
                        currentMediaList = $("#videoMediaList");
                        localStorage.prevMenu = "mainVideoButton";
+
+                       if (videoPlayer.currentVideoContent && videoPlayer.currentVideoContent.contentURI)
+                       {
+                               localStorage.prevVideo = videoPlayer.currentVideoContent.contentURI
+                               localStorage.prevVideoTime = videoPlayer.playerControls.currentTime;
+                       }
+
                        localStorage.prevAudioTime = undefined;
                        localStorage.prevAudioTrack = undefined;
 
@@ -336,13 +343,15 @@ function changeMenu(menuButtonId)
 
 function showMainMenu()
 {
-       console.log("MediaPlayer in showMainMenu");
+       console.log("MediaPlayer in showMainMenu, clearing all localStorage...");
        currentMenu = "main";
        localStorage.prevMenu = "MAIN";
        localStorage.prevAudioTime = undefined;
        localStorage.prevAudioTrack = undefined;
        localStorage.prevVideo = undefined;
        localStorage.prevVideoTime = undefined;
+       localStorage.prevImage = undefined;
+
        currentPlayer.pause();
 
        //If the media list is showing, hide it.  Remove the mediaListAudioList class if it exists so that it will resize properly
index ca14eda..559f2a2 100644 (file)
@@ -12,6 +12,7 @@ VideoPlayer = function()
 {
        this.clearVideoTimeInterval = undefined;
        this.loadPrevVideo = false;
+       this.currentVideoContent = undefined;
 }
 
 VideoPlayer.prototype.play = function()
@@ -33,10 +34,6 @@ VideoPlayer.prototype.play = function()
                        this.clearVideoTimeInterval = setInterval(timeoutFunction.bind(this),500);
                }
        }
-       else
-       {
-               this.pause();
-       }
 }
 
 VideoPlayer.prototype.pause = function()
@@ -82,10 +79,12 @@ VideoPlayer.prototype.load = function(index, play)
 {
        this.listIndex = index;
        this.loadAndPlay = play;
+       this.currentVideoContent = this.content[this.listIndex];
        this.playerControls.pause();
        $("#videoSrc").attr("src", this.content[this.listIndex].contentURI);
 
-       if (!this.content[this.listIndex].remoteFile)
+       //Only store track to localStorage if it's a local file, and current menu is the Video menu
+       if (!this.content[this.listIndex].remoteFile && localStorage.prevMenu === "mainVideoButton")
        {
                localStorage.prevVideo = this.content[this.listIndex].contentURI;
        }
@@ -123,21 +122,18 @@ VideoPlayer.prototype.onContentLoaded = function()
                        {
                                if (this.content[i].contentURI === localStorage.prevVideo)
                                {
-                                       console.log("MediaPlayer: Previous video found, loading " + this.content[this.listIndex].contentURI);
+                                       console.log("MediaPlayer: Previous video found, loading " + this.content[i].contentURI);
                                        this.listIndex = i;
                                        this.loadPrevVideo = true;
-                                       $("#videoSrc").attr("src", this.content[this.listIndex].contentURI);
                                        this.fillMediaList();
-                                       this.playerControls.load();
+                                       this.load(i, true);
                                }
                        }
                }
                else
                {
                        console.log("MediaPlayer: No previous video found, loading first");
-                       $("#videoSrc").attr("src", this.content[0].contentURI);
-                       localStorage.prevVideo = this.content[0].contentURI;
-                       this.playerControls.load();
+                       this.load(0,false);
                }
        }
 
index 4415bb7..f092b0f 100644 (file)
@@ -1,3 +1,6 @@
+* Mon Oct 14 2013 brianjjones <brian.j.jones@intel.com> submit/tizen/20131010.205318@a65dc75
+- Image player will now remember what image it was last on
+
 * Tue Oct 08 2013 brianjjones <brian.j.jones@intel.com> accepted/tizen/20131004.164521@81d77fa
 - Re-organizing the code so that the players are object based. Adding code to remember
   what page you were on as well as the previous media