OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 /** | 5 /** |
6 * Test API for Chrome OS Video Player and Audio Player. | 6 * Test API for Chrome OS Video Player and Audio Player. |
7 * | 7 * |
8 * To test the Video Player open a tab with the URL: | 8 * To test the Video Player open a tab with the URL: |
9 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/video_player.html | 9 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/video_player.html |
10 * | 10 * |
11 * To test the Audio Player open a tab with the URL: | 11 * To test the Audio Player open a tab with the URL: |
12 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/mediaplayer.html | 12 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/mediaplayer.html |
13 * | 13 * |
14 */ | 14 */ |
15 var playerTestAPI = { | 15 var playerTestAPI = { |
16 | 16 |
17 /* Methods common for audio and video players */ | 17 /* Methods common for audio and video players */ |
18 | 18 |
19 /** | 19 /** |
20 * Respond with the path to the current media source. | 20 * Respond with the path to the current media source. |
21 */ | 21 */ |
22 getSrc: function() { | 22 getSrc: function() { |
23 this.respond_(util.extractFilePath(this.getMedia_().src)); | 23 playerTestAPI.respond_(util.extractFilePath(playerTestAPI.getMedia_().src)); |
24 }, | 24 }, |
25 | 25 |
26 /** | 26 /** |
27 * Respond with a boolean value, true if the media is playing. | 27 * Respond with a boolean value, true if the media is playing. |
28 */ | 28 */ |
29 isPlaying: function() { | 29 isPlaying: function() { |
30 this.respond_(this.getControls_().isPlaying()); | 30 playerTestAPI.respond_(playerTestAPI.getControls_().isPlaying()); |
31 }, | 31 }, |
32 | 32 |
33 /** | 33 /** |
34 * Play the media. | 34 * Play the media. |
35 */ | 35 */ |
36 play: function() { | 36 play: function() { |
37 this.getControls_().play(); | 37 playerTestAPI.getControls_().play(); |
38 }, | 38 }, |
39 | 39 |
40 /** | 40 /** |
41 * Pause the playback. | 41 * Pause the playback. |
42 */ | 42 */ |
43 pause: function() { | 43 pause: function() { |
44 this.getControls_().pause(); | 44 playerTestAPI.getControls_().pause(); |
45 }, | 45 }, |
46 | 46 |
47 /** | 47 /** |
48 * Respond with a number, duration of the media in seconds. | 48 * Respond with a number, duration of the media in seconds. |
49 */ | 49 */ |
50 getDuration: function() { | 50 getDuration: function() { |
51 this.respond_(this.getMedia_().duration); | 51 playerTestAPI.respond_(playerTestAPI.getMedia_().duration); |
52 }, | 52 }, |
53 | 53 |
54 /** | 54 /** |
55 * Respond with a number, current media position in seconds. | 55 * Respond with a number, current media position in seconds. |
56 */ | 56 */ |
57 getCurrentTime: function() { | 57 getCurrentTime: function() { |
58 this.respond_(this.getMedia_().currentTime); | 58 playerTestAPI.respond_(playerTestAPI.getMedia_().currentTime); |
59 }, | 59 }, |
60 | 60 |
61 /** | 61 /** |
62 * Change media position. | 62 * Change media position. |
63 * @param {number} time Media positions. | 63 * @param {number} time Media positions. |
64 */ | 64 */ |
65 seekTo: function(time) { | 65 seekTo: function(time) { |
66 this.getMedia_().currentTime = time; | 66 playerTestAPI.getMedia_().currentTime = time; |
67 }, | 67 }, |
68 | 68 |
69 /* Video player-specific methods. | 69 /* Video player-specific methods. |
70 * | 70 * |
71 * To test the video player open a tab with the url: | 71 * To test the video player open a tab with the url: |
72 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/mediaplayer.html | 72 * chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/mediaplayer.html |
73 * | 73 * |
74 */ | 74 */ |
75 | 75 |
76 /** | 76 /** |
77 * Load the specified file in the video player, | 77 * Load the specified file in the video player, |
78 * Starts playing immediately. | 78 * Starts playing immediately. |
79 * @param {string} filePath File path. | 79 * @param {string} filePath File path. |
80 */ | 80 */ |
81 loadVideo: function(filePath) { | 81 loadVideo: function(filePath) { |
82 var url = util.makeFilesystemUrl(filePath); | 82 var url = util.makeFilesystemUrl(filePath); |
83 location.href = location.origin + location.pathname + '?' + url; | 83 location.href = location.origin + location.pathname + '?' + url; |
84 reload(); | 84 reload(); |
85 }, | 85 }, |
86 | 86 |
87 /** | 87 /** |
88 * Respond with a number, current volume [0..100]. | 88 * Respond with a number, current volume [0..100]. |
89 */ | 89 */ |
90 getVolume: function() { | 90 getVolume: function() { |
91 this.respond_(this.getMedia_().volume * 100); | 91 playerTestAPI.respond_(playerTestAPI.getMedia_().volume * 100); |
92 }, | 92 }, |
93 | 93 |
94 /** | 94 /** |
95 * Change volume. | 95 * Change volume. |
96 * @param {number} volume Volume [0..100] | 96 * @param {number} volume Volume [0..100] |
97 */ | 97 */ |
98 setVolume: function(volume) { | 98 setVolume: function(volume) { |
99 this.respond_(this.getControls_().onVolumeChange_(volume / 100)); | 99 playerTestAPI.respond_( |
| 100 playerTestAPI.getControls_().onVolumeChange_(volume / 100)); |
100 }, | 101 }, |
101 | 102 |
102 /** | 103 /** |
103 * Respond with a boolean, true if the volume is muted. | 104 * Respond with a boolean, true if the volume is muted. |
104 */ | 105 */ |
105 isMuted: function() { | 106 isMuted: function() { |
106 this.respond_(this.getMedia_().volume == 0); | 107 playerTestAPI.respond_(playerTestAPI.getMedia_().volume == 0); |
107 }, | 108 }, |
108 | 109 |
109 /** | 110 /** |
110 * Mute the volume. No-op if already muted. | 111 * Mute the volume. No-op if already muted. |
111 */ | 112 */ |
112 mute: function() { | 113 mute: function() { |
113 if (this.getMedia_().volume != 0) | 114 if (playerTestAPI.getMedia_().volume != 0) |
114 this.getControls_().onSoundButtonClick_(); | 115 playerTestAPI.getControls_().onSoundButtonClick_(); |
115 }, | 116 }, |
116 | 117 |
117 /** | 118 /** |
118 * Unmute the volume. No-op if not muted. | 119 * Unmute the volume. No-op if not muted. |
119 */ | 120 */ |
120 unmute: function() { | 121 unmute: function() { |
121 if (this.getMedia_().volume == 0) | 122 if (playerTestAPI.getMedia_().volume == 0) |
122 this.getControls_().onSoundButtonClick_(); | 123 playerTestAPI.getControls_().onSoundButtonClick_(); |
123 }, | 124 }, |
124 | 125 |
125 /* Audio player-specific methods. */ | 126 /* Audio player-specific methods. */ |
126 | 127 |
127 /** | 128 /** |
128 * Load a group of tracks into the audio player. | 129 * Load a group of tracks into the audio player. |
129 * Starts playing one of the tracks immediately. | 130 * Starts playing one of the tracks immediately. |
130 * @param {Array.<string>} filePaths Array of file paths. | 131 * @param {Array.<string>} filePaths Array of file paths. |
131 * @param {number} firstTrack Number of the file to play first (0-based). | 132 * @param {number} firstTrack Number of the file to play first (0-based). |
132 */ | 133 */ |
133 loadAudio: function(filePaths, firstTrack) { | 134 loadAudio: function(filePaths, firstTrack) { |
134 AudioPlayer.instance.load({ | 135 AudioPlayer.instance.load({ |
135 items: filePaths.map(util.makeFilesystemUrl), | 136 items: filePaths.map(util.makeFilesystemUrl), |
136 position: firstTrack | 137 position: firstTrack |
137 }); | 138 }); |
138 }, | 139 }, |
139 | 140 |
140 /** | 141 /** |
141 * Respond with a current track number, | 142 * Respond with a current track number, |
142 */ | 143 */ |
143 getTrackNumber: function() { | 144 getTrackNumber: function() { |
144 this.respond_(AudioPlayer.instance.currentTrack_); | 145 playerTestAPI.respond_(AudioPlayer.instance.currentTrack_); |
145 }, | 146 }, |
146 | 147 |
147 /** | 148 /** |
148 * Play the next track. | 149 * Play the next track. |
149 */ | 150 */ |
150 forward: function() { | 151 forward: function() { |
151 this.getControls_().onAdvanceClick_(true /* forward */); | 152 playerTestAPI.getControls_().onAdvanceClick_(true /* forward */); |
152 }, | 153 }, |
153 | 154 |
154 /** | 155 /** |
155 * Go back. Will restart the current track if the current position is > 5 sec | 156 * Go back. Will restart the current track if the current position is > 5 sec |
156 * or play the previous track otherwise. | 157 * or play the previous track otherwise. |
157 */ | 158 */ |
158 back: function() { | 159 back: function() { |
159 this.getControls_().onAdvanceClick_(false /* back */); | 160 playerTestAPI.getControls_().onAdvanceClick_(false /* back */); |
160 }, | 161 }, |
161 | 162 |
162 /* Utility methods */ | 163 /* Utility methods */ |
163 | 164 |
164 /** | 165 /** |
165 * @return {AudioControls|VideoControls} Media controls. | 166 * @return {AudioControls|VideoControls} Media controls. |
166 * @private | 167 * @private |
167 */ | 168 */ |
168 getControls_: function() { | 169 getControls_: function() { |
169 return window.controls || window.AudioPlayer.instance.audioControls_; | 170 return window.controls || window.AudioPlayer.instance.audioControls_; |
170 }, | 171 }, |
171 | 172 |
172 /** | 173 /** |
173 * @return {HTMLVideoElement|HTMLAudioElement} Media element. | 174 * @return {HTMLVideoElement|HTMLAudioElement} Media element. |
174 * @private | 175 * @private |
175 */ | 176 */ |
176 getMedia_: function() { | 177 getMedia_: function() { |
177 return this.getControls_().getMedia(); | 178 return playerTestAPI.getControls_().getMedia(); |
178 }, | 179 }, |
179 | 180 |
180 /** | 181 /** |
181 * @param {string|boolean|number} value Value to send back. | 182 * @param {string|boolean|number} value Value to send back. |
182 * @private | 183 * @private |
183 */ | 184 */ |
184 respond_: function(value) { | 185 respond_: function(value) { |
185 if (window.domAutomationController) | 186 if (window.domAutomationController) |
186 window.domAutomationController.send(value); | 187 window.domAutomationController.send(value); |
187 else | 188 else |
188 console.log('playerTestAPI response: ' + value); | 189 console.log('playerTestAPI response: ' + value); |
189 } | 190 } |
190 }; | 191 }; |
OLD | NEW |