Bug 1655204 - part1 : stop being controlled by media control keys when media element receives Stop. r=chunmin

Currently, we treat `pause` and `stop` equally, but `stop` is actully implying more meaning, which should stop controlling media entirely. Therefore, we would pause media and stop controlling it when receiving `stop`.

In addition, removing pause state checking, because it wouldn't happen anything to call `play()` and `pause()` if media is already playing or paused.

Differential Revision: https://phabricator.services.mozilla.com/D84875
This commit is contained in:
alwu
2020-07-29 22:15:50 +00:00
parent 5da1c4e450
commit 05987c5c1d
2 changed files with 11 additions and 5 deletions

View File

@@ -523,12 +523,15 @@ class HTMLMediaElement::MediaControlKeyListener final
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(IsStarted());
MEDIACONTROL_LOG("HandleEvent '%s'", ToMediaControlKeyStr(aKey));
if (aKey == MediaControlKey::Play && Owner()->Paused()) {
if (aKey == MediaControlKey::Play) {
Owner()->Play();
} else if ((aKey == MediaControlKey::Pause ||
aKey == MediaControlKey::Stop) &&
!Owner()->Paused()) {
} else if (aKey == MediaControlKey::Pause) {
Owner()->Pause();
} else {
MOZ_ASSERT(aKey == MediaControlKey::Stop,
"Not supported key for media element!");
Owner()->Pause();
StopIfNeeded();
}
}