AlexaClientSDK  1.18.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Types | Public Member Functions | Static Public Attributes | List of all members
alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface Class Referenceabstract

#include <MediaPlayerInterface.h>

Inheritance diagram for alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface:
Inheritance graph
[legend]

Public Types

using SourceId = uint64_t
 A type that identifies which source is currently being operated on. This must be unique across all instances. More...
 

Public Member Functions

virtual ~MediaPlayerInterface ()=default
 
virtual SourceId setSource (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, const avsCommon::utils::AudioFormat *format=nullptr, const SourceConfig &config=emptySourceConfig())=0
 
virtual SourceId setSource (const std::string &url, std::chrono::milliseconds offset=std::chrono::milliseconds::zero(), const SourceConfig &config=emptySourceConfig(), bool repeat=false)=0
 
virtual SourceId setSource (std::shared_ptr< std::istream > stream, bool repeat=false, const SourceConfig &config=emptySourceConfig())=0
 
virtual bool play (SourceId id)=0
 
virtual bool stop (SourceId id)=0
 
virtual bool pause (SourceId id)=0
 
virtual bool resume (SourceId id)=0
 
virtual std::chrono::milliseconds getOffset (SourceId id)=0
 
virtual uint64_t getNumBytesBuffered ()=0
 
virtual utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerStategetMediaPlayerState (SourceId id)=0
 
virtual void addObserver (std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > playerObserver)=0
 
virtual void removeObserver (std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > playerObserver)=0
 
virtual utils::Optional< PlaybackAttributesgetPlaybackAttributes ()
 
virtual std::vector< PlaybackReportgetPlaybackReports ()
 

Static Public Attributes

static const SourceId ERROR = 0
 An SourceId used to represent an error from calls to setSource(). More...
 

Detailed Description

A MediaPlayerInterface allows for sourcing, playback control, navigation, and querying the state of media content. A MediaPlayerInterface implementation must only handle one source at a time.

Each playback controlling API call (i.e. play(), pause(), stop(), resume()) that succeeds will also result in a callback to the observer. To see how to tell when a method succeeded, please refer to the documentation of each method.

An implementation can call onPlaybackError() at any time. If an onPlaybackError() callback occurs while a plaback controlling API call is waiting for a callback, the original callback must not be made, and the implementation should revert to a stopped state. Any subsequent operations after an onPlaybackError() callback must be preceded by a new setSource() call.

Implementations must make a call to onPlaybackStopped() with the previous SourceId when a new source is set if the previous source was in a non-stopped state.

note A MediaPlayerInterface implementation must be able to support the various audio formats listed at: https://developer.amazon.com/docs/alexa/alexa-voice-service/recommended-media-support.html.

Member Typedef Documentation

◆ SourceId

A type that identifies which source is currently being operated on. This must be unique across all instances.

Constructor & Destructor Documentation

◆ ~MediaPlayerInterface()

virtual alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::~MediaPlayerInterface ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addObserver()

virtual void alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::addObserver ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface playerObserver)
pure virtual

Adds an observer to be notified when playback state changes.

Parameters
playerObserverThe observer to send the notifications to.

Implemented in alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, alexaClientSDK::integration::test::TestMediaPlayer, and alexaClientSDK::mediaPlayer::MediaPlayer.

◆ getMediaPlayerState()

virtual utils::Optional<avsCommon::utils::mediaPlayer::MediaPlayerState> alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::getMediaPlayerState ( SourceId  id)
pure virtual

Returns the current state of the media player source, including the id and offset.

Parameters
idThe unique id of the source for the desired state.
Returns
Optional state including the offset. A blank Optional is returned if retrieving this information fails.

Implemented in alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.

◆ getNumBytesBuffered()

virtual uint64_t alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::getNumBytesBuffered ( )
pure virtual

Returns the number of bytes queued up in the media player buffers.

Returns
The number of bytes currently queued in this MediaPlayer's buffer.

Implemented in alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.

◆ getOffset()

