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