Alexa Auto SDK  2.0.0
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
com.amazon.aace.audio.AudioOutput Class Referenceabstract

Classes

enum  MediaError
 
enum  MediaState
 
enum  MutedState
 

Public Member Functions

boolean prepare (AudioStream stream, boolean repeating)
 
boolean prepare (String url, boolean repeating)
 
boolean play ()
 
boolean stop ()
 
boolean pause ()
 
boolean resume ()
 
long getPosition ()
 
boolean setPosition (long position)
 
long getDuration ()
 
boolean volumeChanged (float volume)
 
boolean mutedStateChanged (MutedState state)
 

Static Public Attributes

static final long TIME_UNKNOWN = -1
 

Protected Member Functions

final void mediaError (MediaError type, String error)
 
final void mediaStateChanged (MediaState state)
 

Detailed Description

AudioOutput should be extended to play audio data provided by the Engine.

After returning true from a playback-controlling method invocation from the Engine (i.e. play(), pause(), stop(), resume()), it is required that platform implementation notify the Engine of a playback state change by calling one of mediaStateChanged() with the new MediaState or mediaError() with the MediaError. The Engine expects no call to mediaStateChanged() in response to an invocation for which the platform returned false.

The platform implementation may call mediaError() or mediaStateChanged() with MediaState.BUFFERING at any time during a playback operation to notify the Engine of an error or buffer underrun, respectvely. When the media player resumes playback after a buffer underrun, the platform implementation should call mediaStateChanged() with MediaState.PLAYING.

Note
The AudioOutput platform implementation should be able to support the audio formats recommended by AVS for a familiar Alexa experience: https://developer.amazon.com/docs/alexa-voice-service/recommended-media-support.html

Member Function Documentation

◆ prepare() [1/2]

boolean com.amazon.aace.audio.AudioOutput.prepare ( AudioStream  stream,
boolean  repeating 
)

Notifies the platform implementation to prepare for playback of an audio stream source. Audio data will be available to stream from the Engine via read(). After returning true, the Engine will call play() to initiate audio playback.

Parameters
streamThe audio stream to prepare
repeatingtrue if the audio should repeat
Returns
true if the platform implementation successfully handled the call, else false

◆ prepare() [2/2]

boolean com.amazon.aace.audio.AudioOutput.prepare ( String  url,
boolean  repeating 
)

Notifies the platform implementation to prepare for playback of a URL audio source. After returning true, the Engine will call play() to initiate audio playback.

Parameters
urlThe URL audio source to prepare
repeatingtrue if the audio should repeat
Returns
true if the platform implementation successfully handled the call, else false

◆ play()

boolean com.amazon.aace.audio.AudioOutput.play ( )

Notifies the platform implementation to start playback of the current audio source. After returning true, the platform implementation must call mediaStateChanged() with MediaState.PLAYING when the media player begins playing the audio or mediaError() if an error occurs.

Returns
true if the platform implementation successfully handled the call, else false

◆ stop()

boolean com.amazon.aace.audio.AudioOutput.stop ( )

Notifies the platform implementation to stop playback of the current audio source. After returning true, the platform implementation must call mediaStateChanged() with MediaState.STOPPED when the media player stops playing the audio or mediaError() if an error occurs.

A subsequent call to play() will be preceded by calls to prepare() and setPosition().

Returns
true if the platform implementation successfully handled the call, else false

◆ pause()

boolean com.amazon.aace.audio.AudioOutput.pause ( )

Notifies the platform implementation to pause playback of the current audio source. After returning true, the platform implementation must call mediaStateChanged() with MediaState.STOPPED when the media player pauses the audio or mediaError() if an error occurs. A subsequent call to resume() will not be preceded by calls to prepare() and setPosition().

Returns
true if the platform implementation successfully handled the call, else false

◆ resume()

boolean com.amazon.aace.audio.AudioOutput.resume ( )

Notifies the platform implementation to resume playback of the current audio source. After returning true, the platform implementation must call mediaStateChanged() with MediaState.PLAYING when the media player resumes the audio or mediaError() if an error occurs.

Returns
true if the platform implementation successfully handled the call, else false

◆ getPosition()

long com.amazon.aace.audio.AudioOutput.getPosition ( )

Returns the current playback position of the platform media player. If the audio source is not playing, the most recent position played should be returned.

Returns
The platform media player's playback position in milliseconds, or TIME_UNKNOWN if the current media position is unknown or invalid.

◆ setPosition()

boolean com.amazon.aace.audio.AudioOutput.setPosition ( long  position)

Notifies the platform implementation to set the playback position of the current audio source in the platform media player

Parameters
positionThe playback position in milliseconds to set in the platform media player
Returns
true if the platform implementation successfully handled the call, else false

◆ getDuration()

long com.amazon.aace.audio.AudioOutput.getDuration ( )

Returns the duration of the current audio source. If the duration is unknown, then TIME_UNKNOWN should be returned.

Returns
The duration of the current audio source in milliseconds, or TIME_UNKNOWN.

◆ volumeChanged()

boolean com.amazon.aace.audio.AudioOutput.volumeChanged ( float  volume)

Notifies the platform implementation to set the volume of the output channel. The volume value should be scaled to fit the needs of the platform.

Parameters
[in]volumeThe volume to set on the output channel. volume is in the range [0,1].
Returns
true if the platform implementation successfully handled the call, else false

◆ mutedStateChanged()

boolean com.amazon.aace.audio.AudioOutput.mutedStateChanged ( MutedState  state)

Notifies the platform implementation to apply a muted state has changed for the output channel

Parameters
[in]stateThe muted state to apply to the output channel. MutedState::MUTED when the output channel be muted, MutedState::UNMUTED when unmuted
Returns
true if the platform implementation successfully handled the call, else false

◆ mediaError()

final void com.amazon.aace.audio.AudioOutput.mediaError ( MediaError  type,
String  error 
)
protected

Notifies the Engine of an error during audio playback

Parameters
errorThe error encountered by the platform media player during playback
descriptionA description of the error
See also
MediaError

◆ mediaStateChanged()

final void com.amazon.aace.audio.AudioOutput.mediaStateChanged ( MediaState  state)
protected

Notifies the Engine of an audio playback state change in the platform implementation. Must be called when the platform media player transitions between stopped and playing states.

Parameters
stateThe new playback state of the platform media player
See also
MediaState

Member Data Documentation

◆ TIME_UNKNOWN

final long com.amazon.aace.audio.AudioOutput.TIME_UNKNOWN = -1
static

Used when audio time is unknown or indeterminate.


Alexa Auto SDK 2.0.0 - Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0