|
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 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())=0 |
|
virtual SourceId | setSource (std::shared_ptr< std::istream > stream, bool repeat=false, const SourceConfig &config=emptySourceConfig(), avsCommon::utils::MediaType format=avsCommon::utils::MediaType::UNKNOWN)=0 |
|
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 () |
|
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.
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
-
id | The 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::acsdkAlerts::renderer::test::TestMediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.
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
-
id | The 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.
virtual bool alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::seekTo |
( |
SourceId |
id, |
|
|
std::chrono::milliseconds |
location, |
|
|
bool |
fromStart |
|
) |
| |
|
inlinevirtual |
Seek to a position within the current song. This should only be called after setSource, and while playing or after a call to stop(id, timeout)
before the timeout period has expired. NOTE: A call to seekTo()
while STOPPED will not result in playback starting. If the pipeline has shutdown, false will be returned, if the pipeline is still open, a onSeeked
callback will be made with the requested location as the endState offset, but playback will not resume until play
is called again.
NOTE: Default empty implementation to avoid build breakage.
- Parameters
-
id | The unique id of the source on which to operate. |
location | Seek location |
fromStart | true if seek location is reletive to song start, false if reletive to current position. |
- Returns
true
if the call succeeded, or false
otherwise.
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
-
id | The 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::acsdkAlerts::renderer::test::TestMediaPlayer, alexaClientSDK::mediaPlayer::android::AndroidSLESMediaPlayer, and alexaClientSDK::integration::test::TestMediaPlayer.
virtual bool alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::stop |
( |
SourceId |
id, |
|
|
std::chrono::seconds |
timeToPipelineShutdown |
|
) |
| |
|
inlinevirtual |
Stops playing the audio specified by the setSource()
call, but will keep the pipeline open for a set time. NOTE: This call is optional, and may not be implemented by all MediaPlayers
The source must be set before issuing stop()
.
Once stop()
has been called, and the pipeline has shutdown, subsequent play()
calls will fail. However, if play()
is called while the pipeline remains open, playback will continue from the stopped location, or, if seekTo()
is called while the pipeline is open, and play()
also called while the pipeline is open, then playback will resume from the location specified in the seekTo()
call. 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
-
id | The unique id of the source on which to operate. |
timeToPipelineShutdown | The pipeline will be kept open for this long, and during that time, a call to @play will resume playback from the stopped location (or seeked location, if seek is called) |
- Returns
true
if the call succeeded, in which case a callback will be made, or false
otherwise.