Bug 470662 - Don't set paused to true when playback ends. Fix handling of playing/suspend attrs. r=chris.double, sr=roc

--HG--
extra : rebase_source : f5161f9a699015b41c4947b52624901786adc852
This commit is contained in:
Matthew Gregan 2009-02-27 00:55:30 +13:00
Родитель f961f09fa9
Коммит 0dea2b79f9
13 изменённых файлов: 146 добавлений и 86 удалений

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

@ -462,19 +462,21 @@ nsContentUtils::InitializeEventTable() {
#ifdef MOZ_MEDIA
{ &nsGkAtoms::onloadstart, { NS_LOADSTART, EventNameType_HTML }},
{ &nsGkAtoms::onprogress, { NS_PROGRESS, EventNameType_HTML }},
{ &nsGkAtoms::onloadedmetadata, { NS_LOADEDMETADATA, EventNameType_HTML }},
{ &nsGkAtoms::onloadeddata, { NS_LOADEDDATA, EventNameType_HTML }},
{ &nsGkAtoms::onsuspend, { NS_SUSPEND, EventNameType_HTML }},
{ &nsGkAtoms::onemptied, { NS_EMPTIED, EventNameType_HTML }},
{ &nsGkAtoms::onstalled, { NS_STALLED, EventNameType_HTML }},
{ &nsGkAtoms::onplay, { NS_PLAY, EventNameType_HTML }},
{ &nsGkAtoms::onpause, { NS_PAUSE, EventNameType_HTML }},
{ &nsGkAtoms::onloadedmetadata, { NS_LOADEDMETADATA, EventNameType_HTML }},
{ &nsGkAtoms::onloadeddata, { NS_LOADEDDATA, EventNameType_HTML }},
{ &nsGkAtoms::onwaiting, { NS_WAITING, EventNameType_HTML }},
{ &nsGkAtoms::onplaying, { NS_PLAYING, EventNameType_HTML }},
{ &nsGkAtoms::oncanplay, { NS_CANPLAY, EventNameType_HTML }},
{ &nsGkAtoms::oncanplaythrough, { NS_CANPLAYTHROUGH, EventNameType_HTML }},
{ &nsGkAtoms::onseeking, { NS_SEEKING, EventNameType_HTML }},
{ &nsGkAtoms::onseeked, { NS_SEEKED, EventNameType_HTML }},
{ &nsGkAtoms::ontimeupdate, { NS_TIMEUPDATE, EventNameType_HTML }},
{ &nsGkAtoms::onended, { NS_ENDED, EventNameType_HTML }},
{ &nsGkAtoms::oncanplay, { NS_CANPLAY, EventNameType_HTML }},
{ &nsGkAtoms::oncanplaythrough, { NS_CANPLAYTHROUGH, EventNameType_HTML }},
{ &nsGkAtoms::onratechange, { NS_RATECHANGE, EventNameType_HTML }},
{ &nsGkAtoms::ondurationchange, { NS_DURATIONCHANGE, EventNameType_HTML }},
{ &nsGkAtoms::onvolumechange, { NS_VOLUMECHANGE, EventNameType_HTML }},

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

@ -1589,31 +1589,35 @@ GK_ATOM(svgUseFrame, "SVGUseFrame")
GK_ATOM(HTMLVideoFrame, "VideoFrame")
GK_ATOM(onloadstart, "onloadstart")
GK_ATOM(onprogress, "onprogress")
GK_ATOM(onloadedmetadata, "onloadedmetadata")
GK_ATOM(onloadeddata, "onloadeddata")
GK_ATOM(onsuspend, "onsuspend")
GK_ATOM(onemptied, "onemptied")
GK_ATOM(onstalled, "onstalled")
GK_ATOM(onplay, "onplay")
GK_ATOM(onpause, "onpause")
GK_ATOM(onloadedmetadata, "onloadedmetadata")
GK_ATOM(onloadeddata, "onloadeddata")
GK_ATOM(onwaiting, "onwaiting")
GK_ATOM(onplaying, "onplaying")
GK_ATOM(oncanplay, "oncanplay")
GK_ATOM(oncanplaythrough, "oncanplaythrough")
GK_ATOM(onseeking, "onseeking")
GK_ATOM(onseeked, "onseeked")
GK_ATOM(ontimeupdate, "ontimeupdate")
GK_ATOM(onended, "onended")
GK_ATOM(oncanplay, "oncanplay")
GK_ATOM(oncanplaythrough, "oncanplaythrough")
GK_ATOM(onratechange, "onratechange")
GK_ATOM(ondurationchange, "ondurationchange")
GK_ATOM(onvolumechange, "onvolumechange")
GK_ATOM(loadstart, "loadstart")
GK_ATOM(progress, "progress")
GK_ATOM(loadedmetadata, "loadedmetadata")
GK_ATOM(loadeddata, "loadeddata")
GK_ATOM(suspend, "suspend")
GK_ATOM(emptied, "emptied")
GK_ATOM(stalled, "stalled")
GK_ATOM(play, "play")
GK_ATOM(pause, "pause")
GK_ATOM(loadedmetadata, "loadedmetadata")
GK_ATOM(loadeddata, "loadeddata")
GK_ATOM(waiting, "waiting")
GK_ATOM(playing, "playing")
GK_ATOM(seeking, "seeking")
GK_ATOM(seeked, "seeked")
GK_ATOM(timeupdate, "timeupdate")

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

@ -77,10 +77,10 @@ static const char* const sEventNames[] = {
"SVGZoom",
#endif // MOZ_SVG
#ifdef MOZ_MEDIA
"loadstart", "progress", "loadedmetadata", "loadeddata",
"emptied", "stalled", "play", "pause",
"waiting", "seeking", "seeked", "timeupdate", "ended",
"canplay", "canplaythrough", "ratechange", "durationchange", "volumechange",
"loadstart", "progress", "suspend", "emptied", "stalled", "play", "pause",
"loadedmetadata", "loadeddata", "waiting", "playing", "canplay",
"canplaythrough", "seeking", "seeked", "timeupdate", "ended", "ratechange",
"durationchange", "volumechange",
#endif // MOZ_MEDIA
"MozAfterPaint",
"MozSwipeGesture",
@ -619,10 +619,8 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg)
mEvent->message = NS_LOADSTART;
else if (atom == nsGkAtoms::onprogress)
mEvent->message = NS_PROGRESS;
else if (atom == nsGkAtoms::onloadedmetadata)
mEvent->message = NS_LOADEDMETADATA;
else if (atom == nsGkAtoms::onloadeddata)
mEvent->message = NS_LOADEDDATA;
else if (atom == nsGkAtoms::onsuspend)
mEvent->message = NS_SUSPEND;
else if (atom == nsGkAtoms::onemptied)
mEvent->message = NS_EMPTIED;
else if (atom == nsGkAtoms::onstalled)
@ -631,20 +629,26 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg)
mEvent->message = NS_PLAY;
else if (atom == nsGkAtoms::onpause)
mEvent->message = NS_PAUSE;
else if (atom == nsGkAtoms::onloadedmetadata)
mEvent->message = NS_LOADEDMETADATA;
else if (atom == nsGkAtoms::onloadeddata)
mEvent->message = NS_LOADEDDATA;
else if (atom == nsGkAtoms::onwaiting)
mEvent->message = NS_WAITING;
else if (atom == nsGkAtoms::onwaiting)
mEvent->message = NS_SEEKING;
else if (atom == nsGkAtoms::onseeking)
mEvent->message = NS_SEEKED;
else if (atom == nsGkAtoms::onseeked)
mEvent->message = NS_TIMEUPDATE;
else if (atom == nsGkAtoms::onended)
mEvent->message = NS_ENDED;
else if (atom == nsGkAtoms::onplaying)
mEvent->message = NS_PLAYING;
else if (atom == nsGkAtoms::oncanplay)
mEvent->message = NS_CANPLAY;
else if (atom == nsGkAtoms::oncanplaythrough)
mEvent->message = NS_CANPLAYTHROUGH;
else if (atom == nsGkAtoms::onseeking)
mEvent->message = NS_SEEKING;
else if (atom == nsGkAtoms::onseeked)
mEvent->message = NS_SEEKED;
else if (atom == nsGkAtoms::ontimeupdate)
mEvent->message = NS_TIMEUPDATE;
else if (atom == nsGkAtoms::onended)
mEvent->message = NS_ENDED;
else if (atom == nsGkAtoms::onratechange)
mEvent->message = NS_RATECHANGE;
else if (atom == nsGkAtoms::ondurationchange)
@ -1474,10 +1478,8 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return sEventNames[eDOMEvents_loadstart];
case NS_PROGRESS:
return sEventNames[eDOMEvents_progress];
case NS_LOADEDMETADATA:
return sEventNames[eDOMEvents_loadedmetadata];
case NS_LOADEDDATA:
return sEventNames[eDOMEvents_loadeddata];
case NS_SUSPEND:
return sEventNames[eDOMEvents_suspend];
case NS_EMPTIED:
return sEventNames[eDOMEvents_emptied];
case NS_STALLED:
@ -1486,8 +1488,18 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return sEventNames[eDOMEvents_play];
case NS_PAUSE:
return sEventNames[eDOMEvents_pause];
case NS_LOADEDMETADATA:
return sEventNames[eDOMEvents_loadedmetadata];
case NS_LOADEDDATA:
return sEventNames[eDOMEvents_loadeddata];
case NS_WAITING:
return sEventNames[eDOMEvents_waiting];
case NS_PLAYING:
return sEventNames[eDOMEvents_playing];
case NS_CANPLAY:
return sEventNames[eDOMEvents_canplay];
case NS_CANPLAYTHROUGH:
return sEventNames[eDOMEvents_canplaythrough];
case NS_SEEKING:
return sEventNames[eDOMEvents_seeking];
case NS_SEEKED:
@ -1496,10 +1508,6 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return sEventNames[eDOMEvents_timeupdate];
case NS_ENDED:
return sEventNames[eDOMEvents_ended];
case NS_CANPLAY:
return sEventNames[eDOMEvents_canplay];
case NS_CANPLAYTHROUGH:
return sEventNames[eDOMEvents_canplaythrough];
case NS_RATECHANGE:
return sEventNames[eDOMEvents_ratechange];
case NS_DURATIONCHANGE:

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

