Commit 8044ac3e authored by acolwell@chromium.org's avatar acolwell@chromium.org

Fix HTMLMediaElement to always use the 'effective playback rate'

Explicitly introduce the "effective playback rate" concept
in the HTML5 spec and use it to make sure the MediaController's
playback rate is always used when a controller is attached.


BUG=385408
TEST=LayoutTests/media/media-controller-effective-playback-rate.html

Review URL: https://codereview.chromium.org/336303002

git-svn-id: svn://svn.chromium.org/blink/trunk@176344 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 81bedfd6
EVENT(canplay)
EXPECTED (video.controller.playbackRate == '1') OK
EXPECTED (video.playbackRate == '0') OK
RUN(video.play())
EVENT(play)
EVENT(timeupdate)
EXPECTED (video.currentTime != '0') OK
END OF TEST
<!DOCTYPE html>
<html>
<head>
<title>Test effective playback rate with a MediaController.</title>
<script src="media-file.js"></script>
<script src="video-test.js"></script>
<script>
var start = function()
{
findMediaElement();
video.src = findMediaFile("video", "content/test");
// Set the rate on the media element so playback won't move forward.
video.playbackRate = 0;
waitForEvent("canplay",canplay);
};
var canplay = function()
{
video.controller = new MediaController();
// Verify the controller playback rate is 1. This
// means the "effective playback rate" is 1 even though
// the HTMLMediaElement's playbackRate attribute is 0.
testExpected("video.controller.playbackRate", 1);
testExpected("video.playbackRate", 0);
// Initiate playback and verify that time moves forward.
run("video.play()");
waitForEventOnce("play", play);
};
var play = function()
{
waitForEventOnce("timeupdate", timeupdate);
};
var timeupdate = function() {
testExpected("video.currentTime", 0, "!=");
endTest();
};
</script>
</head>
<body onload="start()">
<video></video>
</body>
</html>
...@@ -2116,8 +2116,12 @@ void HTMLMediaElement::setPlaybackRate(double rate) ...@@ -2116,8 +2116,12 @@ void HTMLMediaElement::setPlaybackRate(double rate)
scheduleEvent(EventTypeNames::ratechange); scheduleEvent(EventTypeNames::ratechange);
} }
if (m_player && potentiallyPlaying() && m_player->rate() != rate && !m_mediaController) updatePlaybackRate();
m_player->setRate(rate); }
double HTMLMediaElement::effectivePlaybackRate() const
{
return m_mediaController ? m_mediaController->playbackRate() : m_playbackRate;
} }
HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::directionOfPlayback() const HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::directionOfPlayback() const
...@@ -2127,7 +2131,7 @@ HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::directionOfPlayback() co ...@@ -2127,7 +2131,7 @@ HTMLMediaElement::DirectionOfPlayback HTMLMediaElement::directionOfPlayback() co
void HTMLMediaElement::updatePlaybackRate() void HTMLMediaElement::updatePlaybackRate()
{ {
double effectiveRate = m_mediaController ? m_mediaController->playbackRate() : m_playbackRate; double effectiveRate = effectivePlaybackRate();
if (m_player && potentiallyPlaying() && m_player->rate() != effectiveRate) if (m_player && potentiallyPlaying() && m_player->rate() != effectiveRate)
m_player->setRate(effectiveRate); m_player->setRate(effectiveRate);
} }
...@@ -2340,7 +2344,7 @@ void HTMLMediaElement::playbackProgressTimerFired(Timer<HTMLMediaElement>*) ...@@ -2340,7 +2344,7 @@ void HTMLMediaElement::playbackProgressTimerFired(Timer<HTMLMediaElement>*)
if (!m_seeking) if (!m_seeking)
scheduleTimeupdateEvent(true); scheduleTimeupdateEvent(true);
if (!m_playbackRate) if (!effectivePlaybackRate())
return; return;
if (!m_paused && hasMediaControls()) if (!m_paused && hasMediaControls())
...@@ -3275,7 +3279,7 @@ void HTMLMediaElement::updatePlayState() ...@@ -3275,7 +3279,7 @@ void HTMLMediaElement::updatePlayState()
if (playerPaused) { if (playerPaused) {
// Set rate, muted before calling play in case they were set before the media engine was setup. // Set rate, muted before calling play in case they were set before the media engine was setup.
// The media engine should just stash the rate and muted values since it isn't already playing. // The media engine should just stash the rate and muted values since it isn't already playing.
m_player->setRate(m_playbackRate); m_player->setRate(effectivePlaybackRate());
updateVolume(); updateVolume();
m_player->play(); m_player->play();
......
...@@ -451,6 +451,9 @@ private: ...@@ -451,6 +451,9 @@ private:
enum DirectionOfPlayback { Backward, Forward }; enum DirectionOfPlayback { Backward, Forward };
DirectionOfPlayback directionOfPlayback() const; DirectionOfPlayback directionOfPlayback() const;
// Returns the "effective playback rate" value as specified in the HTML5 spec.
double effectivePlaybackRate() const;
// Creates placeholder AudioTrack and/or VideoTrack objects when WebMemediaPlayer objects // Creates placeholder AudioTrack and/or VideoTrack objects when WebMemediaPlayer objects
// advertise they have audio and/or video, but don't explicitly signal them via // advertise they have audio and/or video, but don't explicitly signal them via
// addAudioTrack() and addVideoTrack(). // addAudioTrack() and addVideoTrack().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment