Image player will now remember what image it was last on
[profile/ivi/MediaPlayer.git] / js / imagePlayer.js
1
2 /*
3  * Copyright (c) 2013, Intel Corporation.
4  *
5  * This program is licensed under the terms and conditions of the
6  * Apache License, version 2.0.  The full text of the Apache License is at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  */
10
11 ImagePlayer = function()
12 {
13
14 }
15
16 ImagePlayer.prototype.play = function()
17 {
18         console.log("MediaPlayer in ImagePlayer::play");
19         if (this.playerControls.paused)
20                 this.playerControls.play();
21 }
22
23 ImagePlayer.prototype.pause = function()
24 {
25         if (!this.playerControls.paused)
26                 this.playerControls.pause();
27 }
28
29 ImagePlayer.prototype.playing = function()
30 {
31         return !(this.playerControls.paused);
32 }
33
34 ImagePlayer.prototype.next = function()
35 {
36         if (this.content)
37         {
38                 if (this.content.length > (this.listIndex + 1))
39                         this.listIndex++;
40                 else
41                         this.listIndex = 0;
42
43                 this.load(this.listIndex);
44         }
45 }
46
47 ImagePlayer.prototype.previous = function()
48 {
49         if (this.content)
50         {
51                 if (this.listIndex > 0 )
52                         this.listIndex--;
53                 else
54                         this.listIndex = this.content.length - 1;
55
56                 this.load(this.listIndex);
57         }
58 }
59
60 ImagePlayer.prototype.onContentLoaded = function()
61 {
62         try
63         {
64                 this.listIndex = 0;
65
66                 if (localStorage.prevImage && localStorage.prevImage !== "undefined")
67                 {
68                         for (var i = 0; i < this.content.length; i++)
69                         {
70                                 if (this.content[i].contentURI === localStorage.prevImage)
71                                 {
72                                         console.log("MediaPlayer: using previous image " + localStorage.prevImage);
73                                         this.listIndex = i;
74                                         this.fillMediaList();
75                                         this.load(i);
76                                 }
77                         }
78                 }
79                 else
80                 {
81                         console.log("MediaPlayer: using first image " + this.content[this.listIndex].contentURI);
82                         this.load(this.listIndex);
83                 }
84         }
85
86         catch (err)
87         {
88                 console.log("MediaPlayer: Error when parsing imageContent");
89         }
90 }
91
92 ImagePlayer.prototype.load = function(index)
93 {
94         this.listIndex = index;
95
96         if (!this.content[this.listIndex].remoteFile)
97         {
98                 localStorage.prevImage = this.content[this.listIndex].contentURI;
99         }
100         else
101         {
102                 localStorage.prevImage = undefined;
103         }
104
105         $("#imagePlayer").css("background", "url(" + this.content[this.listIndex].contentURI + ") no-repeat center");
106         $("#imagePlayer").css("background-size", "contain");
107 }
108
109 ImagePlayer.prototype.makeListItem = function(j, k)
110 {
111         var canvasH = mediaListItemH * 0.95 ;
112
113     for (var i = j; (i < (j+k) && i < this.content.length); i++)
114     {
115         var artistText = {"text" : this.content[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0};
116         var trackText = {"text" : " ", "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0};
117
118                 this.makeListBar(imgIcon, i, artistText, trackText);
119
120                 // Set callback function for the new list item
121                 $("#" + this.type + "CanvasNum" + i).click(function () {
122
123                         try
124                         {
125                                 imagePlayer.load($(this).parent().parent().index());
126                                 $("#imageMediaList").hide();
127                         }
128                         catch(err)
129                         {
130                             console.log("MediaPlayer: load image error: " + err.message);
131                         }
132                 });
133     }
134 }