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

#include <AndroidSLESMediaPlayer.h>

Inheritance diagram for alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer:
Collaboration graph
[legend]

Public Member Functions

void onPrefetchStatusChange (SLuint32 event)
 
 ~AndroidSLESMediaPlayer ()
 
std::shared_ptr< avsCommon::sdkInterfaces::SpeakerInterfacegetSpeaker ()
 
EqualizerInterface methods.
void setEqualizerBandLevels (acsdkEqualizerInterfaces::EqualizerBandLevelMap bandLevelMap) override
 
int getMinimumBandLevel () override
 
int getMaximumBandLevel () override
 
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, 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
 
std::chrono::milliseconds getOffset (SourceId id) override
 
uint64_t getNumBytesBuffered () override
 
avsCommon::utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerStategetMediaPlayerState (SourceId id) override
 
void addObserver (std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > playerObserver) override
 
void removeObserver (std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > playerObserver) override
 
- 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::acsdkEqualizerInterfaces::EqualizerInterface
virtual ~EqualizerInterface ()=default
 
- 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
 

Static Public Member Functions

static std::unique_ptr< AndroidSLESMediaPlayercreate (std::shared_ptr< avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface > contentFetcherFactory, std::shared_ptr< applicationUtilities::androidUtilities::AndroidSLESEngine > engine, bool enableEqualizer, const PlaybackConfiguration &config=PlaybackConfiguration(), const std::string &name="AndroidMediaPlayer")
 

Protected Member Functions

RequiresShutdown methods.
void doShutdown () override
 

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

This class implements an android compatible media player.

The implementation uses Android OpenSL ES to play the audio and FFmpeg to decode and resample the media input.

Constructor & Destructor Documentation

◆ ~AndroidSLESMediaPlayer()

alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::~AndroidSLESMediaPlayer ( )

Destructor. Stops the media player and shutdown all its members.

Member Function Documentation

◆ addObserver()

void alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::addObserver ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface playerObserver)
override

◆ create()

static std::unique_ptr<AndroidSLESMediaPlayer> alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::create ( std::shared_ptr< avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface contentFetcherFactory,
std::shared_ptr< applicationUtilities::androidUtilities::AndroidSLESEngine engine,
bool  enableEqualizer,
const PlaybackConfiguration config = PlaybackConfiguration(),
const std::string &  name = "AndroidMediaPlayer" 
)
static

Create AndroidSLESMediaPlayer.

Parameters
contentFetcherFactoryUsed to create objects that can fetch remote HTTP content.
engineThe OpenSL ES engine that is used to access the OpenSL ES media player and output mixer.
configThe playback configuration.
nameThe instance name used for logging purpose.
Returns
An instance of the AndroidSLESMediaPlayer if successful else nullptr.

◆ doShutdown()

void alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::doShutdown ( )
overrideprotectedvirtual

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.

◆ getMaximumBandLevel()

int alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::getMaximumBandLevel ( )
overridevirtual

Returns the maximum band level (dB) supported by this equalizer.

Returns
The maximum band level (dB) supported by this equalizer.

Implements alexaClientSDK::acsdkEqualizerInterfaces::EqualizerInterface.

◆ getMediaPlayerState()

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

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.

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

◆ getMinimumBandLevel()

int alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::getMinimumBandLevel ( )
overridevirtual

Returns the minimum band level (dB) supported by this equalizer.

Returns
The minimum band level (dB) supported by this equalizer.

Implements alexaClientSDK::acsdkEqualizerInterfaces::EqualizerInterface.

◆ getNumBytesBuffered()

uint64_t alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::getNumBytesBuffered ( )
overridevirtual

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

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

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

◆ getOffset()

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

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

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

◆ getSpeaker()

std::shared_ptr<avsCommon::sdkInterfaces::SpeakerInterface> alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::getSpeaker ( )

Get the speaker object that can be used to control the media player instance volume.

Returns
An instance of the speaker if successful else nullptr.

◆ onPrefetchStatusChange()

void alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::onPrefetchStatusChange ( SLuint32  event)

Callback method called by the AndroidSL ES media player when the prefetch status changes.

Parameters
eventEvent that has occurred.

◆ pause()

bool alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::pause ( SourceId  id)
overridevirtual

Pauses playing audio specified by the setSource() call.

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

  • without making a setSource(), false will be returned.
  • when audio is not starting/resuming/playing, false will be returned.
  • when a play() or resume() call has already been made, but no callback has been issued yet for those functions, the audio stream will pause without playing any audio. Implementations must call both MediaPlayerObserverInterface::onPlaybackStarted() / MediaPlayerObserverInterface::onPlaybackResumed and MediaPlayerObserverInterface::onPlaybackPaused() in this scenario, as both the play() / resume() and the pause() are required to have corresponding callbacks.

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.

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

◆ play()

bool alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::play ( SourceId  id)
overridevirtual

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.

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

◆ removeObserver()

void alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::removeObserver ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface playerObserver)
override

◆ resume()

bool alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::resume ( SourceId  id)
overridevirtual

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.

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

◆ setEqualizerBandLevels()

void alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::setEqualizerBandLevels ( acsdkEqualizerInterfaces::EqualizerBandLevelMap  bandLevelMap)
overridevirtual

Changes the equalization parameters for the audio.

Parameters
bandLevelMapEQ bands and their levels to be applied. Levels for all bands supported must be provided.

Implements alexaClientSDK::acsdkEqualizerInterfaces::EqualizerInterface.

◆ setSource() [1/4]

SourceId alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::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

◆ setSource() [2/4]

SourceId alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::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

◆ setSource() [3/4]

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

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.
playbackContextAn optional parameter used for sending headers needed for data requests.
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.

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

◆ setSource() [4/4]

SourceId alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::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

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.
formatThe MediaType audio encoding format of the incoming audio stream.
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.

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

◆ stop()

bool alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer::stop ( SourceId  id)
overridevirtual

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.

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