![]() |
AlexaClientSDK
3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
|
A mock MediaPlayer for unit tests. More...
#include <MockMediaPlayer.h>
Public Types | |
using | observer = avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface |
using | MediaPlayerState = avsCommon::utils::mediaPlayer::MediaPlayerState |
![]() | |
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 | |
MockMediaPlayer () | |
MOCK_METHOD1 (play, bool(SourceId)) | |
MOCK_METHOD1 (pause, bool(SourceId)) | |
MOCK_METHOD1 (resume, bool(SourceId)) | |
MOCK_METHOD3 (seekTo, bool(SourceId, std::chrono::milliseconds location, bool fromStart)) | |
MOCK_METHOD1 (stop, bool(SourceId)) | |
MOCK_METHOD2 (stop, bool(SourceId, std::chrono::seconds)) | |
MOCK_METHOD1 (getOffset, std::chrono::milliseconds(SourceId)) | |
MOCK_METHOD0 (getNumBytesBuffered, uint64_t()) | |
MOCK_METHOD1 (getMediaPlayerState, avsCommon::utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerState >(SourceId)) | |
MOCK_METHOD0 (getPlaybackAttributes, avsCommon::utils::Optional< PlaybackAttributes >()) | |
MOCK_METHOD0 (getPlaybackReports, std::vector< PlaybackReport >()) | |
MOCK_METHOD0 (getFingerprint, Optional< Fingerprint >()) | |
MOCK_METHOD2 (attachmentSetSource, SourceId(std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, const avsCommon::utils::AudioFormat *audioFormat)) | |
MOCK_METHOD2 (streamSetSource, SourceId(std::shared_ptr< std::istream > stream, bool repeat)) | |
MOCK_METHOD1 (urlSetSource, SourceId(const std::string &url)) | |
SourceId | mockSetSource () |
bool | mockPlay (SourceId sourceId) |
bool | mockPause (SourceId sourceId) |
bool | mockResume (SourceId sourceId) |
bool | mockStop (SourceId sourceId) |
bool | mockStop2 (SourceId sourceId, std::chrono::seconds closePipleineTime) |
bool | mockFinished (SourceId sourceId) |
bool | mockError (SourceId sourceId) |
bool | mockSetOffset (SourceId sourceId, std::chrono::milliseconds offset) |
std::chrono::milliseconds | mockGetOffset (SourceId id) |
avsCommon::utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerState > | mockGetState (SourceId id) |
bool | mockSeek (SourceId sourceId, std::chrono::milliseconds location, bool fromStart) |
void | resetWaitTimer () |
bool | waitUntilNextSetSource (const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
bool | waitUntilPlaybackStarted (const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
bool | waitUntilPlaybackStarted (SourceId id, const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
bool | waitUntilPlaybackPaused (const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
bool | waitUntilPlaybackResumed (const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
bool | waitUntilPlaybackStopped (const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
bool | waitUntilPlaybackFinished (const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
bool | waitUntilPlaybackError (const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
bool | waitUntilSeeked (const std::chrono::milliseconds timeout=std::chrono::milliseconds(DEFAULT_TIME)) |
SourceId | getCurrentSourceId () |
SourceId | getSourceId () |
SourceId | getLatestSourceId () |
std::unordered_set< std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > > | getObservers () const |
MediaPlayerInterface overrides | |
SourceId | setSource (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, const avsCommon::utils::AudioFormat *audioFormat=nullptr, const SourceConfig &config=emptySourceConfig()) |
SourceId | setSource (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, std::chrono::milliseconds offsetAdjustment, const avsCommon::utils::AudioFormat *audioFormat=nullptr, const SourceConfig &config=emptySourceConfig()) |
SourceId | setSource (const std::string &url, std::chrono::milliseconds offset=std::chrono::milliseconds::zero(), const SourceConfig &config=emptySourceConfig(), bool repeat=false, const PlaybackContext &playbackContext=PlaybackContext()) |
SourceId | setSource (std::shared_ptr< std::istream > stream, bool repeat=false, const SourceConfig &config=emptySourceConfig(), avsCommon::utils::MediaType format=avsCommon::utils::MediaType::UNKNOWN) |
void | addObserver (std::shared_ptr< observer > playerObserver) |
void | removeObserver (std::shared_ptr< observer > playerObserver) |
RequiresShutdown overrides | |
void | doShutdown () |
![]() | |
virtual SourceId | attachmentSetSource (std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, const avsCommon::utils::AudioFormat *audioFormat)=0 |
virtual SourceId | streamSetSource (std::shared_ptr< std::istream > stream, bool repeat)=0 |
virtual SourceId | urlSetSource (const std::string &url)=0 |
![]() | |
virtual | ~MediaPlayerInterface ()=default |
virtual bool | play (SourceId id)=0 |
virtual bool | stop (SourceId id)=0 |
virtual bool | stop (SourceId id, std::chrono::seconds timeToPipelineShutdown) |
virtual bool | pause (SourceId id)=0 |
virtual bool | resume (SourceId id)=0 |
virtual bool | seekTo (SourceId id, std::chrono::milliseconds location, bool fromStart) |
virtual std::chrono::milliseconds | getOffset (SourceId id)=0 |
virtual uint64_t | getNumBytesBuffered ()=0 |
virtual utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerState > | getMediaPlayerState (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< PlaybackAttributes > | getPlaybackAttributes () |
virtual std::vector< PlaybackReport > | getPlaybackReports () |
virtual utils::Optional< Fingerprint > | getFingerprint () |
![]() | |
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::shared_ptr< testing::NiceMock< MockMediaPlayer > > | create () |
static void | enableConcurrentMediaPlayers () |
Additional Inherited Members | |
![]() | |
static const SourceId | ERROR = 0 |
An SourceId used to represent an error from calls to setSource() . More... | |
A mock MediaPlayer for unit tests.
using alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MediaPlayerState = avsCommon::utils::mediaPlayer::MediaPlayerState |
using alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::observer = avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MockMediaPlayer | ( | ) |
void alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::addObserver | ( | std::shared_ptr< observer > | playerObserver | ) |
|
static |
Creates an instance of the MockMediaPlayer
.
MockMediaPlayer
.
|
virtual |
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.
Implements alexaClientSDK::avsCommon::utils::RequiresShutdown.
|
static |
Configures the MockMediaPlayer to support concurrent MediaPlayers. Concurrent players differ in that they don't assume that the last Player with 'setSource' called is the 'current' player. Instead, the last player on which 'play' was called is the current player. This is used in tests involving pre-buffering, where multiple players may have had 'setSource' called. The enabled state will persist until 'doShutdown' is called
MediaPlayerInterface::SourceId alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::getCurrentSourceId | ( | ) |
Get the SourceId for the media MockMediaPlayer is currently playing.
MediaPlayerInterface::SourceId alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::getLatestSourceId | ( | ) |
Get the SourceId for the most recent MediaPlayer.setSource()
std::unordered_set< std::shared_ptr< MediaPlayerObserverInterface > > alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::getObservers | ( | ) | const |
Get the list of current observers.
MediaPlayerInterface::SourceId alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::getSourceId | ( | ) |
Get the SourceId for this MediaPlayer instance
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD0 | ( | getNumBytesBuffered | , |
uint64_t() | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD0 | ( | getPlaybackAttributes | , |
avsCommon::utils::Optional< PlaybackAttributes > | () | ||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD0 | ( | getPlaybackReports | , |
std::vector< PlaybackReport > | () | ||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD0 | ( | getFingerprint | , |
Optional< Fingerprint > | () | ||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD1 | ( | play | , |
bool(SourceId) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD1 | ( | pause | , |
bool(SourceId) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD1 | ( | resume | , |
bool(SourceId) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD1 | ( | stop | , |
bool(SourceId) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD1 | ( | getOffset | , |
std::chrono::milliseconds(SourceId) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD1 | ( | getMediaPlayerState | , |
avsCommon::utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerState > | SourceId | ||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD1 | ( | urlSetSource | , |
SourceId(const std::string &url) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD2 | ( | stop | , |
bool(SourceId, std::chrono::seconds) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD2 | ( | attachmentSetSource | , |
SourceId(std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, const avsCommon::utils::AudioFormat *audioFormat) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD2 | ( | streamSetSource | , |
SourceId(std::shared_ptr< std::istream > stream, bool repeat) | |||
) |
alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::MOCK_METHOD3 | ( | seekTo | , |
bool(SourceId, std::chrono::milliseconds location, bool fromStart) | |||
) |
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockError | ( | SourceId | sourceId | ) |
This is a mock method which will send the onPlaybackError()
notification to the observer.
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockFinished | ( | SourceId | sourceId | ) |
This is a mock method which will send the onPlaybackFinished()
notification to the observer.
std::chrono::milliseconds alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockGetOffset | ( | SourceId | id | ) |
This is a mock method which validates the id in a getOffset()
call.
Optional< avsCommon::utils::mediaPlayer::MediaPlayerState > alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockGetState | ( | SourceId | id | ) |
This is a mock method which gives the sourceId
and the offset through getOffset()
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockPause | ( | SourceId | sourceId | ) |
This is a mock method which will send the onPlaybackPaused()
notification to the observer.
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockPlay | ( | SourceId | sourceId | ) |
This is a mock method which will send the onPlaybackStarted()
notification to the observer.
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockResume | ( | SourceId | sourceId | ) |
This is a mock method which will send the onPlaybackResumed()
notification to the observer.
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockSeek | ( | SourceId | sourceId, |
std::chrono::milliseconds | location, | ||
bool | fromStart | ||
) |
This is a mock method which will send a onPlaybackStarted()
notification to the observer, with updated offset
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockSetOffset | ( | SourceId | sourceId, |
std::chrono::milliseconds | offset | ||
) |
This is a mock method which validates sourceId
and if valid, sets the offset.
MediaPlayerInterface::SourceId alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockSetSource | ( | ) |
This is a mock method which will generate a new SourceId.
SUCCESS
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockStop | ( | SourceId | sourceId | ) |
This is a mock method which will send the onPlaybackStopped()
notification to the observer.
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::mockStop2 | ( | SourceId | sourceId, |
std::chrono::seconds | closePipleineTime | ||
) |
This is a mock method which will send the onPlaybackStopped()
notification to the observer.
void alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::removeObserver | ( | std::shared_ptr< observer > | playerObserver | ) |
void alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::resetWaitTimer | ( | ) |
Reset the timer used in the following waitXXX methods. Used to test resuming
|
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.
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 bufferedattachmentReader | Object with which to read an incoming audio attachment. |
format | The audioFormat to be used to interpret raw audio data. |
config | Media configuration of source. |
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.
|
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.
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 bufferedattachmentReader | Object with which to read an incoming audio attachment. |
format | The audioFormat to be used to interpret raw audio data. |
offsetAdjustment | Offset adjustment required for the offset reported |
config | Media configuration of source. |
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.
|
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.
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 bufferedurl | The url to set as the source. |
offset | An optional offset parameter to start playing from when a play() call is made. |
config | Media configuration of source. |
repeat | An optional parameter to play the url source in a loop. |
playbackContext | An optional parameter used for sending headers needed for data requests. |
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.
Reimplemented in alexaClientSDK::acsdkAlerts::renderer::test::TestMediaPlayer.
|
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.
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 bufferedstream | Object from which to read an incoming audio stream. |
repeat | Whether the audio stream should be played in a loop until stopped. |
config | Media configuration of source. |
format | The MediaType audio encoding format of the incoming audio stream. |
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.
Reimplemented in alexaClientSDK::acsdkAlerts::renderer::test::TestMediaPlayer.
bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilNextSetSource | ( | const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) | ) |
Waits for the next call to setSource()
. When concurrentMediaPlayers are enabled, this function will wait for the next call to any instance's setSource()
timeout | The maximum time to wait. |
true
if setSource was called within timeout
milliseconds else false
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilPlaybackError | ( | const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) | ) |
Waits for the current source to reach the playback error state.
timeout | The maximum time to wait. |
true
if the state was reached within timeout
milliseconds else false
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilPlaybackFinished | ( | const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) | ) |
Waits for the current source to reach the playback finished state.
timeout | The maximum time to wait. |
true
if the state was reached within timeout
milliseconds else false
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilPlaybackPaused | ( | const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) | ) |
Waits for the current source to reach the playback paused state.
timeout | The maximum time to wait. |
true
if the state was reached within timeout
milliseconds else false
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilPlaybackResumed | ( | const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) | ) |
Waits for the current source to reach the playback resumed state.
timeout | The maximum time to wait. |
true
if the state was reached within timeout
milliseconds else false
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilPlaybackStarted | ( | const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) | ) |
Waits for the current source to reach the playback started state. This is only valid when concurrentMediaPlayers are not enabled.
timeout | The maximum time to wait. |
true
if the state was reached within timeout
milliseconds else false
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilPlaybackStarted | ( | SourceId | id, |
const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) |
||
) |
Waits for a source to reach the playback started state.
timeout | The maximum time to wait. |
is | The SourceId of the track waiting to Play |
true
if the state was reached within timeout
milliseconds else false
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilPlaybackStopped | ( | const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) | ) |
Waits for the current source to reach the playback stopped state.
timeout | The maximum time to wait. |
true
if the state was reached within timeout
milliseconds else false
. bool alexaClientSDK::avsCommon::utils::mediaPlayer::test::MockMediaPlayer::waitUntilSeeked | ( | const std::chrono::milliseconds | timeout = std::chrono::milliseconds(DEFAULT_TIME) | ) |
Waits for the current source to reach the seek complete state.
timeout | The maximum time to wait. |
true
if the state was reached within timeout
milliseconds else false
. AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0