@ -142,19 +142,21 @@ public:
#ifdef MOZ_MEDIA
eDOMEvents_loadstart,
eDOMEvents_progress,
eDOMEvents_loadedmetadata,
eDOMEvents_loadeddata,
eDOMEvents_suspend,
eDOMEvents_emptied,
eDOMEvents_stalled,
eDOMEvents_play,
eDOMEvents_pause,
eDOMEvents_loadedmetadata,
eDOMEvents_loadeddata,
eDOMEvents_waiting,
eDOMEvents_playing,
eDOMEvents_canplay,
eDOMEvents_canplaythrough,
eDOMEvents_seeking,
eDOMEvents_seeked,
eDOMEvents_timeupdate,
eDOMEvents_ended,
eDOMEvents_canplay,
eDOMEvents_canplaythrough,
eDOMEvents_ratechange,
eDOMEvents_durationchange,
eDOMEvents_volumechange,

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

@ -1184,8 +1184,6 @@ void nsHTMLMediaElement::NetworkError()
void nsHTMLMediaElement::PlaybackEnded()
{
NS_ASSERTION(mDecoder->IsEnded(), "Decoder fired ended, but not in ended state");
mBegun = PR_FALSE;
mPaused = PR_TRUE;
DispatchAsyncSimpleEvent(NS_LITERAL_STRING("ended"));
}

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

