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

Unified Diff: ui/file_manager/video_player/js/video_player.js

Issue 412813002: Video Player: Support casting a video (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/video_player/js/video_player.js
diff --git a/ui/file_manager/video_player/js/video_player.js b/ui/file_manager/video_player/js/video_player.js
index 73ada6a9ec31cbb54db85af69c0253b1d11bd92f..abb5724c14b9ad5000785816227814434b796417 100644
--- a/ui/file_manager/video_player/js/video_player.js
+++ b/ui/file_manager/video_player/js/video_player.js
@@ -274,37 +274,74 @@ VideoPlayer.prototype.loadVideo_ = function(url, title, opt_callback) {
this.controls.inactivityWatcher.disabled = false;
this.controls.decodeErrorOccured = false;
+ var videoElementInitializePromise;
if (this.currentCast_) {
- videoPlayerElement.setAttribute('casting', true);
- this.videoElement_ = new CastVideoElement();
- this.controls.attachMedia(this.videoElement_);
-
- document.querySelector('#cast-name-label').textContent =
- loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON');
- document.querySelector('#cast-name').textContent =
- this.currentCast_.friendlyName;
+
+ 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.
+ videoPlayerElement.setAttribute('casting', true);
+
+ document.querySelector('#cast-name-label').textContent =
+ loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON');
+ document.querySelector('#cast-name').textContent =
+ this.currentCast_.friendlyName;
+
+ var downloadUrlPromise = new Promise(function(innerFulfill, innerReject) {
+ chrome.fileBrowserPrivate.getDownloadUrl(video.url, innerFulfill);
+ }.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.
+
+ var mimePromise = new Promise(function(innerFulfill, innerReject) {
+ chrome.fileBrowserPrivate.getDriveEntryProperties(
+ [video.entry.toURL()],
+ function(props) {
+ if (!props || props.length === 0 || !props[0].contentMimeType) {
+ // TODO(yoshiki): Adds a logic to guess the mime.
+ innerFulfill('');
+ }
+ innerFulfill(props[0].contentMimeType);
+ }.wrap());
+ }.wrap());
+
+ Promise.all([downloadUrlPromise, mimePromise]).then(function(results) {
+ var downloadUrl = results[0];
+ var mime = results[1];
+
+ chrome.cast.requestSession(function(session) {
+ var mediaInfo = new chrome.cast.media.MediaInfo(downloadUrl);
+ mediaInfo.contentType = mime;
+ this.videoElement_ = new CastVideoElement(mediaInfo, session);
+ this.controls.attachMedia(this.videoElement_);
+ fulfill();
+ }.wrap(this), reject, undefined, this.currentCast_.label);
+ }.wrap(this));
+ }.wrap(this));
} else {
- videoPlayerElement.removeAttribute('casting');
+ videoElementInitializePromise = new Promise(function(fulfill, reject) {
+ videoPlayerElement.removeAttribute('casting');
- this.videoElement_ = document.createElement('video');
- document.querySelector('#video-container').appendChild(this.videoElement_);
+ this.videoElement_ = document.createElement('video');
+ document.querySelector('#video-container').appendChild(
+ this.videoElement_);
- this.controls.attachMedia(this.videoElement_);
- this.videoElement_.src = url;
+ this.controls.attachMedia(this.videoElement_);
+ this.videoElement_.src = video.url;
+ fulfill();
+ }.wrap(this));
}
- this.videoElement_.load();
+ videoElementInitializePromise.then(function() {
+ this.videoElement_.load();
- if (opt_callback) {
- var handler = function(currentPos, event) {
- console.log('loaded: ', currentPos, this.currentPos_);
- if (currentPos === this.currentPos_)
- opt_callback();
- this.videoElement_.removeEventListener('loadedmetadata', handler);
- }.wrap(this, this.currentPos_);
+ if (opt_callback) {
+ var handler = function(currentPos, event) {
+ console.log('loaded: ', currentPos, this.currentPos_);
hirono 2014/07/24 02:12:37 nit: debug log?
yoshiki 2014/07/24 02:57:32 Done.
+ if (currentPos === this.currentPos_)
+ opt_callback();
+ this.videoElement_.removeEventListener('loadedmetadata', handler);
+ }.wrap(this, this.currentPos_);
- this.videoElement_.addEventListener('loadedmetadata', handler);
- }
+ this.videoElement_.addEventListener('loadedmetadata', handler);
+ }
+ }.wrap(this));
};
/**

Powered by Google App Engine
This is Rietveld 408576698