NowPlayingManager.cpp [plain text]
#include "config.h"
#include "NowPlayingManager.h"
#if PLATFORM(COCOA)
#include "MediaSessionManagerCocoa.h"
#endif
namespace WebCore {
NowPlayingManager::NowPlayingManager() = default;
NowPlayingManager::~NowPlayingManager() = default;
void NowPlayingManager::didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType type, const PlatformMediaSession::RemoteCommandArgument* argument)
{
ASSERT(m_nowPlayingInfo);
if (!m_client)
return;
Optional<double> value;
if (argument)
value = argument->asDouble;
m_client->didReceiveRemoteControlCommand(type, value);
}
bool NowPlayingManager::supportsSeeking() const
{
return m_nowPlayingInfo && m_nowPlayingInfo->supportsSeeking;
}
void NowPlayingManager::clearNowPlayingInfoClient(Client& client)
{
if (m_client.get() != &client)
return;
m_remoteCommandListener = nullptr;
m_client.clear();
m_nowPlayingInfo = { };
#if PLATFORM(COCOA)
MediaSessionManagerCocoa::clearNowPlayingInfo();
#endif
}
void NowPlayingManager::setNowPlayingInfo(Client& client, NowPlayingInfo&& nowPlayingInfo)
{
if (!m_remoteCommandListener)
m_remoteCommandListener = RemoteCommandListener::create(*this);
m_client = makeWeakPtr(client);
m_nowPlayingInfo = WTFMove(nowPlayingInfo);
#if PLATFORM(COCOA)
MediaSessionManagerCocoa::setNowPlayingInfo(!m_nowPlayingInfo, *m_nowPlayingInfo);
#endif
}
}