| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 Polymer({ | 5 Polymer({ |
| 6 is: 'audio-player', | 6 is: 'audio-player', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** | 9 /** |
| 10 * Flag whether the audio is playing or paused. True if playing, or false | 10 * Flag whether the audio is playing or paused. True if playing, or false |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 reflectToAttribute: true | 83 reflectToAttribute: true |
| 84 }, | 84 }, |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * The number of played tracks. (exposed publicly for tests) | 87 * The number of played tracks. (exposed publicly for tests) |
| 88 */ | 88 */ |
| 89 playcount: { | 89 playcount: { |
| 90 type: Number, | 90 type: Number, |
| 91 value: 0, | 91 value: 0, |
| 92 reflectToAttribute: true | 92 reflectToAttribute: true |
| 93 }, |
| 94 |
| 95 ariaLabels: { |
| 96 type: Object |
| 93 } | 97 } |
| 94 }, | 98 }, |
| 95 | 99 |
| 96 /** | 100 /** |
| 101 * The last playing state when user starts dragging the seek bar. |
| 102 * @private {boolean} |
| 103 */ |
| 104 wasPlayingOnDragStart_: false, |
| 105 |
| 106 /** |
| 97 * Handles change event for shuffle mode. | 107 * Handles change event for shuffle mode. |
| 98 * @param {boolean} shuffle | 108 * @param {boolean} shuffle |
| 99 */ | 109 */ |
| 100 shuffleChanged: function(shuffle) { | 110 shuffleChanged: function(shuffle) { |
| 101 if (this.model) | 111 if (this.model) |
| 102 this.model.shuffle = shuffle; | 112 this.model.shuffle = shuffle; |
| 103 }, | 113 }, |
| 104 | 114 |
| 105 /** | 115 /** |
| 106 * Handles change event for repeat mode. | 116 * Handles change event for repeat mode. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 128 this.model.expanded = expanded; | 138 this.model.expanded = expanded; |
| 129 }, | 139 }, |
| 130 | 140 |
| 131 /** | 141 /** |
| 132 * Initializes an element. This method is called automatically when the | 142 * Initializes an element. This method is called automatically when the |
| 133 * element is ready. | 143 * element is ready. |
| 134 */ | 144 */ |
| 135 ready: function() { | 145 ready: function() { |
| 136 this.addEventListener('keydown', this.onKeyDown_.bind(this)); | 146 this.addEventListener('keydown', this.onKeyDown_.bind(this)); |
| 137 | 147 |
| 148 this.$.audioController.addEventListener('dragging-changed', |
| 149 this.onDraggingChanged_.bind(this)); |
| 150 |
| 138 this.$.audio.volume = 0; // Temporary initial volume. | 151 this.$.audio.volume = 0; // Temporary initial volume. |
| 139 this.$.audio.addEventListener('ended', this.onAudioEnded.bind(this)); | 152 this.$.audio.addEventListener('ended', this.onAudioEnded.bind(this)); |
| 140 this.$.audio.addEventListener('error', this.onAudioError.bind(this)); | 153 this.$.audio.addEventListener('error', this.onAudioError.bind(this)); |
| 141 | 154 |
| 142 var onAudioStatusUpdatedBound = this.onAudioStatusUpdate_.bind(this); | 155 var onAudioStatusUpdatedBound = this.onAudioStatusUpdate_.bind(this); |
| 143 this.$.audio.addEventListener('timeupdate', onAudioStatusUpdatedBound); | 156 this.$.audio.addEventListener('timeupdate', onAudioStatusUpdatedBound); |
| 144 this.$.audio.addEventListener('ended', onAudioStatusUpdatedBound); | 157 this.$.audio.addEventListener('ended', onAudioStatusUpdatedBound); |
| 145 this.$.audio.addEventListener('play', onAudioStatusUpdatedBound); | 158 this.$.audio.addEventListener('play', onAudioStatusUpdatedBound); |
| 146 this.$.audio.addEventListener('pause', onAudioStatusUpdatedBound); | 159 this.$.audio.addEventListener('pause', onAudioStatusUpdatedBound); |
| 147 this.$.audio.addEventListener('suspend', onAudioStatusUpdatedBound); | 160 this.$.audio.addEventListener('suspend', onAudioStatusUpdatedBound); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 * This handler is registered in this.ready(). | 281 * This handler is registered in this.ready(). |
| 269 * @private | 282 * @private |
| 270 */ | 283 */ |
| 271 onAudioStatusUpdate_: function() { | 284 onAudioStatusUpdate_: function() { |
| 272 this.time = (this.lastAudioUpdateTime_ = this.$.audio.currentTime * 1000); | 285 this.time = (this.lastAudioUpdateTime_ = this.$.audio.currentTime * 1000); |
| 273 this.duration = this.$.audio.duration * 1000; | 286 this.duration = this.$.audio.duration * 1000; |
| 274 this.playing = !this.$.audio.paused; | 287 this.playing = !this.$.audio.paused; |
| 275 }, | 288 }, |
| 276 | 289 |
| 277 /** | 290 /** |
| 291 * Invoked when receivig a request to start playing the current music. |
| 292 */ |
| 293 onPlayCurrentTrack: function() { |
| 294 this.$.audio.play(); |
| 295 }, |
| 296 |
| 297 /** |
| 278 * Invoked when receiving a request to replay the current music from the track | 298 * Invoked when receiving a request to replay the current music from the track |
| 279 * list element. | 299 * list element. |
| 280 */ | 300 */ |
| 281 onReplayCurrentTrack: function() { | 301 onReplayCurrentTrack: function() { |
| 282 // Changes the current time back to the beginning, regardless of the current | 302 // Changes the current time back to the beginning, regardless of the current |
| 283 // status (playing or paused). | 303 // status (playing or paused). |
| 284 this.$.audio.currentTime = 0; | 304 this.$.audio.currentTime = 0; |
| 285 this.time = 0; | 305 this.time = 0; |
| 286 }, | 306 }, |
| 287 | 307 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 }, | 409 }, |
| 390 | 410 |
| 391 /** | 411 /** |
| 392 * Invoked when the audio player is being unloaded. | 412 * Invoked when the audio player is being unloaded. |
| 393 */ | 413 */ |
| 394 onPageUnload: function() { | 414 onPageUnload: function() { |
| 395 this.$.audio.src = ''; // Hack to prevent crashing. | 415 this.$.audio.src = ''; // Hack to prevent crashing. |
| 396 }, | 416 }, |
| 397 | 417 |
| 398 /** | 418 /** |
| 419 * Invoked when dragging state of seek bar on control panel is changed. |
| 420 * During the user is dragging it, audio playback is paused temporalily. |
| 421 */ |
| 422 onDraggingChanged_: function() { |
| 423 if (this.$.audioController.dragging) { |
| 424 if (this.playing) { |
| 425 this.wasPlayingOnDragStart_ = true; |
| 426 this.$.audio.pause(); |
| 427 } |
| 428 } else { |
| 429 if (this.wasPlayingOnDragStart_) { |
| 430 this.$.audio.play(); |
| 431 this.wasPlayingOnDragStart_ = false; |
| 432 } |
| 433 } |
| 434 }, |
| 435 |
| 436 /** |
| 399 * Invoked when the 'keydown' event is fired. | 437 * Invoked when the 'keydown' event is fired. |
| 400 * @param {Event} event The event object. | 438 * @param {Event} event The event object. |
| 401 */ | 439 */ |
| 402 onKeyDown_: function(event) { | 440 onKeyDown_: function(event) { |
| 403 switch (event.keyIdentifier) { | 441 switch (event.keyIdentifier) { |
| 404 case 'Up': | 442 case 'Up': |
| 405 if (this.$.audioController.volumeSliderShown && this.model.volume < 100) | 443 if (this.$.audioController.volumeSliderShown && this.model.volume < 100) |
| 406 this.model.volume += 1; | 444 this.model.volume += 1; |
| 407 break; | 445 break; |
| 408 case 'Down': | 446 case 'Down': |
| (...skipping 25 matching lines...) Expand all Loading... |
| 434 | 472 |
| 435 /** | 473 /** |
| 436 * Computes volume value for audio element. (should be in [0.0, 1.0]) | 474 * Computes volume value for audio element. (should be in [0.0, 1.0]) |
| 437 * @param {number} volume Volume which is set in the UI. ([0, 100]) | 475 * @param {number} volume Volume which is set in the UI. ([0, 100]) |
| 438 * @return {number} | 476 * @return {number} |
| 439 */ | 477 */ |
| 440 computeAudioVolume_: function(volume) { | 478 computeAudioVolume_: function(volume) { |
| 441 return volume / 100; | 479 return volume / 100; |
| 442 } | 480 } |
| 443 }); | 481 }); |
| OLD | NEW |