AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Classes | Public Member Functions | Static Public Member Functions | List of all members
alexaClientSDK::mediaPlayer::MediaPlayer Class Reference

#include <MediaPlayer.h>

Inheritance diagram for alexaClientSDK::mediaPlayer::MediaPlayer:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::mediaPlayer::MediaPlayer:
Collaboration graph
[legend]

Public Member Functions

 ~MediaPlayer ()
 
void doShutdown () override
 
Overridden MediaPlayerInterface methods.
SourceId setSource (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, const avsCommon::utils::AudioFormat *format=nullptr, const avsCommon::utils::mediaPlayer::SourceConfig &config=avsCommon::utils::mediaPlayer::emptySourceConfig()) override
 
SourceId setSource (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, std::chrono::milliseconds offsetAdjustment, const avsCommon::utils::AudioFormat *format=nullptr, const avsCommon::utils::mediaPlayer::SourceConfig &config=avsCommon::utils::mediaPlayer::emptySourceConfig()) override
 
SourceId setSource (const std::string &url, std::chrono::milliseconds offset=std::chrono::milliseconds::zero(), const avsCommon::utils::mediaPlayer::SourceConfig &config=avsCommon::utils::mediaPlayer::emptySourceConfig(), bool repeat=false, const avsCommon::utils::mediaPlayer::PlaybackContext &playbackContext=avsCommon::utils::mediaPlayer::PlaybackContext()) override
 
SourceId setSource (std::shared_ptr< std::istream > stream, bool repeat=false, const avsCommon::utils::mediaPlayer::SourceConfig &config=avsCommon::utils::mediaPlayer::emptySourceConfig(), avsCommon::utils::MediaType format=avsCommon::utils::MediaType::UNKNOWN) override
 
bool play (SourceId id) override
 
bool stop (SourceId id) override
 
bool pause (SourceId id) override
 
bool resume (SourceId id) override
 
uint64_t getNumBytesBuffered () override
 
std::chrono::milliseconds getOffset (SourceId id) override
 
avsCommon::utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerStategetMediaPlayerState (SourceId id) override
 
void addObserver (std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > observer) override
 
void removeObserver (std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > observer) override
 
Overridden SpeakerInterface methods.
bool setVolume (int8_t volume) override
 
bool setMute (bool mute) override
 
bool getSpeakerSettings (avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings *settings) override
 
Overridden PipelineInterface methods.
void setAppSrc (GstAppSrc *appSrc) override
 
GstAppSrc * getAppSrc () const override
 
void setDecoder (GstElement *decoder) override
 
GstElement * getDecoder () const override
 
GstElement * getPipeline () const override
 
guint queueCallback (const std::function< gboolean()> *callback) override
 
guint attachSource (GSource *source) override
 
gboolean removeSource (guint tag) override
 
Overridden UrlContentToAttachmentConverter::ErrorObserverInterface methods.
void onError () override
 
void onWriteComplete () override
 
Overridden SourceObserverInterface methods.
void onFirstByteRead () override
 
- 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
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface
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 (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, std::chrono::milliseconds offsetAdjustment, const avsCommon::utils::AudioFormat *format=nullptr, const SourceConfig &config=emptySourceConfig())=0
 
virtual bool stop (SourceId id, std::chrono::seconds timeToPipelineShutdown)
 
virtual bool seekTo (SourceId id, std::chrono::milliseconds location, bool fromStart)
 
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 ()
 
virtual utils::Optional< FingerprintgetFingerprint ()
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::SpeakerInterface
virtual ~SpeakerInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::acsdkEqualizerInterfaces::EqualizerInterface
virtual ~EqualizerInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::ErrorObserverInterface
virtual ~ErrorObserverInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::WriteCompleteObserverInterface
virtual ~WriteCompleteObserverInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::mediaPlayer::SourceObserverInterface
virtual ~SourceObserverInterface ()=default
 

Static Public Member Functions

static std::shared_ptr< MediaPlayercreate (std::shared_ptr< avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface > contentFetcherFactory=nullptr, bool enableEqualizer=false, std::string name="", bool enableLiveMode=false)
 

Additional Inherited Members

- Public Types inherited from alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface
using SourceId = uint64_t
 A type that identifies which source is currently being operated on. This must be unique across all instances. More...
 
- Static Public Attributes inherited from alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface
static const SourceId ERROR = 0
 An SourceId used to represent an error from calls to setSource(). More...
 

Detailed Description

Class that handles creation of audio pipeline and playing of audio data.