@ -1357,6 +1357,8 @@ nsWaveDecoder::Load(nsIURI* aURI, nsIChannel* aChannel, nsIStreamListener** aStr
// Reset progress member variables
mResourceLoaded = PR_FALSE;
mResourceLoadedReported = PR_FALSE;
mMetadataLoadedReported = PR_FALSE;
if (aStreamListener) {
*aStreamListener = nsnull;

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

@ -131,6 +131,7 @@ _TEST_FILES += \
test_bug465498.html \
test_bug468190_wav.html \
test_can_play_type_wave.html \
test_paused_after_ended.html \
test_wav_8bit.html \
test_wav_ended1.html \
test_wav_ended2.html \

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

@ -15,7 +15,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=468190
<script class="testbody" type="text/javascript">
// Test if video can be replayed after ended.
var completed = false;
var playCount = 0;
var playingCount = 0;
var endCount = 0;
function startTest() {
if (completed)
@ -30,25 +31,27 @@ function playbackStarted() {
if (completed)
return false;
playCount++;
playingCount++;
}
function playbackEnded() {
if (completed)
return false
endCount++;
var v = document.getElementById('v');
ok(v.currentTime >= 3.9 && v.currentTime <= 4.0,
"Checking currentTime at end: " + v.currentTime);
ok(v.ended, "Checking playback has ended");
if (playCount < 2) {
ok(playingCount > 0, "Expect at least one playing event");
playingCount = 0;
if (endCount < 2) {
v.currentTime = 0;
ok(v.seeking, "Checking that seeking is now true");
ok(!v.ended, "Checking ended is no longer set as seeking has begun");
v.play();
}
else {
ok(playCount == 2, "Check playback after ended event");
} else {
ok(endCount == 2, "Check playback after ended event");
completed = true;
SimpleTest.finish();
}
@ -61,7 +64,7 @@ SimpleTest.waitForExplicitFinish();
<video id='v'
src='seek.ogv'
onloadedmetadata='return startTest();'
onplay='return playbackStarted();'
onplaying='return playbackStarted();'
onended='return playbackEnded();'></video>
</body>
</html>

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

@ -15,7 +15,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=468190
<script class="testbody" type="text/javascript">
// Test if video can be replayed after ended.
var completed = false;
var playCount = 0;
var playingCount = 0;
var endCount = 0;
function startTest() {
if (completed)
@ -30,25 +31,27 @@ function playbackStarted() {
if (completed)
return false;
playCount++;
playingCount++;
}
function playbackEnded() {
if (completed)
return false
endCount++;
var v = document.getElementById('v');
ok(v.currentTime >= 0.9 && v.currentTime <= 1.1,
"Checking currentTime at end: " + v.currentTime);
ok(v.ended, "Checking playback has ended");
if (playCount < 2) {
ok(playingCount > 0, "Expect at least one playing event");
playingCount = 0;
if (endCount < 2) {
v.currentTime = 0;
ok(v.seeking, "Checking that seeking is now true");
ok(!v.ended, "Checking ended is no longer set as seeking has begun");
v.play();
}
else {
ok(playCount == 2, "Check playback after ended event");
} else {
ok(endCount == 2, "Check playback after ended event");
completed = true;
SimpleTest.finish();
}
@ -60,7 +63,7 @@ SimpleTest.waitForExplicitFinish();
</pre>
<video id='v'
onloadedmetadata='return startTest();'
onplay='return playbackStarted();'
onplaying='return playbackStarted();'
onended='return playbackEnded();'><source src='r11025_s16_c1.wav' type='audio/x-wav'></video>
</body>
</html>

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

@ -11,7 +11,8 @@
<script class="testbody" type="text/javascript">
// Test if video can be replayed after ended.
var completed = false;
var playCount = 0;
var playingCount = 0;
var endCount = 0;
function startTest() {
if (completed)
@ -26,21 +27,24 @@ function playbackStarted() {
if (completed)
return false;
playCount++;
playingCount++;
}
function playbackEnded() {
if (completed)
return false
endCount++;
var v = document.getElementById('v');
ok(v.currentTime >= 3.9 && v.currentTime <= 4.0,
"Checking currentTime at end: " + v.currentTime);
ok(v.ended, "Checking playback has ended");
if (playCount < 2) {
ok(playingCount > 0, "Expect at least one playing event");
playingCount = 0;
if (endCount < 2) {
v.play();
}
else {
ok(playCount == 2, "Check playback after ended event");
} else {
ok(endCount == 2, "Check playback after ended event");
completed = true;
SimpleTest.finish();
}
@ -53,7 +57,7 @@ SimpleTest.waitForExplicitFinish();
<video id='v'
src='seek.ogv'
onloadedmetadata='return startTest();'
onplay='return playbackStarted();'
onplaying='return playbackStarted();'
onended='return playbackEnded();'></video>
</body>
</html>

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

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: paused</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">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var a = document.createElement('audio');
a.src = 'r11025_u8_c1.wav';
a.load();
is(a.paused, true, "Must be paused at start");
a.play();
is(a.paused, false, "Must not be paused after play");
a.addEventListener("ended", function () {
is(a.paused, false, "Must not be paused after end");
SimpleTest.finish();
}, false);
</script>
</pre>
</body>
</html>

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

@ -12,7 +12,8 @@
<script class="testbody" type="text/javascript">
// Test if audio can be replayed after ended.
var completed = false;
var playCount = 0;
var playingCount = 0;
var endCount = 0;
function startTest() {
if (completed)
@ -27,22 +28,24 @@ function playbackStarted() {
if (completed)
return false;
playCount++;
playingCount++;
}
function playbackEnded() {
if (completed)
return false
endCount++;
var v = document.getElementById('v');
ok(v.currentTime >= 0.9 && v.currentTime <= 1.1,
"Checking currentTime at end: " + v.currentTime);
ok(v.ended, "Checking playback has ended");
if (playCount < 2) {
ok(playingCount > 0, "Expect at least one playing event");
playingCount = 0;
if (endCount < 2) {
v.play();
}
else {
ok(playCount == 2, "Check playback after ended event");
} else {
ok(endCount == 2, "Check playback after ended event");
completed = true;
SimpleTest.finish();
}
@ -54,7 +57,7 @@ SimpleTest.waitForExplicitFinish();
</pre>
<audio id='v'
onloadedmetadata='return startTest();'
onplay='return playbackStarted();'
onplaying='return playbackStarted();'
onended='return playbackEnded();'>
<source type='audio/x-wav' src='r11025_s16_c1.wav'>
</audio>

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

@ -368,24 +368,26 @@ class nsHashKey;
#define NS_MEDIA_EVENT_START 3300
#define NS_LOADSTART (NS_MEDIA_EVENT_START)
#define NS_PROGRESS (NS_MEDIA_EVENT_START+1)
#define NS_LOADEDMETADATA (NS_MEDIA_EVENT_START+2)
#define NS_LOADEDDATA (NS_MEDIA_EVENT_START+3)
#define NS_EMPTIED (NS_MEDIA_EVENT_START+4)
#define NS_STALLED (NS_MEDIA_EVENT_START+5)
#define NS_PLAY (NS_MEDIA_EVENT_START+6)
#define NS_PAUSE (NS_MEDIA_EVENT_START+7)
#define NS_WAITING (NS_MEDIA_EVENT_START+8)
#define NS_SEEKING (NS_MEDIA_EVENT_START+9)
#define NS_SEEKED (NS_MEDIA_EVENT_START+10)
#define NS_TIMEUPDATE (NS_MEDIA_EVENT_START+11)
#define NS_ENDED (NS_MEDIA_EVENT_START+12)
#define NS_CANPLAY (NS_MEDIA_EVENT_START+13)
#define NS_CANPLAYTHROUGH (NS_MEDIA_EVENT_START+14)
#define NS_RATECHANGE (NS_MEDIA_EVENT_START+15)
#define NS_DURATIONCHANGE (NS_MEDIA_EVENT_START+16)
#define NS_VOLUMECHANGE (NS_MEDIA_EVENT_START+17)
#define NS_MEDIA_ABORT (NS_MEDIA_EVENT_START+18)
#define NS_MEDIA_ERROR (NS_MEDIA_EVENT_START+19)
#define NS_SUSPEND (NS_MEDIA_EVENT_START+2)
#define NS_EMPTIED (NS_MEDIA_EVENT_START+3)
#define NS_STALLED (NS_MEDIA_EVENT_START+4)
#define NS_PLAY (NS_MEDIA_EVENT_START+5)
#define NS_PAUSE (NS_MEDIA_EVENT_START+6)
#define NS_LOADEDMETADATA (NS_MEDIA_EVENT_START+7)
#define NS_LOADEDDATA (NS_MEDIA_EVENT_START+8)
#define NS_WAITING (NS_MEDIA_EVENT_START+9)
#define NS_PLAYING (NS_MEDIA_EVENT_START+10)
#define NS_CANPLAY (NS_MEDIA_EVENT_START+11)
#define NS_CANPLAYTHROUGH (NS_MEDIA_EVENT_START+12)
#define NS_SEEKING (NS_MEDIA_EVENT_START+13)
#define NS_SEEKED (NS_MEDIA_EVENT_START+14)
#define NS_TIMEUPDATE (NS_MEDIA_EVENT_START+15)
#define NS_ENDED (NS_MEDIA_EVENT_START+16)
#define NS_RATECHANGE (NS_MEDIA_EVENT_START+17)
#define NS_DURATIONCHANGE (NS_MEDIA_EVENT_START+18)
#define NS_VOLUMECHANGE (NS_MEDIA_EVENT_START+19)
#define NS_MEDIA_ABORT (NS_MEDIA_EVENT_START+20)
#define NS_MEDIA_ERROR (NS_MEDIA_EVENT_START+21)
#endif // MOZ_MEDIA
// paint notification events