virtual std::chrono::milliseconds alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::getOffset ( SourceId  id)
pure virtual

Returns the offset, in milliseconds, of the media source.

Parameters
idThe unique id of the source on which to operate.
Returns
If the specified source is playing, the offset in milliseconds that the source has been playing will be returned. If the specified source is not playing, the last offset it played will be returned.
Deprecated:
Use getMediaPlayerState instead, which contains the offset

Implemented in alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.

◆ getPlaybackAttributes()

utils::Optional< PlaybackAttributes > alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::getPlaybackAttributes ( )
inlinevirtual

Get PlaybackAttributes for the current stream being played. This method only needs to be implemented if your mediaplayer supports Premium Audio.

Returns
playbackAttributes The playback attributes for the current stream if premium audio is supported and it has an active source; otherwise, an empty object.

◆ getPlaybackReports()

std::vector< PlaybackReport > alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::getPlaybackReports ( )
inlinevirtual

Get list of PlaybackReports for current track. This method only needs to be implemented if your mediaplayer supports Premium Audio.

Returns
The list of PlaybackReport for current track if premium audio is supported and it has an active source; otherwise, an empty list.

◆ pause()

virtual bool alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::pause ( SourceId  id)
pure virtual

Pauses playing audio specified by the setSource() call.

The source must be set before issuing pause(). If pause() is called

If the id does not match the id of the active source, then false will be returned. If the pause() succeeded, true will be returned. When true is returned, a callback will be made to either MediaPlayerObserverInterface::onPlaybackPaused() or to MediaPlayerObserverInterface::onPlaybackError().

Parameters
idThe unique id of the source on which to operate.
Returns
true if the call succeeded, in which case a callback will be made, or false otherwise.

Implemented in alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.

◆ play()

virtual bool alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::play ( SourceId  id)
pure virtual

Starts playing audio specified by the setSource() call.

The source must be set before issuing play().

If play() is called

  • without making a setSource(), false will be returned.
  • when audio is already playing, false will be returned.
  • after a play() call has already been made but no callback or return code has been issued yet, false will be returned.

If the id does not match the id of the active source, then false will be returned. If the play() succeeded, true will be returned. When true is returned, a callback will be made to either MediaPlayerObserverInterface::onPlaybackStarted() or to MediaPlayerObserverInterface::onPlaybackError().

Parameters
idThe unique id of the source on which to operate.
Returns
true if the call succeeded, in which case a callback will be made, or false otherwise.

Implemented in alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::capabilityAgents::alerts::renderer::test::TestMediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.

◆ removeObserver()

virtual void alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::removeObserver ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface playerObserver)
pure virtual

Removes an observer to be notified when playback state changes.

Parameters
playerObserverThe observer to be removed

Implemented in alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, alexaClientSDK::integration::test::TestMediaPlayer, and alexaClientSDK::mediaPlayer::MediaPlayer.

◆ resume()

virtual bool alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::resume ( SourceId  id)
pure virtual

Resumes playing the paused audio specified by the setSource() call.

The source must be set before issuing resume(). If resume() is called

  • without making a setSource(), false will be returned.
  • when audio is already playing, false will be returned.
  • when audio is not paused, false will be returned.
  • after a resume() call has already been made but no callback or return code has been issued yet, false will be returned.

If the id does not match the id of the active source, then false will be returned. If the resume() succeeded, true will be returned. When true is returned, a callback will be made to either MediaPlayerObserverInterface::onPlaybackResumed() or to MediaPlayerObserverInterface::onPlaybackError().

Parameters
idThe unique id of the source on which to operate.
Returns
true if the call succeeded, in which case a callback will be made, or false otherwise.

Implemented in alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.

◆ setSource() [1/3]

virtual SourceId alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::setSource ( const std::string &  url,
std::chrono::milliseconds  offset = std::chrono::milliseconds::zero(),
const SourceConfig config = emptySourceConfig(),
bool  repeat = false 
)
pure virtual

