OLD | NEW |
---|---|
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 * @param {Element} playerContainer Main container. | 8 * @param {Element} playerContainer Main container. |
9 * @param {Element} videoContainer Container for the video element. | 9 * @param {Element} videoContainer Container for the video element. |
10 * @param {Element} controlsContainer Container for video controls. | 10 * @param {Element} controlsContainer Container for video controls. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 videoPlayerElement.setAttribute('first-video', true); | 267 videoPlayerElement.setAttribute('first-video', true); |
268 else | 268 else |
269 videoPlayerElement.removeAttribute('first-video'); | 269 videoPlayerElement.removeAttribute('first-video'); |
270 | 270 |
271 // Re-enables ui and hides error message if already displayed. | 271 // Re-enables ui and hides error message if already displayed. |
272 document.querySelector('#video-player').removeAttribute('disabled'); | 272 document.querySelector('#video-player').removeAttribute('disabled'); |
273 document.querySelector('#error').removeAttribute('visible'); | 273 document.querySelector('#error').removeAttribute('visible'); |
274 this.controls.inactivityWatcher.disabled = false; | 274 this.controls.inactivityWatcher.disabled = false; |
275 this.controls.decodeErrorOccured = false; | 275 this.controls.decodeErrorOccured = false; |
276 | 276 |
277 var videoElementInitializePromise; | |
277 if (this.currentCast_) { | 278 if (this.currentCast_) { |
278 videoPlayerElement.setAttribute('casting', true); | |
279 this.videoElement_ = new CastVideoElement(); | |
280 this.controls.attachMedia(this.videoElement_); | |
281 | 279 |
282 document.querySelector('#cast-name-label').textContent = | 280 videoElementInitializePromise = new Promise(function(fulfill, reject) { |
hirono
2014/07/24 02:12:37
To relay rejected states, the videoElementInitiali
yoshiki
2014/07/24 02:57:32
I'm not sure but can't we call the outer reject in
hirono
2014/07/24 03:42:49
We can. But currently if downloadUrlPromise or mim
yoshiki
2014/07/24 05:19:00
I agree this. How about the current code?
hirono
2014/07/24 05:46:09
It looks good. But I would rather stop nesting 'ne
yoshiki
2014/07/24 06:03:22
Done.
| |
283 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON'); | 281 videoPlayerElement.setAttribute('casting', true); |
284 document.querySelector('#cast-name').textContent = | 282 |
285 this.currentCast_.friendlyName; | 283 document.querySelector('#cast-name-label').textContent = |
284 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON'); | |
285 document.querySelector('#cast-name').textContent = | |
286 this.currentCast_.friendlyName; | |
287 | |
288 var downloadUrlPromise = new Promise(function(innerFulfill, innerReject) { | |
289 chrome.fileBrowserPrivate.getDownloadUrl(video.url, innerFulfill); | |
290 }.wrap()); | |
hirono
2014/07/24 02:12:36
We don't need to wrap the function for Promise. Be
yoshiki
2014/07/24 02:57:32
Done.
| |
291 | |
292 var mimePromise = new Promise(function(innerFulfill, innerReject) { | |
293 chrome.fileBrowserPrivate.getDriveEntryProperties( | |
294 [video.entry.toURL()], | |
295 function(props) { | |
296 if (!props || props.length === 0 || !props[0].contentMimeType) { | |
297 // TODO(yoshiki): Adds a logic to guess the mime. | |
298 innerFulfill(''); | |
299 } | |
300 innerFulfill(props[0].contentMimeType); | |
301 }.wrap()); | |
302 }.wrap()); | |
303 | |
304 Promise.all([downloadUrlPromise, mimePromise]).then(function(results) { | |
305 var downloadUrl = results[0]; | |
306 var mime = results[1]; | |
307 | |
308 chrome.cast.requestSession(function(session) { | |
309 var mediaInfo = new chrome.cast.media.MediaInfo(downloadUrl); | |
310 mediaInfo.contentType = mime; | |
311 this.videoElement_ = new CastVideoElement(mediaInfo, session); | |
312 this.controls.attachMedia(this.videoElement_); | |
313 fulfill(); | |
314 }.wrap(this), reject, undefined, this.currentCast_.label); | |
315 }.wrap(this)); | |
316 }.wrap(this)); | |
286 } else { | 317 } else { |
287 videoPlayerElement.removeAttribute('casting'); | 318 videoElementInitializePromise = new Promise(function(fulfill, reject) { |
319 videoPlayerElement.removeAttribute('casting'); | |
288 | 320 |
289 this.videoElement_ = document.createElement('video'); | 321 this.videoElement_ = document.createElement('video'); |
290 document.querySelector('#video-container').appendChild(this.videoElement_); | 322 document.querySelector('#video-container').appendChild( |
323 this.videoElement_); | |
291 | 324 |
292 this.controls.attachMedia(this.videoElement_); | 325 this.controls.attachMedia(this.videoElement_); |
293 this.videoElement_.src = url; | 326 this.videoElement_.src = video.url; |
327 fulfill(); | |
328 }.wrap(this)); | |
294 } | 329 } |
295 | 330 |
296 this.videoElement_.load(); | 331 videoElementInitializePromise.then(function() { |
332 this.videoElement_.load(); | |
297 | 333 |
298 if (opt_callback) { | 334 if (opt_callback) { |
299 var handler = function(currentPos, event) { | 335 var handler = function(currentPos, event) { |
300 console.log('loaded: ', currentPos, this.currentPos_); | 336 console.log('loaded: ', currentPos, this.currentPos_); |
hirono
2014/07/24 02:12:37
nit: debug log?
yoshiki
2014/07/24 02:57:32
Done.
| |
301 if (currentPos === this.currentPos_) | 337 if (currentPos === this.currentPos_) |
302 opt_callback(); | 338 opt_callback(); |
303 this.videoElement_.removeEventListener('loadedmetadata', handler); | 339 this.videoElement_.removeEventListener('loadedmetadata', handler); |
304 }.wrap(this, this.currentPos_); | 340 }.wrap(this, this.currentPos_); |
305 | 341 |
306 this.videoElement_.addEventListener('loadedmetadata', handler); | 342 this.videoElement_.addEventListener('loadedmetadata', handler); |
307 } | 343 } |
344 }.wrap(this)); | |
308 }; | 345 }; |
309 | 346 |
310 /** | 347 /** |
311 * Plays the first video. | 348 * Plays the first video. |
312 */ | 349 */ |
313 VideoPlayer.prototype.playFirstVideo = function() { | 350 VideoPlayer.prototype.playFirstVideo = function() { |
314 this.currentPos_ = 0; | 351 this.currentPos_ = 0; |
315 this.reloadCurrentVideo_(this.onFirstVideoReady_.wrap(this)); | 352 this.reloadCurrentVideo_(this.onFirstVideoReady_.wrap(this)); |
316 }; | 353 }; |
317 | 354 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 var initPromise = Promise.all( | 517 var initPromise = Promise.all( |
481 [new Promise(initVideos.wrap(null)), | 518 [new Promise(initVideos.wrap(null)), |
482 new Promise(initStrings.wrap(null)), | 519 new Promise(initStrings.wrap(null)), |
483 new Promise(util.addPageLoadHandler.wrap(null))]); | 520 new Promise(util.addPageLoadHandler.wrap(null))]); |
484 | 521 |
485 initPromise.then(function(results) { | 522 initPromise.then(function(results) { |
486 var videos = results[0]; | 523 var videos = results[0]; |
487 player.prepare(videos); | 524 player.prepare(videos); |
488 return new Promise(player.playFirstVideo.wrap(player)); | 525 return new Promise(player.playFirstVideo.wrap(player)); |
489 }.wrap(null)); | 526 }.wrap(null)); |
OLD | NEW |