AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Protected Member Functions | Protected Attributes | List of all members
alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler Class Referenceabstract

#include <ExternalMediaAdapterHandler.h>

Inheritance diagram for alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler:
Collaboration graph
[legend]

Public Member Functions

ExternalMediaAdapterHandler functions
std::vector< acsdkExternalMediaPlayerInterfaces::PlayerInfoupdatePlayerInfo (const std::vector< acsdkExternalMediaPlayerInterfaces::PlayerInfo > &playerList) override
 
bool login (const std::string &localPlayerId, const std::string &accessToken, const std::string &userName, bool forceLogin, std::chrono::milliseconds tokenRefreshInterval) override
 
bool logout (const std::string &localPlayerId) override
 
bool play (const PlayParams &params) override
 
bool playControl (const std::string &localPlayerId, acsdkExternalMediaPlayerInterfaces::RequestType requestType, const std::string &playbackTarget) override
 
bool seek (const std::string &localPlayerId, std::chrono::milliseconds offset) override
 
bool adjustSeek (const std::string &localPlayerId, std::chrono::milliseconds deltaOffset) override
 
acsdkExternalMediaPlayerInterfaces::AdapterState getAdapterState (const std::string &localPlayerId) override
 
std::vector< acsdkExternalMediaPlayerInterfaces::AdapterStategetAdapterStates () override
 
std::chrono::milliseconds getOffset (const std::string &localPlayerId) override
 
void setExternalMediaPlayer (const std::shared_ptr< acsdkExternalMediaPlayerInterfaces::ExternalMediaPlayerInterface > externalMediaPlayer) override
 
SpeakerManagerObserverInterface Functions
void onSpeakerSettingsChanged (const Source &source, const avsCommon::sdkInterfaces::ChannelVolumeInterface::Type &type, const avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings &settings) override
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerObserverInterface
virtual ~SpeakerManagerObserverInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface
 ExternalMediaAdapterHandlerInterface (const std::string &name)
 
virtual ~ExternalMediaAdapterHandlerInterface ()=default
 
virtual void setExternalMediaPlayer (const std::shared_ptr< ExternalMediaPlayerInterface > externalMediaPlayer)=0
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::RequiresShutdown
 RequiresShutdown (const std::string &name)
 
virtual ~RequiresShutdown ()
 Destructor. More...
 
const std::string & name () const
 
void shutdown ()
 
bool isShutdown () const
 

Protected Member Functions

 ExternalMediaAdapterHandler (const std::string &name)
 
bool initializeAdapterHandler (std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface > speakerManager)
 
bool validatePlayer (const std::string &localPlayerId, bool checkAuthorized=true)
 
std::string createExternalMediaPlayerEvent (const std::string &localPlayerId, const std::string &event, bool includePlaybackSessionId=false, std::function< void(rapidjson::Value::Object &, rapidjson::Value::AllocatorType &)> createPayload=[](rapidjson::Value::Object &v, rapidjson::Value::AllocatorType &a) {})
 
void reportDiscoveredPlayers (const std::vector< acsdkExternalMediaPlayerInterfaces::DiscoveredPlayerInfo > &discoveredPlayers)
 
bool removeDiscoveredPlayer (const std::string &localPlayerId)
 
virtual void doShutdown () override
 alexaClientSDK::avsCommon::utils::RequiresShutdown More...
 
virtual bool handleAuthorization (const AuthorizedPlayerInfo &authorizedPlayer)=0
 
virtual bool handleLogin (const std::string &localPlayerId, const std::string &accessToken, const std::string &userName, bool forceLogin, std::chrono::milliseconds tokenRefreshInterval)=0
 
virtual bool handleLogout (const std::string &localPlayerId)=0
 
virtual bool handlePlay (const ExternalMediaAdapterHandlerInterface::PlayParams &params)=0
 
virtual bool handlePlayControl (const std::string &localPlayerId, acsdkExternalMediaPlayerInterfaces::RequestType requestType, const std::string &playbackTarget)=0
 