Constructor & Destructor Documentation

◆ ~MediaPlayer()

alexaClientSDK::mediaPlayer::MediaPlayer::~MediaPlayer ( )

Destructor.

Member Function Documentation

◆ addObserver()

void alexaClientSDK::mediaPlayer::MediaPlayer::addObserver ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface observer)
override

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

◆ attachSource()

guint alexaClientSDK::mediaPlayer::MediaPlayer::attachSource ( GSource *  source)
overridevirtual

Attach the source to the worker thread.

Parameters
sourceThe source to be executed on the worker thread.
Returns
The ID (greater than 0) of the source. 0 if there is an error.

Implements alexaClientSDK::mediaPlayer::PipelineInterface.

◆ create()

static std::shared_ptr<MediaPlayer> alexaClientSDK::mediaPlayer::MediaPlayer::create ( std::shared_ptr< avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface contentFetcherFactory = nullptr,
bool  enableEqualizer = false,
std::string  name = "",
bool  enableLiveMode = false 
)
static

Creates an instance of the MediaPlayer.

Parameters
contentFetcherFactoryUsed to create objects that can fetch remote HTTP content.
enableEqualizerFlag, indicating whether equalizer should be enabled for this instance.
nameReadable name for the new instance.
enableLiveModeFlag, indicating if the player is in live mode.
Returns
An instance of the MediaPlayer if successful else a nullptr.

◆ doShutdown()

void alexaClientSDK::mediaPlayer::MediaPlayer::doShutdown ( )
overridevirtual

Prepares/enables this object to be deleted. This should be the last function called on this object prior to deleting (or resetting) its shared_ptr.

Warning
  • Attempting to call functions on this object after calling shutdown() can result in undefined behavior.
  • Neglecting to call shutdown() on this object can result in resource leaks or other undefined behavior.

Implements alexaClientSDK::avsCommon::utils::RequiresShutdown.

◆ getAppSrc()

GstAppSrc* alexaClientSDK::mediaPlayer::MediaPlayer::getAppSrc ( ) const
overridevirtual

Gets the appSrc element of the AudioPipeline.

Returns
The appSrc element.

Implements alexaClientSDK::mediaPlayer::PipelineInterface.

◆ getDecoder()

GstElement* alexaClientSDK::mediaPlayer::MediaPlayer::getDecoder ( ) const
overridevirtual

Gets the decoder element of the AudioPipeline.

Returns
The decoder element.

Implements alexaClientSDK::mediaPlayer::PipelineInterface.

◆ getMediaPlayerState()

avsCommon::utils::Optional<avsCommon::utils::mediaPlayer::MediaPlayerState> alexaClientSDK::mediaPlayer::MediaPlayer::getMediaPlayerState ( SourceId  id)
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.

◆ getNumBytesBuffered()

uint64_t alexaClientSDK::mediaPlayer::MediaPlayer::getNumBytesBuffered ( )
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.

◆ getOffset()

std::chrono::milliseconds alexaClientSDK::mediaPlayer::MediaPlayer::getOffset ( SourceId  id)
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.

◆ getPipeline()

GstElement* alexaClientSDK::mediaPlayer::MediaPlayer::getPipeline ( ) const
overridevirtual

Gets the pipeline of the AudioPipeline.

Returns
The pipeline.

Implements alexaClientSDK::mediaPlayer::PipelineInterface.

◆ getSpeakerSettings()

bool alexaClientSDK::mediaPlayer::MediaPlayer::getSpeakerSettings ( avsCommon::sdkInterfaces::SpeakerInterface::SpeakerSettings settings)
overridevirtual

Return a SpeakerSettings object to indicate the current settings of the SpeakerInterface.

Parameters
[out]settingsA SpeakerSettings object if successful.
Returns
Whether the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerInterface.

◆ onError()

void alexaClientSDK::mediaPlayer::MediaPlayer::onError ( )
overridevirtual

Notification that an error has occurred in the streaming of content.

Implements alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::ErrorObserverInterface.

◆ onFirstByteRead()

void alexaClientSDK::mediaPlayer::MediaPlayer::onFirstByteRead ( )
overridevirtual

This indicates that the first bytes of data have been read from the source.

Implements alexaClientSDK::mediaPlayer::SourceObserverInterface.

◆ onWriteComplete()

void alexaClientSDK::mediaPlayer::MediaPlayer::onWriteComplete ( )
overridevirtual

Notification that the attachement has had all data written to it

Implements alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::WriteCompleteObserverInterface.

