Bug 469272. Get rid of mPlayRequested since it's not needed; just use mPaused to remember whether we should be playing or not, if play() is called before the stream is loaded. r=doublec,r=kinetik

--HG--
extra : rebase_source : 2753730346f3159f07214e0116a9a32bc45a348d
This commit is contained in:
Robert O'Callahan 2009-02-11 14:23:19 +13:00
Родитель ba8463c7e0
Коммит bf033eb12c
5 изменённых файлов: 73 добавлений и 37 удалений

Просмотреть файл

@ -272,8 +272,4 @@ protected:
// to ensure that the playstate doesn't change when the user goes Forward/Back
// from the bfcache.
PRPackedBool mPausedBeforeFreeze;
// True if playback was requested before a decoder was available to begin
// playback with.
PRPackedBool mPlayRequested;
};

Просмотреть файл

@ -506,8 +506,7 @@ nsHTMLMediaElement::nsHTMLMediaElement(nsINodeInfo *aNodeInfo, PRBool aFromParse
mPaused(PR_TRUE),
mMuted(PR_FALSE),
mIsDoneAddingChildren(!aFromParser),
mPlayingBeforeSeek(PR_FALSE),
mPlayRequested(PR_FALSE)
mPlayingBeforeSeek(PR_FALSE)
{
}
@ -525,33 +524,37 @@ nsHTMLMediaElement::~nsHTMLMediaElement()
NS_IMETHODIMP nsHTMLMediaElement::Play()
{
if (!mDecoder) {
mPlayRequested = PR_TRUE;
return NS_OK;
}
if (mNetworkState == nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
mPlayRequested = PR_TRUE;
return Load();
}
if (mDecoder->IsEnded()) {
SetCurrentTime(0);
nsresult rv = Load();
NS_ENSURE_SUCCESS(rv, rv);
} else if (mDecoder) {
if (mDecoder->IsEnded()) {
SetCurrentTime(0);
}
nsresult rv = mDecoder->Play();
NS_ENSURE_SUCCESS(rv, rv);
}
// TODO: If the playback has ended, then the user agent must set
// currentLoop to zero and seek to the effective start.
// TODO: The playback rate must be set to the default playback rate.
nsresult rv = mDecoder->Play();
NS_ENSURE_SUCCESS(rv, rv);
if (mPaused) {
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("play"));
switch (mReadyState) {
case nsIDOMHTMLMediaElement::HAVE_METADATA:
case nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA:
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("waiting"));
break;
case nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA:
case nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA:
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("playing"));
break;
}
}
PRBool oldPaused = mPaused;
mPaused = PR_FALSE;
mAutoplaying = PR_FALSE;
if (oldPaused)
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("play"));
return NS_OK;
}
@ -870,7 +873,15 @@ nsresult nsHTMLMediaElement::InitializeDecoderForChannel(nsIChannel *aChannel,
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
return mDecoder->Load(nsnull, aChannel, aListener);
nsresult rv = mDecoder->Load(nsnull, aChannel, aListener);
if (NS_FAILED(rv))
return rv;
if (!mPaused) {
rv = mDecoder->Play();
}
return rv;
}
nsresult nsHTMLMediaElement::NewURIFromString(const nsAutoString& aURISpec, nsIURI** aURI)
@ -953,14 +964,6 @@ void nsHTMLMediaElement::MetadataLoaded()
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("durationchange"));
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("loadedmetadata"));
if (mPlayRequested) {
mPlayRequested = PR_FALSE;
mPaused = PR_FALSE;
if (mDecoder) {
mDecoder->Play();
}
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("play"));
}
}
void nsHTMLMediaElement::FirstFrameLoaded()
@ -1103,16 +1106,12 @@ void nsHTMLMediaElement::ChangeReadyState(nsMediaReadyState aState)
break;
case nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA:
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("canplaythrough"));
if (oldState != mReadyState) {
LOG(PR_LOG_DEBUG, ("Ready state changed to HAVE_ENOUGH_DATA"));
}
if (oldState <= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA) {
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("canplay"));
}
if (oldState <= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("canplaythrough"));
}
if (mAutoplaying &&
mPaused &&
HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) {
@ -1127,6 +1126,9 @@ void nsHTMLMediaElement::ChangeReadyState(nsMediaReadyState aState)
IsPotentiallyPlaying()) {
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("playing"));
}
if (oldState <= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("canplaythrough"));
}
break;
}
}

Просмотреть файл

@ -75,6 +75,7 @@ _TEST_FILES += \
test_ended1.html \
test_ended2.html \
test_onloadedmetadata.html \
test_play.html \
test_progress1.html \
test_progress3.html \
test_standalone.html \

Просмотреть файл

@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: autoplay attribute get</title>
<title>Media test: autoplay attribute</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />

Просмотреть файл

@ -0,0 +1,37 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: play() method</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<video id="v"></video>
<script>
SimpleTest.waitForExplicitFinish();
var v = document.getElementById("v");
var playEvents = ["play", "canplay", "playing", "canplaythrough"];
function gotPlayEvent(event) {
is(event.type, playEvents.shift(), "Check expected event");
}
for (var i = 0; i < playEvents.length; ++i) {
v.addEventListener(playEvents[i], gotPlayEvent, false);
}
function ended() {
is(playEvents.length, 0, "Undelivered event " + playEvents[0]);
SimpleTest.finish();
}
v.addEventListener("ended", ended, false);
v.src = "320x240.ogv";
v.load();
v.play();
</script>
</pre>
</body>
</html>