2
* MovieManager class definition
3
* @author <a href="mailto:jeff.stys@nasa.gov">Jeff Stys</a>
4
* @author <a href="mailto:keith.hughitt@nasa.gov">Keith Hughitt</a>
6
* TODO 2011/03/14: Choose a reasonable limit for the number of entries based on whether or not
7
* localStorage is supported: if supported limit can be large (e.g. 100), otherwise should be
17
/*jslint browser: true, white: true, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: true,
18
bitwise: true, regexp: false, strict: true, newcap: true, immed: true, maxlen: 120, sub: true */
19
/*global Helioviewer, MediaManager, $, setTimeout */
21
var MovieManager = MediaManager.extend(
22
/** @lends MovieManager.prototype */
26
* Creates a new MovieManager instance
28
init: function (movies) {
30
this.format = $.support.vp8 ? "webm" : "mp4";
32
// Check status of any previously unfinished movie requests
34
$.each(movies, function (i, movie) {
35
if (movie.status < 2) {
36
self._monitorQueuedMovie(movie.id, Date.parseUTCDate(movie.dateRequested), 0);
44
* @param {Int} id Movie id
45
* @param {Float} duration Movie duration in seconds
46
* @param {Float} imageScale Image scale for the movie
47
* @param {String} layers Layers in the movie serialized as a string
48
* @param {String} dateRequested Date string for when the movie was requested
49
* @param {String} startDate Observation date associated with the first movie frame
50
* @param {String} endDate Observation date associated with the last movie frame
51
* @param {Float} frameRate Movie frame-rate in frames/sec
52
* @param {Int} numFrames Total number of frames in the movie
53
* @param {Float} x1 Top-left corner x-coordinate
54
* @param {Float} y1 Top-left corner y-coordinate
55
* @param {Float} x2 Bottom-right corner x-coordinate
56
* @param {Float} y2 Bottom-right corner y-coordinate
57
* @param {Int} width Movie width
58
* @param {Int} height Movie height
60
* @return {Movie} A Movie object
63
id, duration, imageScale, layers, events, eventsLabels, scale,
64
scaleType, scaleX, scaleY, dateRequested, startDate, endDate,
65
frameRate, numFrames, x1, x2, y1, y2, width, height, thumbnail, url
69
"duration" : duration,
70
"imageScale" : imageScale,
73
"eventsLabels" : eventsLabels,
75
"scaleType" : scaleType,
78
"dateRequested" : dateRequested,
79
"startDate" : startDate,
81
"frameRate" : frameRate,
82
"numFrames" : numFrames,
90
"name" : this._getName(layers),
92
"thumbnail" : thumbnail,
101
* Adds a movie that is currently being processed
103
* @param {Int} id Movie id
104
* @param {Int} eta Estimated time in seconds before movie is ready
105
* @param {String} token Resque token for tracking status in queue
106
* @param {Float} imageScale Image scale for the movie
107
* @param {String} layers Layers in the movie serialized as a string
108
* @param {String} dateRequested Date string for when the movie was requested
109
* @param {String} startDate Observation date associated with the first movie frame
110
* @param {String} endDate Observation date associated with the last movie frame
111
* @param {Float} x1 Top-left corner x-coordinate
112
* @param {Float} y1 Top-left corner y-coordinate
113
* @param {Float} x2 Bottom-right corner x-coordinate
114
* @param {Float} y2 Bottom-right corner y-coordinate
116
* @return {Movie} A Movie object
118
queue: function (id, eta, token, imageScale, layers, events, eventsLabels,
119
scale, scaleType, scaleX, scaleY, dateRequested, startDate,
120
endDate, x1, x2, y1, y2) {
124
"imageScale" : imageScale,
127
"eventsLabels" : eventsLabels,
129
"scaleType" : scaleType,
132
"dateRequested" : dateRequested,
133
"startDate" : startDate,
141
"name" : this._getName(layers)
144
if (this._history.unshift(movie) > this._historyLimit) {
145
this._history = this._history.slice(0, this._historyLimit);
148
this._monitorQueuedMovie(id, Date.parseUTCDate(dateRequested), token, eta);
155
* Updates stored information for a given movie and notify user that movie is available
157
* @param {Int} id Movie id
158
* @param {Float} frameRate Movie frame-rate in frames/sec
159
* @param {Int} numFrames Total number of frames in the movie
160
* @param {String} startDate The actual movie start date
161
* @param {String} endDate The actual movie end date
162
* @param {Int} width Movie width
163
* @param {Int} height Movie height
165
update: function (id, frameRate, numFrames, startDate, endDate, width,
166
height, thumbnails, url) {
168
var movie = this.get(id);
170
// Add the new values
172
"frameRate" : frameRate,
173
"numFrames" : numFrames,
174
"startDate" : startDate,
179
"thumbnail" : thumbnails.small,
183
// Delete resque token
188
// Update preview tooltip
189
$(document).trigger("movie-ready", [movie]);
192
this._displayDownloadNotification(movie);
196
* Displays a jGrowl notification to the user informing them that their
197
* download has completed
199
_displayDownloadNotification: function (movie) {
200
var jGrowlOpts, message, self = this;
202
// Options for the jGrowl notification
206
open: function (msg) {
207
msg.find(".message-console-movie-ready").data("movie", movie);
210
message = "<span class='message-console-movie-ready'>" +
211
"Your " + movie.name + " movie is ready! " +
212
"Click here to watch or download it.</span>";
214
// Create the jGrowl notification.
215
$(document).trigger("message-console-log",
216
[message, jGrowlOpts, true, true]);
220
* Monitors a queued movie and notifies the user when it becomes available
222
_monitorQueuedMovie: function (id, dateRequested, token, eta)
224
var queryMovieStatus, self = this;
226
queryMovieStatus = function () {
227
var params, callback;
229
callback = function (response) {
230
// If the user has removed the movie from history, stop monitoring
236
if (response.status < 2) {
237
// If more than 24 hours has elapsed, set status to ERROR
238
if ((Date.now() - dateRequested) / 1000 > (24 * 60 * 60)) {
241
// Otherwise continue to monitor
242
self._monitorQueuedMovie(id, dateRequested, token, 60);
243
} else if (response.error) {
246
self.update(id, response.frameRate, response.numFrames,
247
response.startDate, response.endDate,
248
response.width, response.height,
249
response.thumbnails, response.url);
254
"action" : "getMovieStatus",
257
"format" : self.format
259
$.get(Helioviewer.api, params, callback, Helioviewer.dataType);
261
setTimeout(queryMovieStatus, Math.max(eta, 5) * 1000);
265
* Aborts a failed movie request
267
_abort: function (id) {
268
var error, movie = this.get(id);
275
error = "Sorry, we were unable to create the movie you requested. " +
276
"This usually means that there are not enough images for the " +
277
"time range requested. Please try adjusting the observation " +
278
"date or movie duration and try creating a new movie.";
280
$(document).trigger("message-console-error", [error, {"sticky": true}]);
284
* Saves the current list of movies
287
Helioviewer.userSettings.set("history.movies", this._history);