1 // Copyright (c) 2012 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.
8 * Test API for Chrome OS Video Player and Audio Player.
10 * To test the Video Player open a tab with the URL:
11 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/video_player.html
13 * To test the Audio Player open a tab with the URL:
14 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/mediaplayer.html
19 /* Methods common for audio and video players */
22 * Respond with the path to the current media source.
25 playerTestAPI.respond_(util.extractFilePath(playerTestAPI.getMedia_().src));
29 * Respond with a boolean value, true if the media is playing.
31 isPlaying: function() {
32 playerTestAPI.respond_(playerTestAPI.getControls_().isPlaying());
39 playerTestAPI.getControls_().play();
46 playerTestAPI.getControls_().pause();
50 * Respond with a number, duration of the media in seconds.
52 getDuration: function() {
53 playerTestAPI.respond_(playerTestAPI.getMedia_().duration);
57 * Respond with a number, current media position in seconds.
59 getCurrentTime: function() {
60 playerTestAPI.respond_(playerTestAPI.getMedia_().currentTime);
64 * Change media position.
65 * @param {number} time Media positions.
67 seekTo: function(time) {
68 playerTestAPI.getMedia_().currentTime = time;
71 /* Video player-specific methods.
73 * To test the video player open a tab with the url:
74 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/mediaplayer.html
79 * Load the specified file in the video player,
80 * Starts playing immediately.
81 * @param {string} filePath File path.
83 loadVideo: function(filePath) {
84 var url = util.makeFilesystemUrl(filePath);
85 location.href = location.origin + location.pathname + '?' + url;
90 * Respond with a number, current volume [0..100].
92 getVolume: function() {
93 playerTestAPI.respond_(playerTestAPI.getMedia_().volume * 100);
98 * @param {number} volume Volume [0..100].
100 setVolume: function(volume) {
101 playerTestAPI.respond_(
102 playerTestAPI.getControls_().onVolumeChange_(volume / 100));
106 * Respond with a boolean, true if the volume is muted.
108 isMuted: function() {
109 playerTestAPI.respond_(playerTestAPI.getMedia_().volume == 0);
113 * Mute the volume. No-op if already muted.
116 if (playerTestAPI.getMedia_().volume != 0)
117 playerTestAPI.getControls_().onSoundButtonClick_();
121 * Unmute the volume. No-op if not muted.
124 if (playerTestAPI.getMedia_().volume == 0)
125 playerTestAPI.getControls_().onSoundButtonClick_();
128 /* Audio player-specific methods. */
131 * Load a group of tracks into the audio player.
132 * Starts playing one of the tracks immediately.
133 * @param {Array.<string>} filePaths Array of file paths.
134 * @param {number} firstTrack Number of the file to play first (0-based).
136 loadAudio: function(filePaths, firstTrack) {
137 AudioPlayer.instance.load({
138 items: filePaths.map(util.makeFilesystemUrl),
144 * Respond with a current track number,
146 getTrackNumber: function() {
147 playerTestAPI.respond_(AudioPlayer.instance.currentTrack_);
151 * Play the next track.
153 forward: function() {
154 playerTestAPI.getControls_().onAdvanceClick_(true /* forward */);
158 * Go back. Will restart the current track if the current position is > 5 sec
159 * or play the previous track otherwise.
162 playerTestAPI.getControls_().onAdvanceClick_(false /* back */);
165 /* Utility methods */
168 * @return {AudioControls|VideoControls} Media controls.
171 getControls_: function() {
172 return window.controls || window.AudioPlayer.instance.audioControls_;
176 * @return {HTMLVideoElement|HTMLAudioElement} Media element.
179 getMedia_: function() {
180 return playerTestAPI.getControls_().getMedia();
184 * @param {string|boolean|number} value Value to send back.
187 respond_: function(value) {
188 if (window.domAutomationController)
189 window.domAutomationController.send(value);
191 console.log('playerTestAPI response: ' + value);