Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: ui/file_manager/video_player/js/cast/cast_video_element.js

Issue 439223003: Video Player: Fix minor error handling bugs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Inverval for updating media info (in ms). 8 * Inverval for updating media info (in ms).
9 * @type {number} 9 * @type {number}
10 * @const 10 * @const
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 /** 183 /**
184 * Plays the video. 184 * Plays the video.
185 */ 185 */
186 play: function() { 186 play: function() {
187 var play = function() { 187 var play = function() {
188 this.castMedia_.play(null, 188 this.castMedia_.play(null,
189 function () { 189 function () {
190 this.playInProgress_ = false; 190 this.playInProgress_ = false;
191 }.wrap(this), 191 }.wrap(this),
192 function () { 192 function (error) {
193 this.playInProgress_ = false; 193 this.playInProgress_ = false;
194 this.onCastCommandError_(); 194 this.onCastCommandError_(error);
195 }.wrap(this)); 195 }.wrap(this));
196 }.wrap(this); 196 }.wrap(this);
197 197
198 this.playInProgress_ = true; 198 this.playInProgress_ = true;
199 199
200 if (!this.castMedia_) 200 if (!this.castMedia_)
201 this.load(play); 201 this.load(play);
202 else 202 else
203 play(); 203 play();
204 }, 204 },
205 205
206 /** 206 /**
207 * Pauses the video. 207 * Pauses the video.
208 */ 208 */
209 pause: function() { 209 pause: function() {
210 if (!this.castMedia_) 210 if (!this.castMedia_)
211 return; 211 return;
212 212
213 this.pauseInProgress_ = true; 213 this.pauseInProgress_ = true;
214 this.castMedia_.pause(null, 214 this.castMedia_.pause(null,
215 function () { 215 function () {
216 this.pauseInProgress_ = false; 216 this.pauseInProgress_ = false;
217 }.wrap(this), 217 }.wrap(this),
218 function () { 218 function (error) {
219 this.pauseInProgress_ = false; 219 this.pauseInProgress_ = false;
220 this.onCastCommandError_(); 220 this.onCastCommandError_(error);
221 }.wrap(this)); 221 }.wrap(this));
222 }, 222 },
223 223
224 /** 224 /**
225 * Loads the video. 225 * Loads the video.
226 */ 226 */
227 load: function(opt_callback) { 227 load: function(opt_callback) {
228 var sendTokenPromise = this.mediaManager_.getToken().then(function(token) { 228 var sendTokenPromise = this.mediaManager_.getToken().then(function(token) {
229 this.token_ = token; 229 this.token_ = token;
230 this.sendMessage_({message: 'push-token', token: token}); 230 this.sendMessage_({message: 'push-token', token: token});
(...skipping 18 matching lines...) Expand all
249 249
250 var request = new chrome.cast.media.LoadRequest(this.mediaInfo_); 250 var request = new chrome.cast.media.LoadRequest(this.mediaInfo_);
251 return new Promise( 251 return new Promise(
252 this.castSession_.loadMedia.bind(this.castSession_, request)). 252 this.castSession_.loadMedia.bind(this.castSession_, request)).
253 then(function(media) { 253 then(function(media) {
254 this.onMediaDiscovered_(media); 254 this.onMediaDiscovered_(media);
255 if (opt_callback) 255 if (opt_callback)
256 opt_callback(); 256 opt_callback();
257 }.bind(this)); 257 }.bind(this));
258 }.bind(this)).catch(function(error) { 258 }.bind(this)).catch(function(error) {
259 this.unloadMedia_();
260 this.dispatchEvent(new Event('error'));
259 console.error('Cast failed.', error.stack || error); 261 console.error('Cast failed.', error.stack || error);
260 }); 262 });
hirono 2014/08/04 11:05:52 .bind(this)?
yoshiki 2014/08/05 00:47:16 Done.
261 }, 263 },
262 264
263 /** 265 /**
264 * Unloads the video. 266 * Unloads the video.
265 * @private 267 * @private
266 */ 268 */
267 unloadMedia_: function() { 269 unloadMedia_: function() {
268 if (this.castMedia_) { 270 if (this.castMedia_) {
269 this.castMedia_.stop(null, 271 this.castMedia_.stop(null,
270 function () {}, 272 function () {},
271 function () { 273 function (error) {
272 // Ignores session error, since session may already be closed. 274 // Ignores session error, since session may already be closed.
273 if (error.code !== chrome.cast.ErrorCode.SESSION_ERROR) 275 if (error.code !== chrome.cast.ErrorCode.SESSION_ERROR)
274 this.onCastCommandError_(error); 276 this.onCastCommandError_(error);
275 }.wrap(this)); 277 }.wrap(this));
276 278
277 this.castMedia_.removeUpdateListener(this.onCastMediaUpdatedBound_); 279 this.castMedia_.removeUpdateListener(this.onCastMediaUpdatedBound_);
278 this.castMedia_ = null; 280 this.castMedia_ = null;
279 } 281 }
280 clearInterval(this.updateTimerId_); 282 clearInterval(this.updateTimerId_);
281 }, 283 },
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Notify that the metadata of the video is ready. 349 // Notify that the metadata of the video is ready.
348 this.dispatchEvent(new Event('loadedmetadata')); 350 this.dispatchEvent(new Event('loadedmetadata'));
349 351
350 media.addUpdateListener(this.onCastMediaUpdatedBound_); 352 media.addUpdateListener(this.onCastMediaUpdatedBound_);
351 this.updateTimerId_ = setInterval(this.onPeriodicalUpdateTimer_.bind(this), 353 this.updateTimerId_ = setInterval(this.onPeriodicalUpdateTimer_.bind(this),
352 MEDIA_UPDATE_INTERVAL); 354 MEDIA_UPDATE_INTERVAL);
353 }, 355 },
354 356
355 /** 357 /**
356 * This method should be called when a media command to cast is failed. 358 * This method should be called when a media command to cast is failed.
359 * @param {Object} error Object representing the error.
357 * @private 360 * @private
358 */ 361 */
359 onCastCommandError_: function() { 362 onCastCommandError_: function(error) {
360 this.unloadMedia_(); 363 this.unloadMedia_();
361 this.dispatchEvent(new Event('error')); 364 this.dispatchEvent(new Event('error'));
365 console.error('Error on sending command to cast.', error.stack || error);
362 }, 366 },
363 367
364 /** 368 /**
365 * This is called when any media data is updated and by the periodical timer 369 * This is called when any media data is updated and by the periodical timer
366 * is fired. 370 * is fired.
367 * 371 *
368 * @param {boolean} alive Media availability. False if it's unavailable. 372 * @param {boolean} alive Media availability. False if it's unavailable.
369 * @private 373 * @private
370 */ 374 */
371 onCastMediaUpdated_: function(alive) { 375 onCastMediaUpdated_: function(alive) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 this.dispatchEvent(new Event('durationchange')); 407 this.dispatchEvent(new Event('durationchange'));
404 } 408 }
405 409
406 // Media is being unloaded. 410 // Media is being unloaded.
407 if (!alive) { 411 if (!alive) {
408 this.unloadMedia_(); 412 this.unloadMedia_();
409 return; 413 return;
410 } 414 }
411 }, 415 },
412 }; 416 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698