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 * Overrided metadata worker's path. | 6 * Overrided metadata worker's path. |
7 * @type {string} | 7 * @type {string} |
8 */ | 8 */ |
9 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; | 9 ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 this.invalidTracks_ = {}; | 21 this.invalidTracks_ = {}; |
22 | 22 |
23 this.model_ = new AudioPlayerModel(); | 23 this.model_ = new AudioPlayerModel(); |
24 Object.observe(this.model_, function(changes) { | 24 Object.observe(this.model_, function(changes) { |
25 for (var i = 0; i < changes.length; i++) { | 25 for (var i = 0; i < changes.length; i++) { |
26 var change = changes[i]; | 26 var change = changes[i]; |
27 if (change.name == 'expanded' && | 27 if (change.name == 'expanded' && |
28 (change.type == 'add' || change.type == 'update')) { | 28 (change.type == 'add' || change.type == 'update')) { |
29 this.onModelExpandedChanged(change.oldValue, change.object.expanded); | 29 this.onModelExpandedChanged(change.oldValue, change.object.expanded); |
30 break; | 30 break; |
31 } else if (change.name == 'volumeSliderShown' && | |
yawano
2015/10/30 08:28:25
small nit: use === instead of ==.
fukino
2015/10/30 09:05:25
Done.
| |
32 (change.type == 'add' || change.type == 'update')) { | |
33 this.onModelVolumeSliderShownChanged( | |
34 change.oldValue, change.object.expanded); | |
yawano
2015/10/30 08:28:25
change.object.volumeSliderShown?
fukino
2015/10/30 09:05:25
Sorry! Actually these arguments are not used.
I re
| |
35 break; | |
31 } | 36 } |
32 } | 37 } |
33 }.bind(this)); | 38 }.bind(this)); |
34 | 39 |
35 this.entries_ = []; | 40 this.entries_ = []; |
36 this.currentTrackIndex_ = -1; | 41 this.currentTrackIndex_ = -1; |
37 this.playlistGeneration_ = 0; | 42 this.playlistGeneration_ = 0; |
38 | 43 |
39 /** | 44 /** |
40 * Whether if the playlist is expanded or not. This value is changed by | 45 * Whether if the playlist is expanded or not. This value is changed by |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 }; | 282 }; |
278 | 283 |
279 /** | 284 /** |
280 * Toggles the expanded mode when resizing. | 285 * Toggles the expanded mode when resizing. |
281 * | 286 * |
282 * @param {Event} event Resize event. | 287 * @param {Event} event Resize event. |
283 * @private | 288 * @private |
284 */ | 289 */ |
285 AudioPlayer.prototype.onResize_ = function(event) { | 290 AudioPlayer.prototype.onResize_ = function(event) { |
286 if (!this.isExpanded_ && | 291 if (!this.isExpanded_ && |
287 window.innerHeight >= AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) { | 292 window.innerHeight >= this.getExpandedModeMinHeight_()) { |
288 this.isExpanded_ = true; | 293 this.isExpanded_ = true; |
289 this.player_.expanded = true; | 294 this.player_.expanded = true; |
290 } else if (this.isExpanded_ && | 295 } else if (this.isExpanded_ && |
291 window.innerHeight < AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) { | 296 window.innerHeight < this.getExpandedModeMinHeight_()) { |
292 this.isExpanded_ = false; | 297 this.isExpanded_ = false; |
293 this.player_.expanded = false; | 298 this.player_.expanded = false; |
294 } | 299 } |
295 }; | 300 }; |
296 | 301 |
297 /** | 302 /** |
298 * Handles keydown event to open inspector with shortcut keys. | 303 * Handles keydown event to open inspector with shortcut keys. |
299 * | 304 * |
300 * @param {Event} event KeyDown event. | 305 * @param {Event} event KeyDown event. |
301 * @private | 306 * @private |
(...skipping 26 matching lines...) Expand all Loading... | |
328 AudioPlayer.HEADER_HEIGHT = 33; // 32px + border 1px | 333 AudioPlayer.HEADER_HEIGHT = 33; // 32px + border 1px |
329 | 334 |
330 /** | 335 /** |
331 * Track height in pixels. | 336 * Track height in pixels. |
332 * @type {number} | 337 * @type {number} |
333 * @const | 338 * @const |
334 */ | 339 */ |
335 AudioPlayer.TRACK_HEIGHT = 48; | 340 AudioPlayer.TRACK_HEIGHT = 48; |
336 | 341 |
337 /** | 342 /** |
338 * Controls bar height in pixels. | 343 * Volume slider's height in pixels. |
339 * @type {number} | 344 * @type {number} |
340 * @const | 345 * @const |
341 */ | 346 */ |
342 AudioPlayer.CONTROLS_HEIGHT = 96; | 347 AudioPlayer.VOLUME_SLIDER_HEIGHT = 48; |
fukino
2015/10/30 07:50:07
Since the control panels' height is not static any
| |
348 | |
349 /** | |
350 * Height of the control which has buttons such as play, next, shffule, etc... | |
351 * @type {number} | |
352 * @const | |
353 */ | |
354 AudioPlayer.BUTTONS_CONTROL_HEIGHT = 48; | |
355 | |
356 /** | |
357 * Height of the control which has progress slider, time, and duration. | |
358 * @type {number} | |
359 * @const | |
360 */ | |
361 AudioPlayer.TIME_CONTROL_HEIGHT = 48; | |
343 | 362 |
344 /** | 363 /** |
345 * Default number of items in the expanded mode. | 364 * Default number of items in the expanded mode. |
346 * @type {number} | 365 * @type {number} |
347 * @const | 366 * @const |
348 */ | 367 */ |
349 AudioPlayer.DEFAULT_EXPANDED_ITEMS = 5; | 368 AudioPlayer.DEFAULT_EXPANDED_ITEMS = 5; |
350 | 369 |
351 /** | 370 /** |
352 * Minimum size of the window in the expanded mode in pixels. | |
353 * @type {number} | |
354 * @const | |
355 */ | |
356 AudioPlayer.EXPANDED_MODE_MIN_HEIGHT = AudioPlayer.CONTROLS_HEIGHT + | |
357 AudioPlayer.TRACK_HEIGHT * 2; | |
358 | |
359 /** | |
360 * Invoked when the 'expanded' property in the model is changed. | 371 * Invoked when the 'expanded' property in the model is changed. |
361 * @param {boolean} oldValue Old value. | 372 * @param {boolean} oldValue Old value. |
362 * @param {boolean} newValue New value. | 373 * @param {boolean} newValue New value. |
363 */ | 374 */ |
364 AudioPlayer.prototype.onModelExpandedChanged = function(oldValue, newValue) { | 375 AudioPlayer.prototype.onModelExpandedChanged = function(oldValue, newValue) { |
365 if (this.isExpanded_ !== null && | 376 if (this.isExpanded_ !== null && |
366 this.isExpanded_ === newValue) | 377 this.isExpanded_ === newValue) |
367 return; | 378 return; |
368 | 379 |
369 if (this.isExpanded_ && !newValue) | 380 if (this.isExpanded_ && !newValue) |
370 this.lastExpandedHeight_ = window.innerHeight; | 381 this.lastExpandedHeight_ = window.innerHeight; |
371 | 382 |
372 if (this.isExpanded_ !== newValue) { | 383 if (this.isExpanded_ !== newValue) { |
373 this.isExpanded_ = newValue; | 384 this.isExpanded_ = newValue; |
374 this.syncHeight_(); | 385 this.syncHeight_(); |
375 | 386 |
376 // Saves new state. | 387 // Saves new state. |
377 window.appState.expanded = newValue; | 388 window.appState.expanded = newValue; |
378 util.saveAppState(); | 389 util.saveAppState(); |
379 } | 390 } |
380 }; | 391 }; |
381 | 392 |
382 /** | 393 /** |
394 * Invoked when the 'volumeSliderShwon' property in the model is changed. | |
yawano
2015/10/30 08:28:25
typo: volumeSliderShwon -> volumeSliderShown
fukino
2015/10/30 09:05:25
Done.
| |
395 * @param {boolean} oldValue Old value. | |
396 * @param {boolean} newValue New value. | |
397 */ | |
398 AudioPlayer.prototype.onModelVolumeSliderShownChanged = | |
399 function(oldValue, newValue) { | |
400 this.syncHeight_(); | |
401 }; | |
402 | |
403 /** | |
383 * @private | 404 * @private |
384 */ | 405 */ |
385 AudioPlayer.prototype.syncHeight_ = function() { | 406 AudioPlayer.prototype.syncHeight_ = function() { |
386 var targetHeight; | 407 var targetHeight; |
387 | 408 |
388 if (this.player_.expanded) { | 409 if (this.player_.expanded) { |
389 // Expanded. | 410 // Expanded. |
390 if (!this.lastExpandedHeight_ || | 411 if (!this.lastExpandedHeight_ || |
391 this.lastExpandedHeight_ < AudioPlayer.EXPANDED_MODE_MIN_HEIGHT) { | 412 this.lastExpandedHeight_ < this.getExpandedModeMinHeight_()) { |
392 var expandedListHeight = | 413 var expandedListHeight = |
393 Math.min(this.entries_.length, AudioPlayer.DEFAULT_EXPANDED_ITEMS) * | 414 Math.min(this.entries_.length, AudioPlayer.DEFAULT_EXPANDED_ITEMS) * |
394 AudioPlayer.TRACK_HEIGHT; | 415 AudioPlayer.TRACK_HEIGHT; |
395 targetHeight = AudioPlayer.CONTROLS_HEIGHT + expandedListHeight; | 416 targetHeight = this.getControlsHeight_() + expandedListHeight; |
396 this.lastExpandedHeight_ = targetHeight; | 417 this.lastExpandedHeight_ = targetHeight; |
397 } else { | 418 } else { |
398 targetHeight = this.lastExpandedHeight_; | 419 targetHeight = this.lastExpandedHeight_; |
399 } | 420 } |
400 } else { | 421 } else { |
401 // Not expanded. | 422 // Not expanded. |
402 targetHeight = AudioPlayer.CONTROLS_HEIGHT + AudioPlayer.TRACK_HEIGHT; | 423 targetHeight = this.getControlsHeight_() + AudioPlayer.TRACK_HEIGHT; |
403 } | 424 } |
404 | 425 |
405 window.resizeTo(window.innerWidth, targetHeight + AudioPlayer.HEADER_HEIGHT); | 426 window.resizeTo(window.innerWidth, targetHeight + AudioPlayer.HEADER_HEIGHT); |
406 }; | 427 }; |
407 | 428 |
408 /** | 429 /** |
430 * Calculate the height of control panel. | |
yawano
2015/10/30 08:28:25
nit: Calculate -> Calculates
fukino
2015/10/30 09:05:25
Done.
| |
431 * @return {number} Current height of control panel in pixels. | |
432 * @private | |
433 */ | |
434 AudioPlayer.prototype.getControlsHeight_ = function() { | |
435 var height = AudioPlayer.BUTTONS_CONTROL_HEIGHT + | |
436 AudioPlayer.TIME_CONTROL_HEIGHT; | |
437 if (this.player_.volumeSliderShown) | |
438 height += AudioPlayer.VOLUME_SLIDER_HEIGHT; | |
439 | |
440 return height; | |
441 }; | |
442 | |
443 /** | |
444 * Calculate the minium height of the app to show the playlist in expanded mode. | |
yawano
2015/10/30 08:28:25
nit: Calculate -> Calculates
fukino
2015/10/30 09:05:25
Done.
| |
445 * @return {number} The minimum height of audio app window in which we can show | |
446 * the playlist in expanded mode. | |
447 * @private | |
448 */ | |
449 AudioPlayer.prototype.getExpandedModeMinHeight_ = function() { | |
450 return this.getControlsHeight_() + AudioPlayer.TRACK_HEIGHT * 2; | |
451 }; | |
452 | |
453 /** | |
409 * Create a TrackInfo object encapsulating the information about one track. | 454 * Create a TrackInfo object encapsulating the information about one track. |
410 * | 455 * |
411 * @param {FileEntry} entry FileEntry to be retrieved the track info from. | 456 * @param {FileEntry} entry FileEntry to be retrieved the track info from. |
412 * @constructor | 457 * @constructor |
413 */ | 458 */ |
414 AudioPlayer.TrackInfo = function(entry) { | 459 AudioPlayer.TrackInfo = function(entry) { |
415 this.url = entry.toURL(); | 460 this.url = entry.toURL(); |
416 this.title = this.getDefaultTitle(); | 461 this.title = this.getDefaultTitle(); |
417 this.artist = this.getDefaultArtist(); | 462 this.artist = this.getDefaultArtist(); |
418 | 463 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 // TODO(yoshiki): Handle error in better way. | 498 // TODO(yoshiki): Handle error in better way. |
454 // TODO(yoshiki): implement artwork (metadata.thumbnail) | 499 // TODO(yoshiki): implement artwork (metadata.thumbnail) |
455 this.title = metadata.mediaTitle || this.getDefaultTitle(); | 500 this.title = metadata.mediaTitle || this.getDefaultTitle(); |
456 this.artist = error || metadata.mediaArtist || this.getDefaultArtist(); | 501 this.artist = error || metadata.mediaArtist || this.getDefaultArtist(); |
457 }; | 502 }; |
458 | 503 |
459 // Starts loading the audio player. | 504 // Starts loading the audio player. |
460 window.addEventListener('DOMContentLoaded', function(e) { | 505 window.addEventListener('DOMContentLoaded', function(e) { |
461 AudioPlayer.load(); | 506 AudioPlayer.load(); |
462 }); | 507 }); |
OLD | NEW |