Set a url source to play. The source should be set before making calls to any of the playback control APIs. If any source was set prior to this call, that source will be discarded.

Note
A MediaPlayerInterface implementation must handle only one source at a time. An implementation must call MediaPlayerObserverInterface::onPlaybackStopped() with the previous source's id if there was a source set. Also, an implementation must call MediaPlayerObserverInterface::onBufferingComplete() when this source has been fully buffered
Parameters
urlThe url to set as the source.
offsetAn optional offset parameter to start playing from when a play() call is made.
configMedia configuration of source.
repeatAn optional parameter to play the url source in a loop.
Returns
The SourceId that represents the source being handled as a result of this call. ERROR will be returned if the source failed to be set. Must be unique across all instances.

Implemented in alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer, alexaClientSDK::capabilityAgents::alerts::renderer::test::TestMediaPlayer, alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::integration::test::TestMediaPlayer, and alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer.

◆ setSource() [2/3]

virtual SourceId alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::setSource ( std::shared_ptr< avsCommon::avs::attachment::AttachmentReader attachmentReader,
const avsCommon::utils::AudioFormat format = nullptr,
const SourceConfig config = emptySourceConfig() 
)
pure virtual

Set an AttachmentReader source to play. The source should be set before making calls to any of the playback control APIs. If any source was set prior to this call, that source will be discarded.

Note
A MediaPlayerInterface implementation must handle only one source at a time. An implementation must call MediaPlayerObserverInterface::onPlaybackStopped() with the previous source's id if there was a source set. Also, an implementation must call MediaPlayerObserverInterface::onBufferingComplete() when this source has been fully buffered
Parameters
attachmentReaderObject with which to read an incoming audio attachment.
formatThe audioFormat to be used to interpret raw audio data.
configMedia configuration of source.
Returns
The SourceId that represents the source being handled as a result of this call. ERROR will be returned if the source failed to be set. Must be unique across all instances.

Implemented in alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.

◆ setSource() [3/3]

virtual SourceId alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::setSource ( std::shared_ptr< std::istream >  stream,
bool  repeat = false,
const SourceConfig config = emptySourceConfig() 
)
pure virtual

Set an istream source to play. The source should be set before making calls to any of the playback control APIs. If any source was set prior to this call, that source will be discarded.

Note
A MediaPlayerInterface implementation must handle only one source at a time. An implementation must call MediaPlayerObserverInterface::onPlaybackStopped() with the previous source's id if there was a source set. Also, an implementation must call MediaPlayerObserverInterface::onBufferingComplete() when this source has been fully buffered
Parameters
streamObject from which to read an incoming audio stream.
repeatWhether the audio stream should be played in a loop until stopped.
configMedia configuration of source.
Returns
The SourceId that represents the source being handled as a result of this call. ERROR will be returned if the source failed to be set. Must be unique across all instances.

Implemented in alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer, alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, alexaClientSDK::integration::test::TestMediaPlayer, and alexaClientSDK::capabilityAgents::alerts::renderer::test::TestMediaPlayer.

◆ stop()

virtual bool alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::stop ( SourceId  id)
pure virtual

Stops playing the audio specified by the setSource() call.

The source must be set before issuing stop().

Once stop() has been called, subsequent play() calls will fail. If stop() is called when audio has already stopped, false will be returned. If the id does not match the id of the active source, then false will be returned. If the stop() succeeded, true will be returned. When true is returned, a callback will be made to either MediaPlayerObserverInterface::onPlaybackStopped() or to MediaPlayerObserverInterface::onPlaybackError().

Parameters
idThe unique id of the source on which to operate.
Returns
true if the call succeeded, in which case a callback will be made, or false otherwise.

Implemented in alexaClientSDK::mediaPlayer::MediaPlayer, alexaClientSDK::capabilityAgents::alerts::renderer::test::TestMediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.

Member Data Documentation

◆ ERROR

const SourceId alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::ERROR = 0
static

An SourceId used to represent an error from calls to setSource().


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

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