Commit 6990c3c6 authored by acolwell@chromium.org's avatar acolwell@chromium.org

Allow load if play() is immediately called when preload == 'none'

This fixes a bug where the load gets blocked by preload == 'none'
eventhough JavaScript has called play() after setting the src
attribute. This particular bug only appears if play() is called before
the JavaScript code relinquishes control back to the UA.

Tests cases were added to make sure that immediate load() and play()
calls both trigger loading. Before this change, only immediate load()
calls ignored the preload == "none" state.

BUG=177870
TEST=LayoutTest/media/video-preload.html

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

git-svn-id: svn://svn.chromium.org/blink/trunk@175590 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 7fe778e7
...@@ -11,9 +11,27 @@ EVENT(play) ...@@ -11,9 +11,27 @@ EVENT(play)
EVENT(loadedmetadata) EVENT(loadedmetadata)
buffered automatically OK buffered automatically OK
Will load with 'preload=none', should buffer automatically because 'load()' is called
RUN(video.setAttribute('preload', 'none'))
RUN(video.removeAttribute('autoplay'))
RUN(video.load())
EVENT(loadstart)
EVENT(loadedmetadata)
buffered automatically OK
Will load with 'preload=none', should buffer automatically because 'play()' is called
RUN(video.setAttribute('preload', 'none'))
RUN(video.removeAttribute('autoplay'))
RUN(video.play())
EVENT(play)
EVENT(loadstart)
EVENT(loadedmetadata)
buffered automatically OK
Will load with 'preload=metadata', should buffer automatically Will load with 'preload=metadata', should buffer automatically
RUN(video.setAttribute('preload', 'metadata')) RUN(video.setAttribute('preload', 'metadata'))
RUN(video.removeAttribute('autoplay')) RUN(video.removeAttribute('autoplay'))
RUN(video.load())
EVENT(loadstart) EVENT(loadstart)
EVENT(loadedmetadata) EVENT(loadedmetadata)
buffered automatically OK buffered automatically OK
...@@ -21,6 +39,7 @@ buffered automatically OK ...@@ -21,6 +39,7 @@ buffered automatically OK
Will load with 'preload=auto', should buffer automatically Will load with 'preload=auto', should buffer automatically
RUN(video.setAttribute('preload', 'auto')) RUN(video.setAttribute('preload', 'auto'))
RUN(video.removeAttribute('autoplay')) RUN(video.removeAttribute('autoplay'))
RUN(video.load())
EVENT(loadstart) EVENT(loadstart)
EVENT(loadedmetadata) EVENT(loadedmetadata)
buffered automatically OK buffered automatically OK
...@@ -28,6 +47,7 @@ buffered automatically OK ...@@ -28,6 +47,7 @@ buffered automatically OK
Will load with 'preload=none', should buffer automatically because of 'autoplay' Will load with 'preload=none', should buffer automatically because of 'autoplay'
RUN(video.setAttribute('preload', 'none')) RUN(video.setAttribute('preload', 'none'))
RUN(video.setAttribute('autoplay', 'true')) RUN(video.setAttribute('autoplay', 'true'))
RUN(video.load())
EVENT(loadstart) EVENT(loadstart)
EVENT(loadedmetadata) EVENT(loadedmetadata)
buffered automatically OK buffered automatically OK
......
...@@ -7,36 +7,56 @@ ...@@ -7,36 +7,56 @@
<script> <script>
var timer = null; var timer = null;
var movieInfo = var movieInfo =
{ {
current : -1, current : -1,
movies : movies :
[ [
{ {
// should not buffer, 'preload' is 'none' // should not buffer, 'preload' is 'none'
preload : "none", preload : "none",
shouldBuffer : false, shouldBuffer : false,
autoPlay : false, autoPlay : false,
description : "until 'play()' is called", playInsteadOfLoad : false,
description : "until 'play()' is called",
},
{
// should buffer, because load() is called.
preload : "none",
shouldBuffer : true,
autoPlay : false,
playInsteadOfLoad : false,
description : "because 'load()' is called",
},
{
// should buffer, because play() is called.
preload : "none",
shouldBuffer : true,
autoPlay : false,
playInsteadOfLoad : true,
description : "because 'play()' is called",
}, },
{ {
preload : "metadata", preload : "metadata",
shouldBuffer : true, shouldBuffer : true,
autoPlay : false, autoPlay : false,
description : "", playInsteadOfLoad : false,
description : "",
}, },
{ {
preload : "auto", preload : "auto",
shouldBuffer : true, shouldBuffer : true,
autoPlay : false, autoPlay : false,
description : "", playInsteadOfLoad : false,
description : "",
}, },
{ {
// should buffer because 'autoplay' is set // should buffer because 'autoplay' is set
preload : "none", preload : "none",
shouldBuffer : true, shouldBuffer : true,
autoPlay : true, autoPlay : true,
description : " because of 'autoplay'", playInsteadOfLoad : false,
description : " because of 'autoplay'",
}, },
] ]
}; };
...@@ -47,7 +67,7 @@ ...@@ -47,7 +67,7 @@
var movie = movieInfo.movies[movieInfo.current]; var movie = movieInfo.movies[movieInfo.current];
logResult(true, "did not buffer automatically"); logResult(true, "did not buffer automatically");
// start playback, which should force data to load // start playback, which should force data to load
movie.shouldBuffer = true; movie.shouldBuffer = true;
run("video.play()"); run("video.play()");
...@@ -92,12 +112,17 @@ ...@@ -92,12 +112,17 @@
setupAttribute('autoplay', movie.autoPlay); setupAttribute('autoplay', movie.autoPlay);
video.src = url; video.src = url;
if (movieInfo.current > 0) if (movieInfo.current > 0) {
video.load(); if (movie.playInsteadOfLoad) {
run("video.play()");
} else {
run("video.load()");
}
}
if (!movie.shouldBuffer) if (!movie.shouldBuffer)
timer = setTimeout(checkLoad, 200); timer = setTimeout(checkLoad, 200);
} }
function start() function start()
{ {
findMediaElement(); findMediaElement();
...@@ -106,7 +131,7 @@ ...@@ -106,7 +131,7 @@
waitForEvent("loadstart"); waitForEvent("loadstart");
waitForEvent("play"); waitForEvent("play");
waitForEvent('loadedmetadata', loadedmetadata); waitForEvent('loadedmetadata', loadedmetadata);
openNextMovie(); openNextMovie();
} }
......
...@@ -889,10 +889,12 @@ void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c ...@@ -889,10 +889,12 @@ void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c
if (attemptLoad && canLoadURL(url, contentType, keySystem)) { if (attemptLoad && canLoadURL(url, contentType, keySystem)) {
ASSERT(!webMediaPlayer()); ASSERT(!webMediaPlayer());
if (!autoplay() && m_preload == MediaPlayer::None) if (!m_havePreparedToPlay && !autoplay() && m_preload == MediaPlayer::None) {
WTF_LOG(Media, "HTMLMediaElement::loadResource : Delaying load because preload == 'none'");
m_delayingLoadForPreloadNone = true; m_delayingLoadForPreloadNone = true;
else } else {
startPlayerLoad(); startPlayerLoad();
}
} else { } else {
mediaLoadingFailed(MediaPlayer::FormatError); mediaLoadingFailed(MediaPlayer::FormatError);
} }
......
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