| 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 11 matching lines...) Expand all Loading... |
| 22 time: { | 22 time: { |
| 23 type: Number, | 23 type: Number, |
| 24 observer: 'timeChanged' | 24 observer: 'timeChanged' |
| 25 }, | 25 }, |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Whether the shuffle button is ON. | 28 * Whether the shuffle button is ON. |
| 29 */ | 29 */ |
| 30 shuffle: { | 30 shuffle: { |
| 31 type: Boolean, | 31 type: Boolean, |
| 32 observer: 'shuffleChanged' | 32 notify: true |
| 33 }, | 33 }, |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Whether the repeat button is ON. | 36 * Whether the repeat button is ON. |
| 37 */ | 37 */ |
| 38 repeat: { | 38 repeat: { |
| 39 type: Boolean, | 39 type: Boolean, |
| 40 observer: 'repeatChanged' | 40 notify: true |
| 41 }, | 41 }, |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * The audio volume. 0 is silent, and 100 is maximum loud. | 44 * The audio volume. 0 is silent, and 100 is maximum loud. |
| 45 */ | 45 */ |
| 46 volume: { | 46 volume: { |
| 47 type: Number, | 47 type: Number, |
| 48 observer: 'volumeChanged' | 48 notify: true |
| 49 }, | 49 }, |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * Whether the expanded button is ON. | 52 * Whether the expanded button is ON. |
| 53 */ | 53 */ |
| 54 expanded: { | 54 expanded: { |
| 55 type: Boolean, | 55 type: Boolean, |
| 56 observer: 'expandedChanged' | 56 notify: true |
| 57 }, | 57 }, |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Track index of the current track. | 60 * Track index of the current track. |
| 61 */ | 61 */ |
| 62 currentTrackIndex: { | 62 currentTrackIndex: { |
| 63 type: Number, | 63 type: Number, |
| 64 observer: 'currentTrackIndexChanged' | 64 observer: 'currentTrackIndexChanged' |
| 65 }, | 65 }, |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Model object of the Audio Player. | |
| 69 * @type {AudioPlayerModel} | |
| 70 */ | |
| 71 model: { | |
| 72 type: Object, | |
| 73 value: null, | |
| 74 observer: 'modelChanged' | |
| 75 }, | |
| 76 | |
| 77 /** | |
| 78 * URL of the current track. (exposed publicly for tests) | 68 * URL of the current track. (exposed publicly for tests) |
| 79 */ | 69 */ |
| 80 currenttrackurl: { | 70 currenttrackurl: { |
| 81 type: String, | 71 type: String, |
| 82 value: '', | 72 value: '', |
| 83 reflectToAttribute: true | 73 reflectToAttribute: true |
| 84 }, | 74 }, |
| 85 | 75 |
| 86 /** | 76 /** |
| 87 * The number of played tracks. (exposed publicly for tests) | 77 * The number of played tracks. (exposed publicly for tests) |
| 88 */ | 78 */ |
| 89 playcount: { | 79 playcount: { |
| 90 type: Number, | 80 type: Number, |
| 91 value: 0, | 81 value: 0, |
| 92 reflectToAttribute: true | 82 reflectToAttribute: true |
| 93 }, | 83 }, |
| 94 | 84 |
| 95 ariaLabels: { | 85 ariaLabels: { |
| 96 type: Object | 86 type: Object |
| 97 } | 87 } |
| 98 }, | 88 }, |
| 99 | 89 |
| 100 /** | 90 /** |
| 101 * The last playing state when user starts dragging the seek bar. | 91 * The last playing state when user starts dragging the seek bar. |
| 102 * @private {boolean} | 92 * @private {boolean} |
| 103 */ | 93 */ |
| 104 wasPlayingOnDragStart_: false, | 94 wasPlayingOnDragStart_: false, |
| 105 | 95 |
| 106 /** | 96 /** |
| 107 * Handles change event for shuffle mode. | |
| 108 * @param {boolean} shuffle | |
| 109 */ | |
| 110 shuffleChanged: function(shuffle) { | |
| 111 if (this.model) | |
| 112 this.model.shuffle = shuffle; | |
| 113 }, | |
| 114 | |
| 115 /** | |
| 116 * Handles change event for repeat mode. | |
| 117 * @param {boolean} repeat | |
| 118 */ | |
| 119 repeatChanged: function(repeat) { | |
| 120 if (this.model) | |
| 121 this.model.repeat = repeat; | |
| 122 }, | |
| 123 | |
| 124 /** | |
| 125 * Handles change event for audio volume. | |
| 126 * @param {number} volume | |
| 127 */ | |
| 128 volumeChanged: function(volume) { | |
| 129 if (this.model) | |
| 130 this.model.volume = volume; | |
| 131 }, | |
| 132 | |
| 133 /** | |
| 134 * Handles change event for expanded state of track list. | |
| 135 */ | |
| 136 expandedChanged: function(expanded) { | |
| 137 if (this.model) | |
| 138 this.model.expanded = expanded; | |
| 139 }, | |
| 140 | |
| 141 /** | |
| 142 * Initializes an element. This method is called automatically when the | 97 * Initializes an element. This method is called automatically when the |
| 143 * element is ready. | 98 * element is ready. |
| 144 */ | 99 */ |
| 145 ready: function() { | 100 ready: function() { |
| 146 this.addEventListener('keydown', this.onKeyDown_.bind(this)); | 101 this.addEventListener('keydown', this.onKeyDown_.bind(this)); |
| 147 | 102 |
| 148 this.$.audioController.addEventListener('dragging-changed', | 103 this.$.audioController.addEventListener('dragging-changed', |
| 149 this.onDraggingChanged_.bind(this)); | 104 this.onDraggingChanged_.bind(this)); |
| 150 | 105 |
| 151 this.$.audio.volume = 0; // Temporary initial volume. | 106 this.$.audio.volume = 0; // Temporary initial volume. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 163 } |
| 209 | 164 |
| 210 // When the new status is "stopped". | 165 // When the new status is "stopped". |
| 211 this.cancelAutoAdvance_(); | 166 this.cancelAutoAdvance_(); |
| 212 this.$.audio.pause(); | 167 this.$.audio.pause(); |
| 213 this.currenttrackurl = ''; | 168 this.currenttrackurl = ''; |
| 214 this.lastAudioUpdateTime_ = null; | 169 this.lastAudioUpdateTime_ = null; |
| 215 }, | 170 }, |
| 216 | 171 |
| 217 /** | 172 /** |
| 218 * Invoked when the model changed. | |
| 219 * @param {AudioPlayerModel} newModel New model. | |
| 220 * @param {AudioPlayerModel} oldModel Old model. | |
| 221 */ | |
| 222 modelChanged: function(newModel, oldModel) { | |
| 223 // Setting up the UI | |
| 224 if (newModel !== oldModel && newModel) { | |
| 225 this.shuffle = newModel.shuffle; | |
| 226 this.repeat = newModel.repeat; | |
| 227 this.volume = newModel.volume; | |
| 228 this.expanded = newModel.expanded; | |
| 229 } | |
| 230 }, | |
| 231 | |
| 232 /** | |
| 233 * Invoked when time is changed. | 173 * Invoked when time is changed. |
| 234 * @param {number} newValue new time (in ms). | 174 * @param {number} newValue new time (in ms). |
| 235 * @param {number} oldValue old time (in ms). | 175 * @param {number} oldValue old time (in ms). |
| 236 */ | 176 */ |
| 237 timeChanged: function(newValue, oldValue) { | 177 timeChanged: function(newValue, oldValue) { |
| 238 // Ignores updates from the audio element. | 178 // Ignores updates from the audio element. |
| 239 if (this.lastAudioUpdateTime_ === newValue) | 179 if (this.lastAudioUpdateTime_ === newValue) |
| 240 return; | 180 return; |
| 241 | 181 |
| 242 if (this.$.audio.readyState !== 0) | 182 if (this.$.audio.readyState !== 0) |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 396 |
| 457 /** | 397 /** |
| 458 * Computes volume value for audio element. (should be in [0.0, 1.0]) | 398 * Computes volume value for audio element. (should be in [0.0, 1.0]) |
| 459 * @param {number} volume Volume which is set in the UI. ([0, 100]) | 399 * @param {number} volume Volume which is set in the UI. ([0, 100]) |
| 460 * @return {number} | 400 * @return {number} |
| 461 */ | 401 */ |
| 462 computeAudioVolume_: function(volume) { | 402 computeAudioVolume_: function(volume) { |
| 463 return volume / 100; | 403 return volume / 100; |
| 464 } | 404 } |
| 465 }); | 405 }); |
| OLD | NEW |