зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1582508 - part5 : replace 'PlaybackState' with 'MediaSessionPlaybackState'. r=chunmin
`PlaybackState` and `MediaSessionPlaybackState` are actually quite similar, and we don't want to have to many states to confuse reader and do unnecessary tranform between two states. Therefore, replaceing `PlaybackState` with `MediaSessionPlaybackState`. Differential Revision: https://phabricator.services.mozilla.com/D66342 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c369eaed94
Коммит
252ad6b503
|
@ -9,6 +9,7 @@
|
|||
#include "MediaController.h"
|
||||
#include "MediaControlUtils.h"
|
||||
#include "MediaControlService.h"
|
||||
#include "mozilla/dom/MediaSessionUtils.h"
|
||||
#include "mozilla/Logging.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -44,7 +45,7 @@ void MediaControlKeysHandler::OnKeyPressed(MediaControlKeysEvent aKeyEvent) {
|
|||
controller->Pause();
|
||||
return;
|
||||
case MediaControlKeysEvent::ePlayPause: {
|
||||
if (controller->GetState() == PlaybackState::ePlaying) {
|
||||
if (controller->GetState() == MediaSessionPlaybackState::Playing) {
|
||||
controller->Pause();
|
||||
} else {
|
||||
controller->Play();
|
||||
|
@ -73,7 +74,7 @@ void MediaControlKeysHandler::OnKeyPressed(MediaControlKeysEvent aKeyEvent) {
|
|||
}
|
||||
|
||||
MediaControlKeysEventSource::MediaControlKeysEventSource()
|
||||
: mPlaybackState(PlaybackState::eStopped) {}
|
||||
: mPlaybackState(MediaSessionPlaybackState::None) {}
|
||||
|
||||
void MediaControlKeysEventSource::AddListener(
|
||||
MediaControlKeysEventListener* aListener) {
|
||||
|
@ -98,15 +99,17 @@ void MediaControlKeysEventSource::Close() {
|
|||
mListeners.Clear();
|
||||
}
|
||||
|
||||
void MediaControlKeysEventSource::SetPlaybackState(PlaybackState aState) {
|
||||
void MediaControlKeysEventSource::SetPlaybackState(
|
||||
MediaSessionPlaybackState aState) {
|
||||
if (mPlaybackState == aState) {
|
||||
return;
|
||||
}
|
||||
LOG_SOURCE("SetPlaybackState '%s'", ToPlaybackStateEventStr(aState));
|
||||
LOG_SOURCE("SetPlaybackState '%s'", ToMediaSessionPlaybackStateStr(aState));
|
||||
mPlaybackState = aState;
|
||||
}
|
||||
|
||||
PlaybackState MediaControlKeysEventSource::GetPlaybackState() const {
|
||||
MediaSessionPlaybackState MediaControlKeysEventSource::GetPlaybackState()
|
||||
const {
|
||||
return mPlaybackState;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYSEVENT_H_
|
||||
|
||||
#include "mozilla/dom/MediaMetadata.h"
|
||||
#include "mozilla/dom/MediaSessionBinding.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
|
@ -61,8 +62,6 @@ class MediaControlKeysHandler final : public MediaControlKeysEventListener {
|
|||
virtual ~MediaControlKeysHandler() = default;
|
||||
};
|
||||
|
||||
enum class PlaybackState : uint8_t;
|
||||
|
||||
/**
|
||||
* MediaControlKeysEventSource is an abstract class which is used to implement
|
||||
* transporting media control keys event to all its listeners when media keys
|
||||
|
@ -83,8 +82,8 @@ class MediaControlKeysEventSource {
|
|||
virtual void Close();
|
||||
virtual bool IsOpened() const = 0;
|
||||
|
||||
virtual void SetPlaybackState(PlaybackState aState);
|
||||
virtual PlaybackState GetPlaybackState() const;
|
||||
virtual void SetPlaybackState(MediaSessionPlaybackState aState);
|
||||
virtual MediaSessionPlaybackState GetPlaybackState() const;
|
||||
|
||||
// Override this method if the event source needs to handle the metadata.
|
||||
virtual void SetMediaMetadata(const MediaMetadataBase& aMetadata) {}
|
||||
|
@ -92,7 +91,7 @@ class MediaControlKeysEventSource {
|
|||
protected:
|
||||
virtual ~MediaControlKeysEventSource() = default;
|
||||
nsTArray<RefPtr<MediaControlKeysEventListener>> mListeners;
|
||||
PlaybackState mPlaybackState;
|
||||
MediaSessionPlaybackState mPlaybackState;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -87,7 +87,8 @@ void MediaControlKeysManager::OnKeyPressed(MediaControlKeysEvent aKeyEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
void MediaControlKeysManager::SetPlaybackState(PlaybackState aState) {
|
||||
void MediaControlKeysManager::SetPlaybackState(
|
||||
MediaSessionPlaybackState aState) {
|
||||
if (mEventSource && mEventSource->IsOpened()) {
|
||||
mEventSource->SetPlaybackState(aState);
|
||||
} else {
|
||||
|
@ -97,7 +98,7 @@ void MediaControlKeysManager::SetPlaybackState(PlaybackState aState) {
|
|||
}
|
||||
}
|
||||
|
||||
PlaybackState MediaControlKeysManager::GetPlaybackState() const {
|
||||
MediaSessionPlaybackState MediaControlKeysManager::GetPlaybackState() const {
|
||||
return (mEventSource && mEventSource->IsOpened())
|
||||
? mEventSource->GetPlaybackState()
|
||||
: mPlaybackState;
|
||||
|
|
|
@ -30,8 +30,8 @@ class MediaControlKeysManager final : public MediaControlKeysEventSource,
|
|||
bool Open() override;
|
||||
bool IsOpened() const override;
|
||||
|
||||
void SetPlaybackState(PlaybackState aState) override;
|
||||
PlaybackState GetPlaybackState() const override;
|
||||
void SetPlaybackState(MediaSessionPlaybackState aState) override;
|
||||
MediaSessionPlaybackState GetPlaybackState() const override;
|
||||
|
||||
// MediaControlKeysEventListener methods
|
||||
void OnKeyPressed(MediaControlKeysEvent aKeyEvent) override;
|
||||
|
|
|
@ -187,7 +187,7 @@ void MediaControlService::ControllerManager::Shutdown() {
|
|||
}
|
||||
|
||||
void MediaControlService::ControllerManager::ControllerPlaybackStateChanged(
|
||||
PlaybackState aState) {
|
||||
MediaSessionPlaybackState aState) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mSource->SetPlaybackState(aState);
|
||||
if (StaticPrefs::media_mediacontrol_testingevents_enabled()) {
|
||||
|
@ -215,7 +215,7 @@ void MediaControlService::ControllerManager::UpdateMainController(
|
|||
|
||||
if (!mMainController) {
|
||||
LOG_MAINCONTROLLER("Clear main controller");
|
||||
mSource->SetPlaybackState(PlaybackState::eStopped);
|
||||
mSource->SetPlaybackState(MediaSessionPlaybackState::None);
|
||||
} else {
|
||||
LOG_MAINCONTROLLER("Set controller %" PRId64 " as main controller",
|
||||
mMainController->Id());
|
||||
|
|
|
@ -100,7 +100,7 @@ class MediaControlService final : public nsIObserver {
|
|||
uint64_t GetControllersNum() const;
|
||||
|
||||
// Callback functions for monitoring main controller's status change.
|
||||
void ControllerPlaybackStateChanged(PlaybackState aState);
|
||||
void ControllerPlaybackStateChanged(MediaSessionPlaybackState aState);
|
||||
void ControllerMetadataChanged(const MediaMetadataBase& aMetadata);
|
||||
|
||||
private:
|
||||
|
|
|
@ -65,20 +65,6 @@ ConvertMediaControlKeysTestEventToMediaControlKeysEvent(
|
|||
}
|
||||
}
|
||||
|
||||
inline const char* ToPlaybackStateEventStr(PlaybackState aState) {
|
||||
switch (aState) {
|
||||
case PlaybackState::ePlaying:
|
||||
return "Playing";
|
||||
case PlaybackState::ePaused:
|
||||
return "Paused";
|
||||
case PlaybackState::eStopped:
|
||||
return "Stopped";
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Invalid playback state.");
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
inline const char* ToControlledMediaStateStr(ControlledMediaState aState) {
|
||||
switch (aState) {
|
||||
case ControlledMediaState::eStarted:
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "MediaControlUtils.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
||||
#include "mozilla/dom/MediaSessionUtils.h"
|
||||
|
||||
// avoid redefined macro in unified build
|
||||
#undef LOG
|
||||
|
@ -37,14 +38,14 @@ MediaController::~MediaController() {
|
|||
|
||||
void MediaController::Play() {
|
||||
LOG("Play");
|
||||
SetGuessedPlayState(PlaybackState::ePlaying);
|
||||
SetGuessedPlayState(MediaSessionPlaybackState::Playing);
|
||||
UpdateMediaControlKeysEventToContentMediaIfNeeded(
|
||||
MediaControlKeysEvent::ePlay);
|
||||
}
|
||||
|
||||
void MediaController::Pause() {
|
||||
LOG("Pause");
|
||||
SetGuessedPlayState(PlaybackState::ePaused);
|
||||
SetGuessedPlayState(MediaSessionPlaybackState::Paused);
|
||||
UpdateMediaControlKeysEventToContentMediaIfNeeded(
|
||||
MediaControlKeysEvent::ePause);
|
||||
}
|
||||
|
@ -75,7 +76,7 @@ void MediaController::SeekForward() {
|
|||
|
||||
void MediaController::Stop() {
|
||||
LOG("Stop");
|
||||
SetGuessedPlayState(PlaybackState::eStopped);
|
||||
SetGuessedPlayState(MediaSessionPlaybackState::None);
|
||||
UpdateMediaControlKeysEventToContentMediaIfNeeded(
|
||||
MediaControlKeysEvent::eStop);
|
||||
}
|
||||
|
@ -102,7 +103,7 @@ void MediaController::UpdateMediaControlKeysEventToContentMediaIfNeeded(
|
|||
|
||||
void MediaController::Shutdown() {
|
||||
MOZ_ASSERT(!mShutdown, "Do not call shutdown twice!");
|
||||
SetGuessedPlayState(PlaybackState::eStopped);
|
||||
SetGuessedPlayState(MediaSessionPlaybackState::None);
|
||||
// The media controller would be removed from the service when we receive a
|
||||
// notification from the content process about all controlled media has been
|
||||
// stoppped. However, if controlled media is stopped after detaching
|
||||
|
@ -175,7 +176,7 @@ void MediaController::IncreasePlayingControlledMediaNum() {
|
|||
"The number of playing media should not exceed the number of "
|
||||
"controlled media!");
|
||||
if (mPlayingControlledMediaNum == 1) {
|
||||
SetGuessedPlayState(PlaybackState::ePlaying);
|
||||
SetGuessedPlayState(MediaSessionPlaybackState::Playing);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +187,7 @@ void MediaController::DecreasePlayingControlledMediaNum() {
|
|||
mPlayingControlledMediaNum);
|
||||
MOZ_ASSERT(mPlayingControlledMediaNum >= 0);
|
||||
if (mPlayingControlledMediaNum == 0) {
|
||||
SetGuessedPlayState(PlaybackState::ePaused);
|
||||
SetGuessedPlayState(MediaSessionPlaybackState::Paused);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,21 +213,22 @@ void MediaController::Deactivate() {
|
|||
}
|
||||
}
|
||||
|
||||
void MediaController::SetGuessedPlayState(PlaybackState aState) {
|
||||
void MediaController::SetGuessedPlayState(MediaSessionPlaybackState aState) {
|
||||
if (mShutdown || mGuessedPlaybackState == aState) {
|
||||
return;
|
||||
}
|
||||
LOG("SetGuessedPlayState : '%s'", ToPlaybackStateEventStr(aState));
|
||||
LOG("SetGuessedPlayState : '%s'", ToMediaSessionPlaybackStateStr(aState));
|
||||
mGuessedPlaybackState = aState;
|
||||
mPlaybackStateChangedEvent.Notify(mGuessedPlaybackState);
|
||||
}
|
||||
|
||||
PlaybackState MediaController::GetState() const {
|
||||
MediaSessionPlaybackState MediaController::GetState() const {
|
||||
return mGuessedPlaybackState;
|
||||
}
|
||||
|
||||
bool MediaController::IsAudible() const {
|
||||
return mGuessedPlaybackState == PlaybackState::ePlaying && mAudible;
|
||||
return mGuessedPlaybackState == MediaSessionPlaybackState::Playing &&
|
||||
mAudible;
|
||||
}
|
||||
|
||||
uint64_t MediaController::ControlledMediaNum() const {
|
||||
|
|
|
@ -19,16 +19,6 @@ namespace dom {
|
|||
class BrowsingContext;
|
||||
enum class MediaControlKeysEvent : uint32_t;
|
||||
|
||||
// This is used to indicate current media playback state for media controller.
|
||||
// For those platforms which have virtual control interface, we have to update
|
||||
// the playback state correctly in order to show the correct control icon on the
|
||||
// interface.
|
||||
enum class PlaybackState : uint8_t {
|
||||
ePlaying,
|
||||
ePaused,
|
||||
eStopped,
|
||||
};
|
||||
|
||||
/**
|
||||
* MediaController is a class, which is used to control all media within a tab.
|
||||
* It can only be used in Chrome process and the controlled media are usually
|
||||
|
@ -73,9 +63,9 @@ class MediaController final : public MediaSessionController {
|
|||
|
||||
bool IsAudible() const;
|
||||
uint64_t ControlledMediaNum() const;
|
||||
PlaybackState GetState() const;
|
||||
MediaSessionPlaybackState GetState() const;
|
||||
|
||||
MediaEventSource<PlaybackState>& PlaybackStateChangedEvent() {
|
||||
MediaEventSource<MediaSessionPlaybackState>& PlaybackStateChangedEvent() {
|
||||
return mPlaybackStateChangedEvent;
|
||||
}
|
||||
|
||||
|
@ -97,7 +87,7 @@ class MediaController final : public MediaSessionController {
|
|||
void Activate();
|
||||
void Deactivate();
|
||||
|
||||
void SetGuessedPlayState(PlaybackState aState);
|
||||
void SetGuessedPlayState(MediaSessionPlaybackState aState);
|
||||
|
||||
bool mAudible = false;
|
||||
bool mIsRegisteredToService = false;
|
||||
|
@ -112,8 +102,9 @@ class MediaController final : public MediaSessionController {
|
|||
// We don't support web audio and plugin and not consider audible state of
|
||||
// media.
|
||||
// [1] https://w3c.github.io/mediasession/#guessed-playback-state
|
||||
PlaybackState mGuessedPlaybackState = PlaybackState::eStopped;
|
||||
MediaEventProducer<PlaybackState> mPlaybackStateChangedEvent;
|
||||
MediaSessionPlaybackState mGuessedPlaybackState =
|
||||
MediaSessionPlaybackState::None;
|
||||
MediaEventProducer<MediaSessionPlaybackState> mPlaybackStateChangedEvent;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "MediaControlService.h"
|
||||
#include "MediaController.h"
|
||||
#include "mozilla/dom/MediaSessionBinding.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
|
@ -15,7 +16,7 @@ TEST(MediaController, DefaultValueCheck)
|
|||
RefPtr<MediaController> controller = new MediaController(CONTROLLER_ID);
|
||||
ASSERT_TRUE(controller->ControlledMediaNum() == 0);
|
||||
ASSERT_TRUE(controller->Id() == CONTROLLER_ID);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::eStopped);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::None);
|
||||
ASSERT_TRUE(!controller->IsAudible());
|
||||
}
|
||||
|
||||
|
@ -89,19 +90,19 @@ TEST(MediaController, AlwaysInaudibleIfControllerIsNotPlaying)
|
|||
TEST(MediaController, ChangePlayingStateViaPlayPauseStop)
|
||||
{
|
||||
RefPtr<MediaController> controller = new MediaController(CONTROLLER_ID);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::eStopped);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::None);
|
||||
|
||||
controller->Play();
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Playing);
|
||||
|
||||
controller->Pause();
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePaused);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Paused);
|
||||
|
||||
controller->Play();
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Playing);
|
||||
|
||||
controller->Stop();
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::eStopped);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::None);
|
||||
}
|
||||
|
||||
class FakeControlledMedia final {
|
||||
|
@ -140,20 +141,20 @@ TEST(MediaController, PlayingStateChangeViaControlledMedia)
|
|||
// In order to check playing state after FakeControlledMedia destroyed.
|
||||
{
|
||||
FakeControlledMedia foo(controller);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::eStopped);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::None);
|
||||
|
||||
foo.SetPlaying(true);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Playing);
|
||||
|
||||
foo.SetPlaying(false);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePaused);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Paused);
|
||||
|
||||
foo.SetPlaying(true);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Playing);
|
||||
}
|
||||
|
||||
// FakeControlledMedia has been destroyed, no playing media exists.
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePaused);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Paused);
|
||||
}
|
||||
|
||||
TEST(MediaController, ControllerShouldRemainPlayingIfAnyPlayingMediaExists)
|
||||
|
@ -162,27 +163,27 @@ TEST(MediaController, ControllerShouldRemainPlayingIfAnyPlayingMediaExists)
|
|||
|
||||
{
|
||||
FakeControlledMedia foo(controller);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::eStopped);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::None);
|
||||
|
||||
foo.SetPlaying(true);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Playing);
|
||||
|
||||
// foo is playing, so controller is in `playing` state.
|
||||
FakeControlledMedia bar(controller);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Playing);
|
||||
|
||||
bar.SetPlaying(true);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Playing);
|
||||
|
||||
// Although we paused bar, but foo is still playing, so the controller would
|
||||
// still be in `playing`.
|
||||
bar.SetPlaying(false);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Playing);
|
||||
|
||||
foo.SetPlaying(false);
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePaused);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Paused);
|
||||
}
|
||||
|
||||
// both foo and bar have been destroyed, no playing media exists.
|
||||
ASSERT_TRUE(controller->GetState() == PlaybackState::ePaused);
|
||||
ASSERT_TRUE(controller->GetState() == MediaSessionPlaybackState::Paused);
|
||||
}
|
||||
|
|
|
@ -38,14 +38,14 @@ TEST(MediaControlKeysEvent, SetSourcePlaybackState)
|
|||
{
|
||||
RefPtr<MediaControlKeysEventSource> source =
|
||||
new MediaControlKeysEventSourceTestImpl();
|
||||
ASSERT_TRUE(source->GetPlaybackState() == PlaybackState::eStopped);
|
||||
ASSERT_TRUE(source->GetPlaybackState() == MediaSessionPlaybackState::None);
|
||||
|
||||
source->SetPlaybackState(PlaybackState::ePlaying);
|
||||
ASSERT_TRUE(source->GetPlaybackState() == PlaybackState::ePlaying);
|
||||
source->SetPlaybackState(MediaSessionPlaybackState::Playing);
|
||||
ASSERT_TRUE(source->GetPlaybackState() == MediaSessionPlaybackState::Playing);
|
||||
|
||||
source->SetPlaybackState(PlaybackState::ePaused);
|
||||
ASSERT_TRUE(source->GetPlaybackState() == PlaybackState::ePaused);
|
||||
source->SetPlaybackState(MediaSessionPlaybackState::Paused);
|
||||
ASSERT_TRUE(source->GetPlaybackState() == MediaSessionPlaybackState::Paused);
|
||||
|
||||
source->SetPlaybackState(PlaybackState::eStopped);
|
||||
ASSERT_TRUE(source->GetPlaybackState() == PlaybackState::eStopped);
|
||||
source->SetPlaybackState(MediaSessionPlaybackState::None);
|
||||
ASSERT_TRUE(source->GetPlaybackState() == MediaSessionPlaybackState::None);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class MediaHardwareKeysEventSourceMacMediaCenter final
|
|||
bool Open() override;
|
||||
void Close() override;
|
||||
bool IsOpened() const override;
|
||||
void SetPlaybackState(dom::PlaybackState aState) override;
|
||||
void SetPlaybackState(dom::MediaSessionPlaybackState aState) override;
|
||||
|
||||
private:
|
||||
~MediaHardwareKeysEventSourceMacMediaCenter();
|
||||
|
|
|
@ -150,14 +150,15 @@ void MediaHardwareKeysEventSourceMacMediaCenter::HandleEvent(MediaControlKeysEve
|
|||
}
|
||||
}
|
||||
|
||||
void MediaHardwareKeysEventSourceMacMediaCenter::SetPlaybackState(PlaybackState aState) {
|
||||
void MediaHardwareKeysEventSourceMacMediaCenter::SetPlaybackState(
|
||||
MediaSessionPlaybackState aState) {
|
||||
MPNowPlayingInfoCenter* center =
|
||||
(MPNowPlayingInfoCenter*)[mpNowPlayingInfoCenterClass defaultCenter];
|
||||
if (aState == PlaybackState::ePlaying) {
|
||||
if (aState == MediaSessionPlaybackState::Playing) {
|
||||
center.playbackState = MPNowPlayingPlaybackStatePlaying;
|
||||
} else if (aState == PlaybackState::ePaused) {
|
||||
} else if (aState == MediaSessionPlaybackState::Paused) {
|
||||
center.playbackState = MPNowPlayingPlaybackStatePaused;
|
||||
} else if (aState == PlaybackState::eStopped) {
|
||||
} else if (aState == MediaSessionPlaybackState::None) {
|
||||
center.playbackState = MPNowPlayingPlaybackStateStopped;
|
||||
}
|
||||
MediaControlKeysEventSource::SetPlaybackState(aState);
|
||||
|
|
|
@ -563,7 +563,8 @@ bool MPRISServiceHandler::SetRate(double aRate) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void MPRISServiceHandler::SetPlaybackState(dom::PlaybackState aState) {
|
||||
void MPRISServiceHandler::SetPlaybackState(
|
||||
dom::MediaSessionPlaybackState aState) {
|
||||
LOG("SetPlaybackState");
|
||||
if (mPlaybackState == aState) {
|
||||
return;
|
||||
|
@ -593,11 +594,11 @@ void MPRISServiceHandler::SetPlaybackState(dom::PlaybackState aState) {
|
|||
|
||||
GVariant* MPRISServiceHandler::GetPlaybackStatus() const {
|
||||
switch (GetPlaybackState()) {
|
||||
case dom::PlaybackState::ePlaying:
|
||||
case dom::MediaSessionPlaybackState::Playing:
|
||||
return g_variant_new_string("Playing");
|
||||
case dom::PlaybackState::ePaused:
|
||||
case dom::MediaSessionPlaybackState::Paused:
|
||||
return g_variant_new_string("Paused");
|
||||
case dom::PlaybackState::eStopped:
|
||||
case dom::MediaSessionPlaybackState::None:
|
||||
return g_variant_new_string("Stopped");
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Invalid Playback State");
|
||||
|
|
|
@ -61,7 +61,7 @@ class MPRISServiceHandler final : public dom::MediaControlKeysEventSource {
|
|||
bool IsOpened() const override;
|
||||
|
||||
// From the EventSource.
|
||||
void SetPlaybackState(dom::PlaybackState aState) override;
|
||||
void SetPlaybackState(dom::MediaSessionPlaybackState aState) override;
|
||||
|
||||
// GetPlaybackState returns dom::PlaybackState. GetPlaybackStatus returns this
|
||||
// state converted into d-bus variants.
|
||||
|
|
|
@ -210,7 +210,7 @@ bool WindowsSMTCProvider::Open() {
|
|||
if (mInitialized) {
|
||||
bool controlAttribs =
|
||||
SetControlAttributes(SMTCControlAttributes::EnableAll());
|
||||
SetPlaybackState(mozilla::dom::PlaybackState::eStopped);
|
||||
SetPlaybackState(mozilla::dom::MediaSessionPlaybackState::None);
|
||||
bool metadata = SetMusicMetadata(Nothing(), L"Mozilla Firefox", Nothing());
|
||||
bool update = Update();
|
||||
LOG("Initialization - Enabling All Control Attributes: %s, Setting "
|
||||
|
@ -230,7 +230,7 @@ bool WindowsSMTCProvider::IsOpened() const { return mInitialized; }
|
|||
void WindowsSMTCProvider::Close() {
|
||||
MediaControlKeysEventSource::Close();
|
||||
if (mInitialized) { // Prevent calling Set methods when init failed
|
||||
SetPlaybackState(mozilla::dom::PlaybackState::eStopped);
|
||||
SetPlaybackState(mozilla::dom::MediaSessionPlaybackState::None);
|
||||
SetControlAttributes(SMTCControlAttributes::DisableAll());
|
||||
mInitialized = false;
|
||||
}
|
||||
|
@ -238,7 +238,8 @@ void WindowsSMTCProvider::Close() {
|
|||
UnregisterEvents();
|
||||
}
|
||||
|
||||
void WindowsSMTCProvider::SetPlaybackState(mozilla::dom::PlaybackState aState) {
|
||||
void WindowsSMTCProvider::SetPlaybackState(
|
||||
mozilla::dom::MediaSessionPlaybackState aState) {
|
||||
MOZ_ASSERT(mInitialized);
|
||||
MediaControlKeysEventSource::SetPlaybackState(aState);
|
||||
|
||||
|
@ -247,15 +248,15 @@ void WindowsSMTCProvider::SetPlaybackState(mozilla::dom::PlaybackState aState) {
|
|||
// Note: we can't return the status of put_PlaybackStatus, but we can at least
|
||||
// assert it.
|
||||
switch (aState) {
|
||||
case mozilla::dom::PlaybackState::ePaused:
|
||||
case mozilla::dom::MediaSessionPlaybackState::Paused:
|
||||
hr = mControls->put_PlaybackStatus(
|
||||
ABI::Windows::Media::MediaPlaybackStatus_Paused);
|
||||
break;
|
||||
case mozilla::dom::PlaybackState::ePlaying:
|
||||
case mozilla::dom::MediaSessionPlaybackState::Playing:
|
||||
hr = mControls->put_PlaybackStatus(
|
||||
ABI::Windows::Media::MediaPlaybackStatus_Playing);
|
||||
break;
|
||||
case mozilla::dom::PlaybackState::eStopped:
|
||||
case mozilla::dom::MediaSessionPlaybackState::None:
|
||||
hr = mControls->put_PlaybackStatus(
|
||||
ABI::Windows::Media::MediaPlaybackStatus_Stopped);
|
||||
break;
|
||||
|
|
|
@ -50,7 +50,8 @@ class WindowsSMTCProvider final
|
|||
// Buttons)
|
||||
bool SetControlAttributes(SMTCControlAttributes aAttributes);
|
||||
|
||||
void SetPlaybackState(mozilla::dom::PlaybackState aState) override;
|
||||
void SetPlaybackState(
|
||||
mozilla::dom::MediaSessionPlaybackState aState) override;
|
||||
|
||||
// Sets the Thumbnail for the currently playing media to the given URL.
|
||||
// Note: This method does not call update(), you need to do that manually.
|
||||
|
|
Загрузка…
Ссылка в новой задаче