◆ pause()

bool alexaClientSDK::mediaPlayer::MediaPlayer::pause ( SourceId  id)
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.

◆ play()

bool alexaClientSDK::mediaPlayer::MediaPlayer::play ( SourceId  id)
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.

◆ queueCallback()

guint alexaClientSDK::mediaPlayer::MediaPlayer::queueCallback ( const std::function< gboolean()> *  callback)
overridevirtual

Queue the specified callback for execution on the worker thread.

Parameters
callbackThe callback to queue.
Returns
The ID of the queued callback (for calling g_source_remove).

Implements alexaClientSDK::mediaPlayer::PipelineInterface.

◆ removeObserver()

void alexaClientSDK::mediaPlayer::MediaPlayer::removeObserver ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface observer)
override

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

◆ removeSource()

gboolean alexaClientSDK::mediaPlayer::MediaPlayer::removeSource ( guint  tag)
overridevirtual

Remove the callback from the worker thread.

Parameters
TheID of the queued callback.
Returns
Whether the removal is successful.

Implements alexaClientSDK::mediaPlayer::PipelineInterface.

◆ resume()

bool alexaClientSDK::mediaPlayer::MediaPlayer::resume ( SourceId  id)
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.

◆ setAppSrc()

void alexaClientSDK::mediaPlayer::MediaPlayer::setAppSrc ( GstAppSrc *  appSrc)
overridevirtual

Sets the appSrc element in the AudioPipeline.

Parameters
appSrcThe element the appSrc of AudioPipeline should be set to.

Implements alexaClientSDK::mediaPlayer::PipelineInterface.

◆ setDecoder()

void alexaClientSDK::mediaPlayer::MediaPlayer::setDecoder ( GstElement *  decoder)
overridevirtual

Sets the decoder element in the AudioPipeline

Parameters
decoderThe element the decoder of AudioPipeline should be set to.

Implements alexaClientSDK::mediaPlayer::PipelineInterface.

◆ setMute()

bool alexaClientSDK::mediaPlayer::MediaPlayer::setMute ( bool  mute)
overridevirtual

Set the mute of the speaker.

Parameters
muteRepresents whether the speaker should be muted (true) or unmuted (false).
Returns
Whether the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerInterface.

◆ setSource() [1/4]

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

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

◆ setSource() [2/4]

SourceId alexaClientSDK::mediaPlayer::MediaPlayer::setSource ( std::shared_ptr< avsCommon::avs::attachment::AttachmentReader attachmentReader,
std::chrono::milliseconds  offsetAdjustment,
const avsCommon::utils::AudioFormat format = nullptr,
const avsCommon::utils::mediaPlayer::SourceConfig config = avsCommon::utils::mediaPlayer::emptySourceConfig() 
)
override

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

◆ setSource() [3/4]

SourceId alexaClientSDK::mediaPlayer::MediaPlayer::setSource ( const std::string &  url,
std::chrono::milliseconds  offset = std::chrono::milliseconds::zero(),
const avsCommon::utils::mediaPlayer::SourceConfig config = avsCommon::utils::mediaPlayer::emptySourceConfig(),
bool  repeat = false,
const avsCommon::utils::mediaPlayer::PlaybackContext playbackContext = avsCommon::utils::mediaPlayer::PlaybackContext() 
)
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.

◆ setSource() [4/4]

SourceId alexaClientSDK::mediaPlayer::MediaPlayer::setSource ( std::shared_ptr< std::istream >  stream,
bool  repeat = false,
const avsCommon::utils::mediaPlayer::SourceConfig config = avsCommon::utils::mediaPlayer::emptySourceConfig(),
avsCommon::utils::MediaType  format = avsCommon::utils::MediaType::UNKNOWN 
)
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.

◆ setVolume()

bool alexaClientSDK::mediaPlayer::MediaPlayer::setVolume ( int8_t  volume)
overridevirtual

Set the absolute volume of the speaker. volume will be [AVS_SET_VOLUME_MIN, AVS_SET_VOLUME_MAX], and implementers of the interface must normalize the volume to fit the needs of their drivers.

Parameters
volumeA volume to set the speaker to.
Returns
Whether the operation was successful.

Implements alexaClientSDK::avsCommon::sdkInterfaces::SpeakerInterface.

◆ stop()

bool alexaClientSDK::mediaPlayer::MediaPlayer::stop ( SourceId  id)
overridevirtual

To resume playback after a pause, call resume. Calling play will reset the pipeline and source, and will not resume playback.

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface.


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