OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 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 2059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2070 // playback state | 2070 // playback state |
2071 double HTMLMediaElement::currentTime() const | 2071 double HTMLMediaElement::currentTime() const |
2072 { | 2072 { |
2073 #if LOG_CACHED_TIME_WARNINGS | 2073 #if LOG_CACHED_TIME_WARNINGS |
2074 static const double minCachedDeltaForWarning = 0.01; | 2074 static const double minCachedDeltaForWarning = 0.01; |
2075 #endif | 2075 #endif |
2076 | 2076 |
2077 if (m_readyState == HAVE_NOTHING) | 2077 if (m_readyState == HAVE_NOTHING) |
2078 return 0; | 2078 return 0; |
2079 | 2079 |
2080 // currentTime equals the end of the media resource when 'ended' event is fi red. | |
2081 // NOTE: Sometimes it happens that the current playback position is not exac tly equal to the media duration, | |
2082 // especially in Android, which often stops at a time which is smaller that the actual duration. | |
2083 if (m_sentEndEvent) { | |
2084 return duration(); | |
2085 } | |
2086 | |
2080 if (m_seeking) { | 2087 if (m_seeking) { |
2081 WTF_LOG(Media, "HTMLMediaElement::currentTime - seeking, returning %f", m_lastSeekTime); | 2088 WTF_LOG(Media, "HTMLMediaElement::currentTime - seeking, returning %f", m_lastSeekTime); |
2082 return m_lastSeekTime; | 2089 return m_lastSeekTime; |
2083 } | 2090 } |
2084 | 2091 |
2085 if (m_cachedTime != MediaPlayer::invalidTime() && m_paused) { | 2092 if (m_cachedTime != MediaPlayer::invalidTime() && m_paused) { |
2086 #if LOG_CACHED_TIME_WARNINGS | 2093 #if LOG_CACHED_TIME_WARNINGS |
2087 double delta = m_cachedTime - webMediaPlayer()->currentTime(); | 2094 double delta = m_cachedTime - webMediaPlayer()->currentTime(); |
2088 if (delta > minCachedDeltaForWarning) | 2095 if (delta > minCachedDeltaForWarning) |
2089 WTF_LOG(Media, "HTMLMediaElement::currentTime - WARNING, cached time is %f seconds off of media time when paused", delta); | 2096 WTF_LOG(Media, "HTMLMediaElement::currentTime - WARNING, cached time is %f seconds off of media time when paused", delta); |
2090 #endif | 2097 #endif |
2091 return m_cachedTime; | 2098 return m_cachedTime; |
2092 } | 2099 } |
2093 | 2100 |
2094 refreshCachedTime(); | 2101 refreshCachedTime(); |
2095 | 2102 |
2096 return m_cachedTime; | 2103 return m_cachedTime; |
2097 } | 2104 } |
2098 | 2105 |
2099 void HTMLMediaElement::setCurrentTime(double time, ExceptionState& exceptionStat e) | 2106 void HTMLMediaElement::setCurrentTime(double time, ExceptionState& exceptionStat e) |
2100 { | 2107 { |
2101 if (m_mediaController) { | 2108 if (m_mediaController) { |
2102 exceptionState.throwDOMException(InvalidStateError, "The element is slav ed to a MediaController."); | 2109 exceptionState.throwDOMException(InvalidStateError, "The element is slav ed to a MediaController."); |
2103 return; | 2110 return; |
2104 } | 2111 } |
2112 | |
amogh.bihani
2014/09/03 05:19:09
Sorry, I'll remove this in next PS.
scherkus (not reviewing)
2014/09/03 17:16:45
thanks :)
| |
2105 seek(time, exceptionState); | 2113 seek(time, exceptionState); |
2106 } | 2114 } |
2107 | 2115 |
2108 double HTMLMediaElement::duration() const | 2116 double HTMLMediaElement::duration() const |
2109 { | 2117 { |
2110 // FIXME: remove m_player check once we figure out how m_player is going | 2118 // FIXME: remove m_player check once we figure out how m_player is going |
2111 // out of sync with readystate. m_player is cleared but readystate is not se t | 2119 // out of sync with readystate. m_player is cleared but readystate is not se t |
2112 // to HAVE_NOTHING | 2120 // to HAVE_NOTHING |
2113 if (!m_player || m_readyState < HAVE_METADATA) | 2121 if (!m_player || m_readyState < HAVE_METADATA) |
2114 return std::numeric_limits<double>::quiet_NaN(); | 2122 return std::numeric_limits<double>::quiet_NaN(); |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3086 | 3094 |
3087 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t he seek. | 3095 // 4.8.10.9 steps 12-14. Needed if no ReadyState change is associated with t he seek. |
3088 if (m_seeking && m_readyState >= HAVE_CURRENT_DATA && !webMediaPlayer()->see king()) | 3096 if (m_seeking && m_readyState >= HAVE_CURRENT_DATA && !webMediaPlayer()->see king()) |
3089 finishSeek(); | 3097 finishSeek(); |
3090 | 3098 |
3091 // Always call scheduleTimeupdateEvent when the media engine reports a time discontinuity, | 3099 // Always call scheduleTimeupdateEvent when the media engine reports a time discontinuity, |
3092 // it will only queue a 'timeupdate' event if we haven't already posted one at the current | 3100 // it will only queue a 'timeupdate' event if we haven't already posted one at the current |
3093 // movie time. | 3101 // movie time. |
3094 scheduleTimeupdateEvent(false); | 3102 scheduleTimeupdateEvent(false); |
3095 | 3103 |
3104 // TODO(amogh.bihani): Remove this once chromium change lands.-------------- -- | |
scherkus (not reviewing)
2014/09/03 17:16:45
can you avoid using the "-----" comments? we don't
| |
3096 double now = currentTime(); | 3105 double now = currentTime(); |
3097 double dur = duration(); | 3106 double dur = duration(); |
3098 | 3107 |
3108 if (!std::isnan(dur) && dur && now >= dur && directionOfPlayback() == Forwar d) | |
3109 mediaPlayerEnded(); | |
3110 // ------------------------------------------------------------------------- -- | |
scherkus (not reviewing)
2014/09/03 17:16:45
remove this whole line
| |
3111 | |
3112 updatePlayState(); | |
3113 } | |
3114 | |
3115 void HTMLMediaElement::mediaPlayerEnded() | |
3116 { | |
3117 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerEnded"); | |
3118 | |
3099 // When the current playback position reaches the end of the media resource when the direction of | 3119 // When the current playback position reaches the end of the media resource when the direction of |
3100 // playback is forwards, then the user agent must follow these steps: | 3120 // playback is forwards, then the user agent must follow these steps: |
3101 if (!std::isnan(dur) && dur && now >= dur && directionOfPlayback() == Forwar d) { | 3121 if (!std::isnan(duration()) && directionOfPlayback() == Forward) { |
3102 // If the media element has a loop attribute specified and does not have a current media controller, | 3122 // If the media element has a loop attribute specified and does not have a current media controller, |
3103 if (loop() && !m_mediaController) { | 3123 if (loop() && !m_mediaController) { |
3104 m_sentEndEvent = false; | 3124 m_sentEndEvent = false; |
3105 // then seek to the earliest possible position of the media resourc e and abort these steps. | 3125 // then seek to the earliest possible position of the media resourc e and abort these steps. |
3106 seek(0, IGNORE_EXCEPTION); | 3126 seek(0, IGNORE_EXCEPTION); |
3107 } else { | 3127 } else { |
3108 // If the media element does not have a current media controller, an d the media element | 3128 // If the media element does not have a current media controller, an d the media element |
3109 // has still ended playback, and the direction of playback is still forwards, and paused | 3129 // has still ended playback, and the direction of playback is still forwards, and paused |
3110 // is false, | 3130 // is false, |
3111 if (!m_mediaController && !m_paused) { | 3131 if (!m_mediaController && !m_paused) { |
3112 // changes paused to true and fires a simple event named pause a t the media element. | 3132 // changes paused to true and fires a simple event named pause a t the media element. |
3113 m_paused = true; | 3133 m_paused = true; |
3114 scheduleEvent(EventTypeNames::pause); | 3134 scheduleEvent(EventTypeNames::pause); |
3115 } | 3135 } |
3116 // Queue a task to fire a simple event named ended at the media elem ent. | 3136 // Queue a task to fire a simple event named ended at the media elem ent. |
3117 if (!m_sentEndEvent) { | 3137 if (!m_sentEndEvent) { |
3118 m_sentEndEvent = true; | 3138 m_sentEndEvent = true; |
3119 scheduleEvent(EventTypeNames::ended); | 3139 scheduleEvent(EventTypeNames::ended); |
3120 } | 3140 } |
3121 // If the media element has a current media controller, then report the controller state | 3141 // If the media element has a current media controller, then report the controller state |
3122 // for the media element's current media controller. | 3142 // for the media element's current media controller. |
3123 updateMediaController(); | 3143 updateMediaController(); |
3124 } | 3144 } |
3145 } else { | |
3146 m_sentEndEvent = false; | |
3125 } | 3147 } |
3126 else | |
3127 m_sentEndEvent = false; | |
3128 | 3148 |
3129 updatePlayState(); | 3149 updatePlayState(); |
3130 } | 3150 } |
3131 | 3151 |
3132 void HTMLMediaElement::mediaPlayerDurationChanged() | 3152 void HTMLMediaElement::mediaPlayerDurationChanged() |
3133 { | 3153 { |
3134 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerDurationChanged"); | 3154 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerDurationChanged"); |
3135 // FIXME: Change MediaPlayerClient & WebMediaPlayer to convey | 3155 // FIXME: Change MediaPlayerClient & WebMediaPlayer to convey |
3136 // the currentTime when the duration change occured. The current | 3156 // the currentTime when the duration change occured. The current |
3137 // WebMediaPlayer implementations always clamp currentTime() to | 3157 // WebMediaPlayer implementations always clamp currentTime() to |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3989 | 4009 |
3990 #if ENABLE(WEB_AUDIO) | 4010 #if ENABLE(WEB_AUDIO) |
3991 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) | 4011 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) |
3992 { | 4012 { |
3993 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) | 4013 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) |
3994 audioSourceProvider()->setClient(0); | 4014 audioSourceProvider()->setClient(0); |
3995 } | 4015 } |
3996 #endif | 4016 #endif |
3997 | 4017 |
3998 } | 4018 } |
OLD | NEW |