virtual bool handleSeek (const std::string &localPlayerId, std::chrono::milliseconds offset)=0
 
virtual bool handleAdjustSeek (const std::string &localPlayerId, std::chrono::milliseconds deltaOffset)=0
 
virtual bool handleGetAdapterState (const std::string &localPlayerId, acsdkExternalMediaPlayerInterfaces::AdapterState &state)=0
 
virtual std::chrono::milliseconds handleGetOffset (const std::string &localPlayerId)
 
virtual void handleSetVolume (int8_t volume)=0
 
virtual void handleSetMute (bool mute)=0
 

Protected Attributes

std::weak_ptr< acsdkExternalMediaPlayerInterfaces::ExternalMediaPlayerInterfacem_externalMediaPlayer
 The pointer to the external media player object. More...
 

Additional Inherited Members

- Public Types inherited from alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerObserverInterface
enum  Source { Source::DIRECTIVE, Source::LOCAL_API, Source::EXTERNAL_CLIENT }
 Indicates whether the source of the call is from an AVS Directive or through a Local API call. More...
 

Detailed Description

The abstract ExternalMediaAdapterHandler class implements the ExternalMediaAdapterHandlerInterface and provides a base for users who wish to add custom External Media Player adapter handlers

Constructor & Destructor Documentation

◆ ExternalMediaAdapterHandler()

alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::ExternalMediaAdapterHandler ( const std::string &  name)
protected

Constructor

Parameters
nameThe name for this adapter handler
externalMediaPlayerThe external media player interface

Member Function Documentation

◆ adjustSeek()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::adjustSeek ( const std::string &  localPlayerId,
std::chrono::milliseconds  deltaOffset 
)
overridevirtual

Method to seek to an offset from the current position.

Parameters
localPlayerIdThe localPlayerId that this seek control is targeted at
deltaOffsetThe offset to seek to relative to the current offset.
Returns
True if the call was handled

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ createExternalMediaPlayerEvent()

std::string alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::createExternalMediaPlayerEvent ( const std::string &  localPlayerId,
const std::string &  event,
bool  includePlaybackSessionId = false,
std::function< void(rapidjson::Value::Object &, rapidjson::Value::AllocatorType &)>  createPayload = [](rapidjson::Value::Object &v, rapidjson::Value::AllocatorType &a) {} 
)
protected

Helper function to create an external media player event

Parameters
localPlayerIdThe local player ID
eventThe event to send
includePlaybackSessionIdWhether the playback session id should be included
createPayloadOptional function which can be used to customize the payload
Returns

◆ doShutdown()

virtual void alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::doShutdown ( )
overrideprotectedvirtual

◆ getAdapterState()

acsdkExternalMediaPlayerInterfaces::AdapterState alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::getAdapterState ( const std::string &  localPlayerId)
overridevirtual

Method to fetch the state(session state and playback state) of an adapter.

Parameters
localPlayerIdThe player ID for which the state is being requested
Returns
The adapter state

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ getAdapterStates()

std::vector<acsdkExternalMediaPlayerInterfaces::AdapterState> alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::getAdapterStates ( )
overridevirtual

Method to fetch the state for all adapters handled by this adapter handler

Returns
Vector of all adapter states

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ getOffset()

std::chrono::milliseconds alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::getOffset ( const std::string &  localPlayerId)
overridevirtual

This function retrieves the offset of the current track the adapter is handling.

Parameters
localPlayerIdThe player ID for which the offset is being requested
Returns
The offset in milliseconds

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ handleAdjustSeek()

virtual bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleAdjustSeek ( const std::string &  localPlayerId,
std::chrono::milliseconds  deltaOffset 
)
protectedpure virtual

Method to seek to an offset from the current position.

Parameters
localPlayerIdThe player ID to control.
deltaOffsetThe offset to seek to relative to the current offset.
Returns
true if successful

◆ handleAuthorization()

virtual bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleAuthorization ( const AuthorizedPlayerInfo authorizedPlayer)
protectedpure virtual

