From 6a2fdb1c3abbdebe15951e92bb465b30f3724424 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Sat, 11 Sep 2010 11:29:11 +1200 Subject: [PATCH] Bug 589626 - Force canplaythrough to fire when the download has been suspended. r=roc a=blocking --- content/html/content/src/nsHTMLMediaElement.cpp | 12 ++++++++++++ content/media/nsBuiltinDecoder.cpp | 1 + content/media/test/test_audio2.html | 2 +- content/media/test/test_timeupdate3.html | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 9811766cec70..fe0081b2a400 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -2087,6 +2087,18 @@ void nsHTMLMediaElement::UpdateReadyStateForData(NextFrameStatus aNextFrame) return; } + if (mDecoder->GetCurrentStream()->IsSuspendedByCache() && + !mDecoder->IsEnded()) + { + // The download has been suspended by the media cache, and we've not + // completed playback of the resource, so go into HAVE_ENOUGH_DATA state. + // This ensures we always fire canplaythrough and other play events, + // particularly when we suspend the download before the download rate + // has been reliably established. + ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA); + return; + } + // Now see if we should set HAVE_ENOUGH_DATA. // If it's something we don't know the size of, then we can't // make a real estimate, so we go straight to HAVE_ENOUGH_DATA once diff --git a/content/media/nsBuiltinDecoder.cpp b/content/media/nsBuiltinDecoder.cpp index 2baa2870267f..a813b56971b3 100644 --- a/content/media/nsBuiltinDecoder.cpp +++ b/content/media/nsBuiltinDecoder.cpp @@ -556,6 +556,7 @@ void nsBuiltinDecoder::NotifySuspendedStatusChanged() // now so we consume data and hopefully free up cache space mElement->NotifyAutoplayDataReady(); } + UpdateReadyStateForData(); } void nsBuiltinDecoder::NotifyBytesDownloaded() diff --git a/content/media/test/test_audio2.html b/content/media/test/test_audio2.html index b698069667a5..e365ec4e0600 100644 --- a/content/media/test/test_audio2.html +++ b/content/media/test/test_audio2.html @@ -17,7 +17,7 @@ var manager = new MediaTestManager; function startTest(test, token) { if (!tmpAudio.canPlayType(test.type)) - continue; + return; manager.started(token); var a1 = new Audio(test.name); is(a1.getAttribute("preload"), "auto", "Preload automatically set to auto"); diff --git a/content/media/test/test_timeupdate3.html b/content/media/test/test_timeupdate3.html index 0fb1a3aaf1d2..4522651beacb 100644 --- a/content/media/test/test_timeupdate3.html +++ b/content/media/test/test_timeupdate3.html @@ -49,6 +49,7 @@ SimpleTest.waitForExplicitFinish();