AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Member Functions | List of all members
alexaClientSDK::integration::test::TestMediaPlayer Class Reference

#include <TestMediaPlayer.h>

Inheritance diagram for alexaClientSDK::integration::test::TestMediaPlayer:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::integration::test::TestMediaPlayer:
Collaboration graph
[legend]

Public Member Functions

 ~TestMediaPlayer ()
 
avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId setSource (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, const avsCommon::utils::AudioFormat *audioFormat=nullptr, const avsCommon::utils::mediaPlayer::SourceConfig &config=avsCommon::utils::mediaPlayer::emptySourceConfig()) override
 
avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId setSource (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, std::chrono::milliseconds offsetAdjustment, const avsCommon::utils::AudioFormat *audioFormat=nullptr, const avsCommon::utils::mediaPlayer::SourceConfig &config=avsCommon::utils::mediaPlayer::emptySourceConfig()) override
 
avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId setSource (std::shared_ptr< std::istream > stream, bool repeat, const avsCommon::utils::mediaPlayer::SourceConfig &config=avsCommon::utils::mediaPlayer::emptySourceConfig(), avsCommon::utils::MediaType format=avsCommon::utils::MediaType::UNKNOWN) override
 
avsCommon::utils::mediaPlayer::MediaPlayerInterface::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
 
bool play (avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId id) override
 
bool stop (avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId id) override
 
bool pause (avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId id) override
 
bool resume (avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId id) override
 
std::chrono::milliseconds getOffset (avsCommon::utils::mediaPlayer::MediaPlayerInterface::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
 
avsCommon::utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerStategetMediaPlayerState (avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId id) override
 
uint64_t getNumBytesBuffered () override
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface
virtual ~MediaPlayerInterface ()=default
 
virtual bool stop (SourceId id, std::chrono::seconds timeToPipelineShutdown)
 
virtual bool seekTo (SourceId id, std::chrono::milliseconds location, bool fromStart)
 
virtual utils::Optional< PlaybackAttributesgetPlaybackAttributes ()
 
virtual std::vector< PlaybackReportgetPlaybackReports ()
 
virtual utils::Optional< FingerprintgetFingerprint ()
 

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

A Mock MediaPlayer that attempts to alert the observer of playing and stopping without actually playing audio. This removes the dependancy on an audio player to run tests with SpeechSynthesizer

Constructor & Destructor Documentation

◆ ~TestMediaPlayer()

alexaClientSDK::integration::test::TestMediaPlayer::~TestMediaPlayer ( )

Member Function Documentation

◆ addObserver()

void alexaClientSDK::integration::test::TestMediaPlayer::addObserver ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface playerObserver)
overridevirtual

Adds an observer to be notified when playback state changes.

Parameters
playerObserverThe observer to send the notifications to.

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

◆ getMediaPlayerState()

avsCommon::utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerState > alexaClientSDK::integration::test::TestMediaPlayer::getMediaPlayerState ( avsCommon::utils::mediaPlayer::MediaPlayerInterface::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.

◆ getNumBytesBuffered()

uint64_t alexaClientSDK::integration::test::TestMediaPlayer::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::integration::test::TestMediaPlayer::getOffset ( avsCommon::utils::mediaPlayer::MediaPlayerInterface::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.

◆ pause()

bool alexaClientSDK::integration::test::TestMediaPlayer::pause ( avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId  id)
overridevirtual

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.

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

◆ play()

bool alexaClientSDK::integration::test::TestMediaPlayer::play ( avsCommon::utils::mediaPlayer::MediaPlayerInterface::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::integration::test::TestMediaPlayer::removeObserver ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface playerObserver)
overridevirtual

Removes an observer to be notified when playback state changes.

Parameters
playerObserverThe observer to be removed

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

◆ resume()

bool alexaClientSDK::integration::test::TestMediaPlayer::resume ( avsCommon::utils::mediaPlayer::MediaPlayerInterface::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.

◆ setSource() [1/4]

avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId alexaClientSDK::integration::test::TestMediaPlayer::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

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() [2/4]

avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId alexaClientSDK::integration::test::TestMediaPlayer::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() 
)
overridevirtual

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.

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

◆ setSource() [3/4]

avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId alexaClientSDK::integration::test::TestMediaPlayer::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() 
)
overridevirtual

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.
offsetAdjustmentOffset adjustment required for the offset reported
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.

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

◆ setSource() [4/4]

avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId alexaClientSDK::integration::test::TestMediaPlayer::setSource ( std::shared_ptr< std::istream >  stream,
bool  repeat,
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::integration::test::TestMediaPlayer::stop ( avsCommon::utils::mediaPlayer::MediaPlayerInterface::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 files:

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