OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 // The played attribute must return a new static normalized TimeRanges objec
t that represents | 123 // The played attribute must return a new static normalized TimeRanges objec
t that represents |
124 // the union of the ranges of the media resources of the slaved media elemen
ts that the | 124 // the union of the ranges of the media resources of the slaved media elemen
ts that the |
125 // user agent has so far rendered, at the time the attribute is evaluated. | 125 // user agent has so far rendered, at the time the attribute is evaluated. |
126 RefPtr<TimeRanges> playedRanges = m_mediaElements.first()->played(); | 126 RefPtr<TimeRanges> playedRanges = m_mediaElements.first()->played(); |
127 for (size_t index = 1; index < m_mediaElements.size(); ++index) | 127 for (size_t index = 1; index < m_mediaElements.size(); ++index) |
128 playedRanges->unionWith(m_mediaElements[index]->played().get()); | 128 playedRanges->unionWith(m_mediaElements[index]->played().get()); |
129 return playedRanges; | 129 return playedRanges; |
130 } | 130 } |
131 | 131 |
132 float MediaController::duration() const | 132 double MediaController::duration() const |
133 { | 133 { |
134 // FIXME: Investigate caching the maximum duration and only updating the cac
hed value | 134 // FIXME: Investigate caching the maximum duration and only updating the cac
hed value |
135 // when the slaved media elements' durations change. | 135 // when the slaved media elements' durations change. |
136 float maxDuration = 0; | 136 double maxDuration = 0; |
137 for (size_t index = 0; index < m_mediaElements.size(); ++index) { | 137 for (size_t index = 0; index < m_mediaElements.size(); ++index) { |
138 float duration = m_mediaElements[index]->duration(); | 138 double duration = m_mediaElements[index]->duration(); |
139 if (std::isnan(duration)) | 139 if (std::isnan(duration)) |
140 continue; | 140 continue; |
141 maxDuration = max(maxDuration, duration); | 141 maxDuration = max(maxDuration, duration); |
142 } | 142 } |
143 return maxDuration; | 143 return maxDuration; |
144 } | 144 } |
145 | 145 |
146 float MediaController::currentTime() const | 146 double MediaController::currentTime() const |
147 { | 147 { |
148 if (m_mediaElements.isEmpty()) | 148 if (m_mediaElements.isEmpty()) |
149 return 0; | 149 return 0; |
150 | 150 |
151 if (m_position == MediaPlayer::invalidTime()) { | 151 if (m_position == MediaPlayer::invalidTime()) { |
152 // Some clocks may return times outside the range of [0..duration]. | 152 // Some clocks may return times outside the range of [0..duration]. |
153 m_position = max(0.0f, min(duration(), m_clock->currentTime())); | 153 m_position = max(0.0, min(duration(), m_clock->currentTime())); |
154 m_clearPositionTimer.startOneShot(0); | 154 m_clearPositionTimer.startOneShot(0); |
155 } | 155 } |
156 | 156 |
157 return m_position; | 157 return m_position; |
158 } | 158 } |
159 | 159 |
160 void MediaController::setCurrentTime(float time, ExceptionCode& code) | 160 void MediaController::setCurrentTime(double time, ExceptionCode& code) |
161 { | 161 { |
162 // When the user agent is to seek the media controller to a particular new p
layback position, | 162 // When the user agent is to seek the media controller to a particular new p
layback position, |
163 // it must follow these steps: | 163 // it must follow these steps: |
164 // If the new playback position is less than zero, then set it to zero. | 164 // If the new playback position is less than zero, then set it to zero. |
165 time = max(0.0f, time); | 165 time = max(0.0, time); |
166 | 166 |
167 // If the new playback position is greater than the media controller duratio
n, then set it | 167 // If the new playback position is greater than the media controller duratio
n, then set it |
168 // to the media controller duration. | 168 // to the media controller duration. |
169 time = min(time, duration()); | 169 time = min(time, duration()); |
170 | 170 |
171 // Set the media controller position to the new playback position. | 171 // Set the media controller position to the new playback position. |
172 m_clock->setCurrentTime(time); | 172 m_clock->setCurrentTime(time); |
173 | 173 |
174 // Seek each slaved media element to the new playback position relative to t
he media element timeline. | 174 // Seek each slaved media element to the new playback position relative to t
he media element timeline. |
175 for (size_t index = 0; index < m_mediaElements.size(); ++index) | 175 for (size_t index = 0; index < m_mediaElements.size(); ++index) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 return; | 210 return; |
211 | 211 |
212 // then the user agent must change the MediaController into a paused media c
ontroller, | 212 // then the user agent must change the MediaController into a paused media c
ontroller, |
213 m_paused = true; | 213 m_paused = true; |
214 // queue a task to fire a simple event named pause at the MediaController, | 214 // queue a task to fire a simple event named pause at the MediaController, |
215 scheduleEvent(eventNames().pauseEvent); | 215 scheduleEvent(eventNames().pauseEvent); |
216 // and then report the controller state of the MediaController. | 216 // and then report the controller state of the MediaController. |
217 reportControllerState(); | 217 reportControllerState(); |
218 } | 218 } |
219 | 219 |
220 void MediaController::setDefaultPlaybackRate(float rate) | 220 void MediaController::setDefaultPlaybackRate(double rate) |
221 { | 221 { |
222 if (m_defaultPlaybackRate == rate) | 222 if (m_defaultPlaybackRate == rate) |
223 return; | 223 return; |
224 | 224 |
225 // The defaultPlaybackRate attribute, on setting, must set the MediaControll
er's media controller | 225 // The defaultPlaybackRate attribute, on setting, must set the MediaControll
er's media controller |
226 // default playback rate to the new value, | 226 // default playback rate to the new value, |
227 m_defaultPlaybackRate = rate; | 227 m_defaultPlaybackRate = rate; |
228 | 228 |
229 // then queue a task to fire a simple event named ratechange at the MediaCon
troller. | 229 // then queue a task to fire a simple event named ratechange at the MediaCon
troller. |
230 scheduleEvent(eventNames().ratechangeEvent); | 230 scheduleEvent(eventNames().ratechangeEvent); |
231 } | 231 } |
232 | 232 |
233 float MediaController::playbackRate() const | 233 double MediaController::playbackRate() const |
234 { | 234 { |
235 return m_clock->playRate(); | 235 return m_clock->playRate(); |
236 } | 236 } |
237 | 237 |
238 void MediaController::setPlaybackRate(float rate) | 238 void MediaController::setPlaybackRate(double rate) |
239 { | 239 { |
240 if (m_clock->playRate() == rate) | 240 if (m_clock->playRate() == rate) |
241 return; | 241 return; |
242 | 242 |
243 // The playbackRate attribute, on setting, must set the MediaController's me
dia controller | 243 // The playbackRate attribute, on setting, must set the MediaController's me
dia controller |
244 // playback rate to the new value, | 244 // playback rate to the new value, |
245 m_clock->setPlayRate(rate); | 245 m_clock->setPlayRate(rate); |
246 | 246 |
247 for (size_t index = 0; index < m_mediaElements.size(); ++index) | 247 for (size_t index = 0; index < m_mediaElements.size(); ++index) |
248 m_mediaElements[index]->updatePlaybackRate(); | 248 m_mediaElements[index]->updatePlaybackRate(); |
249 | 249 |
250 // then queue a task to fire a simple event named ratechange at the MediaCon
troller. | 250 // then queue a task to fire a simple event named ratechange at the MediaCon
troller. |
251 scheduleEvent(eventNames().ratechangeEvent); | 251 scheduleEvent(eventNames().ratechangeEvent); |
252 } | 252 } |
253 | 253 |
254 void MediaController::setVolume(float level, ExceptionCode& code) | 254 void MediaController::setVolume(double level, ExceptionCode& code) |
255 { | 255 { |
256 if (m_volume == level) | 256 if (m_volume == level) |
257 return; | 257 return; |
258 | 258 |
259 // If the new value is outside the range 0.0 to 1.0 inclusive, then, on sett
ing, an | 259 // If the new value is outside the range 0.0 to 1.0 inclusive, then, on sett
ing, an |
260 // IndexSizeError exception must be raised instead. | 260 // IndexSizeError exception must be raised instead. |
261 if (level < 0 || level > 1) { | 261 if (level < 0 || level > 1) { |
262 code = INDEX_SIZE_ERR; | 262 code = INDEX_SIZE_ERR; |
263 return; | 263 return; |
264 } | 264 } |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 double timedelta = now - m_previousTimeupdateTime; | 678 double timedelta = now - m_previousTimeupdateTime; |
679 | 679 |
680 if (timedelta < maxTimeupdateEventFrequency) | 680 if (timedelta < maxTimeupdateEventFrequency) |
681 return; | 681 return; |
682 | 682 |
683 scheduleEvent(eventNames().timeupdateEvent); | 683 scheduleEvent(eventNames().timeupdateEvent); |
684 m_previousTimeupdateTime = now; | 684 m_previousTimeupdateTime = now; |
685 } | 685 } |
686 | 686 |
687 #endif | 687 #endif |
OLD | NEW |