The following functions are to be overriden by implementors Called when the list of authorized discovered players is received from AVS

Parameters
authorizedPlayerThe player and the authorization status
Returns
true if authorization successful

◆ handleGetAdapterState()

virtual bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleGetAdapterState ( const std::string &  localPlayerId,
acsdkExternalMediaPlayerInterfaces::AdapterState state 
)
protectedpure virtual

Method to fetch the state of an adapter.

Parameters
localPlayerIdThe local player ID for which the state is requested
statereference to the AdapterState object which should be updated with the current state for the adapter
Returns
true if successful

◆ handleGetOffset()

virtual std::chrono::milliseconds alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleGetOffset ( const std::string &  localPlayerId)
protectedvirtual

This function retrieves the offset of the current track the adapter is handling.

Parameters
localPlayerIdThe local player Id for which offset is being requested
Returns
This returns the offset in milliseconds.

◆ handleLogin()

virtual bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleLogin ( const std::string &  localPlayerId,
const std::string &  accessToken,
const std::string &  userName,
bool  forceLogin,
std::chrono::milliseconds  tokenRefreshInterval 
)
protectedpure virtual

The handler should login the given player using the provided details

Parameters
localPlayerIdThe player ID to be logged in
accessTokenThe access context of the user identifier.
userNameThe userName of the user logging in.
forceLoginbool which signifies if the adapter has to a force a login or merely cache the access token.
tokenRefreshIntervalThe duration in milliseconds for which the accessToken is valid.
Returns
true if login was successful

◆ handleLogout()

virtual bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleLogout ( const std::string &  localPlayerId)
protectedpure virtual

The handler should log out the given player

Parameters
localPlayerIdThe player ID to be logged out
Returns
true if logout was successful

◆ handlePlay()

virtual bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handlePlay ( const ExternalMediaAdapterHandlerInterface::PlayParams &  params)
protectedpure virtual

The handler should play the given player

Parameters
paramsPlay parameters to play with
Returns
true if successful

◆ handlePlayControl()

virtual bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handlePlayControl ( const std::string &  localPlayerId,
acsdkExternalMediaPlayerInterfaces::RequestType  requestType,
const std::string &  playbackTarget 
)
protectedpure virtual

Method to initiate the different types of play control like PLAY/PAUSE/RESUME/NEXT/...

Parameters
localPlayerIdThe player ID to control
requestTypeThe type of REQUEST. Will always be PLAY/PAUSE/RESUME/NEXT...
playbackTargetTarget for handling play control
Returns

◆ handleSeek()

virtual bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleSeek ( const std::string &  localPlayerId,
std::chrono::milliseconds  offset 
)
protectedpure virtual

Method to seek to the given offset.

Parameters
localPlayerIdThe player ID to control
offsetThe offset to seek to.
Returns
true if successful

◆ handleSetMute()

virtual void alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleSetMute ( bool  mute)
protectedpure virtual

Called when the SpeakerManager reports a change to the mute state

Parameters
volumeThe new mute state

◆ handleSetVolume()

virtual void alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::handleSetVolume ( int8_t  volume)
protectedpure virtual

Called when the SpeakerManager reports a volume change

Parameters
volumeThe new volume

◆ initializeAdapterHandler()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::initializeAdapterHandler ( std::shared_ptr< alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface speakerManager)
protected

Initialize this ExternalMediaAdapterHandler

Parameters
speakerManagerThe speaker manager object
Returns
true if successful

◆ login()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::login ( const std::string &  localPlayerId,
const std::string &  accessToken,
const std::string &  userName,
bool  forceLogin,
std::chrono::milliseconds  tokenRefreshInterval 
)
overridevirtual

Method to allow a user to login to a third party music provider.

Parameters
localPlayerIdThe local player ID being logged in
accessTokenThe access context of the user identifier.
userNameThe userName of the user logging in.
forceLoginbool which signifies if the adapter has to a force a login or merely cache the access token.
tokenRefreshIntervalThe duration in milliseconds for which the accessToken is valid.
Returns
True if the call was handled

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ logout()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::logout ( const std::string &  localPlayerId)
overridevirtual

