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
3 // found in the LICENSE file.
6 * Icon of the video player.
7 * TODO(yoshiki): Consider providing an exact size icon, instead of relying
8 * on downsampling by ash.
13 var ICON_IMAGE
= 'images/icon/video-player-64.png';
16 * Configuration of the video player panel.
19 var windowCreateOptions
= {
26 * Backgound object. This is necessary for AppWindowWrapper.
27 * @type {BackgroundBase}
29 var background
= new BackgroundBase();
32 var generateWindowId
= (function() {
35 return 'VIDEO_PLAYER_APP_' + seq
++;
40 * Opens player window.
41 * @param {!Array<string>} urls List of videos to play and index to start
43 * @return {!Promise} Promise to be fulfilled on success, or rejected on error.
45 function openVideoPlayerWindow(urls
) {
47 var startUrl
= (position
< urls
.length
) ? urls
[position
] : '';
50 return new Promise(function(fulfill
, reject
) {
51 util
.URLsToEntries(urls
).then(function(result
) {
52 fulfill(result
.entries
);
53 }.wrap()).catch(reject
);
54 }.wrap()).then(function(entries
) {
55 if (entries
.length
=== 0)
56 return Promise
.reject('No file to open.');
58 // Adjusts the position to start playing.
59 var maybePosition
= util
.entriesToURLs(entries
).indexOf(startUrl
);
60 if (maybePosition
!== -1)
61 position
= maybePosition
;
63 windowId
= generateWindowId();
65 // Opens the video player window.
66 return new Promise(function(fulfill
, reject
) {
67 var urls
= util
.entriesToURLs(entries
);
68 var videoPlayer
= new AppWindowWrapper('video_player.html',
73 {items
: urls
, position
: position
},
75 fulfill
.bind(null, videoPlayer
));
77 }.wrap()).then(function(videoPlayer
) {
78 var appWindow
= videoPlayer
.rawAppWindow
;
81 appWindow
.contentWindow
.loadMockCastExtensionForTest
= true;
83 videoPlayer
.setIcon(ICON_IMAGE
);
87 }.wrap()).catch(function(error
) {
88 console
.error('Launch failed' + error
.stack
|| error
);
89 return Promise
.reject(error
);
93 background
.setLaunchHandler(openVideoPlayerWindow
);