Bug 1302453 - part1 : send new gecko event when media is resumed.
We uses "media-playback" event to notify fennec media control about media start
and end. However, if we resume media which was paused by media control, it won't
send any notification to JAVA side so that the MediaControlService can't change
the correct playing icon.
Therefore, we create new event to inform this situation.
MozReview-Commit-ID: zScaHxvHXM
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -32,16 +32,18 @@
#include "nsNetUtil.h"
#include "nsXPCOMStrings.h"
#include "xpcpublic.h"
#include "nsThreadUtils.h"
#include "nsIThreadInternal.h"
#include "nsContentUtils.h"
#include "nsIRequest.h"
#include "nsQueryObject.h"
+#include "nsIObserverService.h"
+#include "nsISupportsPrimitives.h"
#include "nsIScriptSecurityManager.h"
#include "nsIXPConnect.h"
#include "jsapi.h"
#include "nsITimer.h"
#include "MediaError.h"
@@ -5940,16 +5942,17 @@ HTMLMediaElement::BlockByAudioChannel()
void
HTMLMediaElement::SetAudioChannelSuspended(SuspendTypes aSuspend)
{
if (mAudioChannelSuspended == aSuspend) {
return;
}
+ MaybeNotifyMediaResumed(aSuspend);
mAudioChannelSuspended = aSuspend;
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("HTMLMediaElement, SetAudioChannelSuspended, this = %p, "
"aSuspend = %d\n", this, aSuspend));
NotifyAudioPlaybackChanged(
AudioChannelService::AudibleChangedReasons::ePauseStateChanged);
}
@@ -6422,16 +6425,47 @@ HTMLMediaElement::IsAudible() const
// Silent audio track.
if (!mIsAudioTrackAudible) {
return false;
}
return true;
}
+void
+HTMLMediaElement::MaybeNotifyMediaResumed(SuspendTypes aSuspend)
+{
+ // In fennec, we should send the notification when media is resumed from the
+ // pause-disposable which was called by media control.
+ if (mAudioChannelSuspended != nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE &&
+ aSuspend != nsISuspendedTypes::NONE_SUSPENDED) {
+ return;
+ }
+
+ uint64_t windowID = mAudioChannelAgent->WindowID();
+ NS_DispatchToMainThread(NS_NewRunnableFunction([windowID]() -> void {
+ nsCOMPtr<nsIObserverService> observerService =
+ services::GetObserverService();
+ if (NS_WARN_IF(!observerService)) {
+ return;
+ }
+
+ nsCOMPtr<nsISupportsPRUint64> wrapper =
+ do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID);
+ if (NS_WARN_IF(!wrapper)) {
+ return;
+ }
+
+ wrapper->SetData(windowID);
+ observerService->NotifyObservers(wrapper,
+ "media-playback-resumed",
+ u"active");
+ }));
+}
+
bool
HTMLMediaElement::HaveFailedWithSourceNotSupportedError() const
{
if (!mError) {
return false;
}
uint16_t errorCode = mError->Code();
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1263,16 +1263,20 @@ protected:
bool IsAllowedToPlay();
bool IsAudible() const;
bool HaveFailedWithSourceNotSupportedError() const;
void OpenUnsupportedMediaWithExtenalAppIfNeeded();
+ // It's used for fennec only, send the notification when the user resumes the
+ // media which was paused by media control.
+ void MaybeNotifyMediaResumed(SuspendTypes aSuspend);
+
class nsAsyncEventRunner;
using nsGenericHTMLElement::DispatchEvent;
// For nsAsyncEventRunner.
nsresult DispatchEvent(const nsAString& aName);
// The current decoder. Load() has been called on this decoder.
// At most one of mDecoder and mSrcStream can be non-null.
RefPtr<MediaDecoder> mDecoder;