Method that handles logging out a user from a third party library/cloud.

Parameters
localPlayerIdThe local player ID being logged out
Returns
True if the call was handled

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ onSpeakerSettingsChanged()

void alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::onSpeakerSettingsChanged ( const Source source,
const avsCommon::sdkInterfaces::ChannelVolumeInterface::Type type,
const avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings settings 
)
overridevirtual

A callback for when the SpeakerInterface::SpeakerSettings successfully changes.

Parameters
source.This indicates the origin of the call.
type.This indicates the type of ChannelVolumeInterface that was modified.
settings.This indicates the current settings after the change.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerObserverInterface.

◆ play()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::play ( const PlayParams params)
overridevirtual

Method to allow a user to initiate play from a third party music service provider based on a play context.

Parameters
paramsPlay parameters required for playback
Returns
True if the call was handled

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ playControl()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::playControl ( const std::string &  localPlayerId,
acsdkExternalMediaPlayerInterfaces::RequestType  requestType,
const std::string &  playbackTarget 
)
overridevirtual

Method to initiate the different types of play control like PLAY/PAUSE/RESUME/NEXT/...

Parameters
localPlayerIdThe localPlayerId that this play control is targeted at
requestTypeThe type of REQUEST. Will always be PLAY/PAUSE/RESUME/NEXT...
playbackTargetPlayback target to handle play control with
Returns
True if the call was handled

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ removeDiscoveredPlayer()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::removeDiscoveredPlayer ( const std::string &  localPlayerId)
protected

Removes a player

Parameters
localPlayerId
Returns
if the player was removed

◆ reportDiscoveredPlayers()

void alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::reportDiscoveredPlayers ( const std::vector< acsdkExternalMediaPlayerInterfaces::DiscoveredPlayerInfo > &  discoveredPlayers)
protected

Add a newly discovered player

Parameters
discoveredPlayersThe details for the player

◆ seek()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::seek ( const std::string &  localPlayerId,
std::chrono::milliseconds  offset 
)
overridevirtual

Method to seek to the given offset.

Parameters
localPlayerIdThe localPlayerId that this seek control is targeted at
offsetThe offset to seek to.
Returns
True if the call was handled

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ setExternalMediaPlayer()

void alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::setExternalMediaPlayer ( const std::shared_ptr< acsdkExternalMediaPlayerInterfaces::ExternalMediaPlayerInterface externalMediaPlayer)
override

◆ updatePlayerInfo()

std::vector<acsdkExternalMediaPlayerInterfaces::PlayerInfo> alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::updatePlayerInfo ( const std::vector< acsdkExternalMediaPlayerInterfaces::PlayerInfo > &  playerList)
overridevirtual

Method to notify the handler that the cloud status of given players has been updated. This method also provides the playerId and skillToken as identified by the cloud. The cloud support for a player may be revoked at any time. The state of any players not included on the playerList should be assumed to be unchanged.

Parameters
playerListThe list of players whose state has changed
Returns
The list of players which were processed by this handler

Implements alexaClientSDK::acsdkExternalMediaPlayerInterfaces::ExternalMediaAdapterHandlerInterface.

◆ validatePlayer()

bool alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::validatePlayer ( const std::string &  localPlayerId,
bool  checkAuthorized = true 
)
protected

Validates if a player exists, and whether it is authorized

Parameters
localPlayerIdThe local player ID
checkAuthorizedCheck if the player should be authorized
Returns
true if the validation check passes

Member Data Documentation

◆ m_externalMediaPlayer

std::weak_ptr<acsdkExternalMediaPlayerInterfaces::ExternalMediaPlayerInterface> alexaClientSDK::acsdkExternalMediaPlayer::ExternalMediaAdapterHandler::m_externalMediaPlayer
protected

The pointer to the external media player object.


The documentation for this class was generated from the following file:

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0