java.lang.Object | |
↳ | com.h6ah4i.android.media.standard.StandardMediaPlayer |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
com.h6ah4i.android.media.IBasicMediaPlayer
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
StandardMediaPlayer() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
attachAuxEffect(int effectId)
Attaches an auxiliary effect to the player.
| ||||||||||
int |
getAudioSessionId()
Returns the audio session ID.
| ||||||||||
int |
getCurrentPosition()
Gets the current playback position.
| ||||||||||
int |
getDuration()
Gets the duration of the file.
| ||||||||||
MediaPlayer |
getMediaPlayer()
Get underlying MediaPlayer instance.
| ||||||||||
boolean |
isLooping()
Checks whether the MediaPlayer is looping or non-looping.
| ||||||||||
boolean |
isPlaying()
Checks whether the MediaPlayer is playing.
| ||||||||||
void |
pause()
Pauses playback.
| ||||||||||
void |
prepare()
Prepares the player for playback, synchronously.
| ||||||||||
void |
prepareAsync()
Prepares the player for playback, asynchronously.
| ||||||||||
void |
release()
Releases resources associated with this MediaPlayer object.
| ||||||||||
void |
reset()
Resets the MediaPlayer to its uninitialized state.
| ||||||||||
void |
seekTo(int msec)
Seeks to specified time position.
| ||||||||||
void |
setAudioAttributes(AudioAttributes attributes)
Sets the audio attributes for this MediaPlayer.
| ||||||||||
void |
setAudioSessionId(int sessionId)
Sets the audio session ID.
| ||||||||||
void |
setAudioStreamType(int streamtype)
Sets the audio stream type for this MediaPlayer.
| ||||||||||
void |
setAuxEffectSendLevel(float level)
Sets the send level of the player to the attached auxiliary effect.
| ||||||||||
void |
setDataSource(FileDescriptor fd)
Sets the data source (FileDescriptor) to use.
| ||||||||||
void |
setDataSource(FileDescriptor fd, long offset, long length)
Sets the data source (FileDescriptor) to use.
| ||||||||||
void |
setDataSource(String path)
Sets the data source (file-path or http/rtsp URL) to use.
| ||||||||||
void |
setDataSource(Context context, Uri uri)
Sets the data source as a content Uri.
| ||||||||||
void |
setLooping(boolean looping)
Sets the player to be looping or non-looping.
| ||||||||||
void |
setNextMediaPlayer(IBasicMediaPlayer next)
Set the MediaPlayer to start when this MediaPlayer finishes playback
(i.e.
| ||||||||||
void |
setOnBufferingUpdateListener(IBasicMediaPlayer.OnBufferingUpdateListener listener)
Register a callback to be invoked when the status of a network stream's
buffer has changed.
| ||||||||||
void |
setOnCompletionListener(IBasicMediaPlayer.OnCompletionListener listener)
Register a callback to be invoked when the end of a media source has been
reached during playback.
| ||||||||||
void |
setOnErrorListener(IBasicMediaPlayer.OnErrorListener listener)
Register a callback to be invoked when an error has happened during an
asynchronous operation.
| ||||||||||
void |
setOnInfoListener(IBasicMediaPlayer.OnInfoListener listener)
Register a callback to be invoked when an info/warning is available.
| ||||||||||
void |
setOnPreparedListener(IBasicMediaPlayer.OnPreparedListener listener)
Register a callback to be invoked when the media source is ready for
playback.
| ||||||||||
void |
setOnSeekCompleteListener(IBasicMediaPlayer.OnSeekCompleteListener listener)
Register a callback to be invoked when a seek operation has been
completed.
| ||||||||||
void |
setVolume(float leftVolume, float rightVolume)
Sets the volume on this player.
| ||||||||||
void |
setWakeMode(Context context, int mode)
Set the low-level power management behavior for this MediaPlayer.
| ||||||||||
void |
start()
Starts or resumes playback.
| ||||||||||
void |
stop()
Stops playback after playback has been stopped or paused.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void | handleOnBufferingUpdate(MediaPlayer mp, int percent) | ||||||||||
void | handleOnCompletion(MediaPlayer mp) | ||||||||||
boolean | handleOnError(MediaPlayer mp, int what, int extra) | ||||||||||
boolean | handleOnInfo(MediaPlayer mp, int what, int extra) | ||||||||||
void | handleOnPrepared(MediaPlayer mp, boolean invokeCallback) | ||||||||||
void | handleOnSeekComplete(MediaPlayer mp) |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
com.h6ah4i.android.media.IBasicMediaPlayer
| |||||||||||
From interface
com.h6ah4i.android.media.IReleasable
|
Attaches an auxiliary effect to the player. A typical auxiliary effect is a reverberation effect which can be applied on any sound source that directs a certain amount of its energy to this effect. This amount is defined by setAuxEffectSendLevel().
After creating an auxiliary effect (e.g.
android.media.audiofx.EnvironmentalReverb), retrieve its ID with
getId()
and use it when calling
this method to attach the player to the effect.
To detach the effect from the player, call this method with a null effect id.
This method must be called after one of the overloaded
setDataSource
methods.
effectId | system wide unique id of the effect to attach |
---|
Returns the audio session ID.
Gets the current playback position.
Gets the duration of the file.
Get underlying MediaPlayer instance.
Checks whether the MediaPlayer is looping or non-looping.
Checks whether the MediaPlayer is playing.
IllegalStateException |
---|
Pauses playback. Call start() to resume.
IllegalStateException |
---|
Prepares the player for playback, synchronously. After setting the datasource and the display surface, you need to either call prepare() or prepareAsync(). For files, it is OK to call prepare(), which blocks until MediaPlayer is ready for playback.
IOException | |
---|---|
IllegalStateException |
Prepares the player for playback, asynchronously. After setting the datasource and the display surface, you need to either call prepare() or prepareAsync(). For streams, you should call prepareAsync(), which returns immediately, rather than blocking until enough data has been buffered.
IllegalStateException |
---|
Releases resources associated with this MediaPlayer object. It is considered good practice to call this method when you're done using the MediaPlayer. In particular, whenever an Activity of an application is paused (its onPause() method is called), or stopped (its onStop() method is called), this method should be invoked to release the MediaPlayer object, unless the application has a special need to keep the object around. In addition to unnecessary resources (such as memory and instances of codecs) being held, failure to call this method immediately if a MediaPlayer object is no longer needed may also lead to continuous battery consumption for mobile devices, and playback failure for other applications if no multiple instances of the same codec are supported on a device. Even if multiple instances of the same codec are supported, some performance degradation may be expected when unnecessary multiple instances are used at the same time.
Resets the MediaPlayer to its uninitialized state. After calling this method, you will have to initialize it again by setting the data source and calling prepare().
Seeks to specified time position.
msec | the offset in milliseconds from the start to seek to |
---|
IllegalStateException |
---|
Sets the audio attributes for this MediaPlayer. See
AudioAttributes
for how to build and configure an instance of
this class. You must call this method before prepare()
or
prepareAsync()
in order for the audio attributes to become
effective thereafter.
attributes | a non-null set of audio attributes |
---|
Sets the audio session ID.
sessionId | the audio session ID. The audio session ID is a system
wide unique identifier for the audio stream played by this
MediaPlayer instance. The primary use of the audio session ID
is to associate audio effects to a particular instance of
MediaPlayer: if an audio session ID is provided when creating
an audio effect, this effect will be applied only to the audio
content of media players within the same audio session and not
to the output mix. When created, a MediaPlayer instance
automatically generates its own audio session ID. However, it
is possible to force this player to be part of an already
existing audio session by calling this method. This method
must be called before one of the overloaded
setDataSource methods. |
---|
IllegalArgumentException | |
---|---|
IllegalStateException |
Sets the audio stream type for this MediaPlayer. See AudioManager for a list of stream types. Must call this method before prepare() or prepareAsync() in order for the target stream type to become effective thereafter.
streamtype | the audio stream type |
---|
Sets the send level of the player to the attached auxiliary effect. The level value range is 0 to 1.0.
By default the send level is 0, so even if an effect is attached to the player this method must be called for the effect to be applied.
Note that the passed level value is a raw scalar. UI controls should be scaled logarithmically: the gain applied by audio framework ranges from -72dB to 0dB, so an appropriate conversion from linear UI input x to level is: x == 0 -> level = 0 0 < x <= R -> level = 10^(72*(x-R)/20/R)
level | send level scalar |
---|
Sets the data source (FileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns.
fd | the FileDescriptor for the file you want to play |
---|
IOException | |
---|---|
IllegalArgumentException | |
IllegalStateException |
Sets the data source (FileDescriptor) to use. The FileDescriptor must be seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns.
fd | the FileDescriptor for the file you want to play |
---|---|
offset | the offset into the file where the data to be played starts, in bytes |
length | the length in bytes of the data to be played |
IOException | |
---|---|
IllegalArgumentException | |
IllegalStateException |
Sets the data source (file-path or http/rtsp URL) to use.
path | the path of the file, or the http/rtsp URL of the stream you want to play |
---|
IOException | |
---|---|
IllegalArgumentException | |
IllegalStateException |
Sets the data source as a content Uri.
context | the Context to use when resolving the Uri |
---|---|
uri | the Content URI of the data you want to play |
IOException | |
---|---|
IllegalArgumentException | |
IllegalStateException | |
SecurityException |
Sets the player to be looping or non-looping.
looping | whether to loop or not |
---|
Set the MediaPlayer to start when this MediaPlayer finishes playback (i.e. reaches the end of the stream). The media framework will attempt to transition from this player to the next as seamlessly as possible. The next player can be set at any time before completion. The next player must be prepared by the app, and the application should not call start() on it. The next MediaPlayer must be different from 'this'. An exception will be thrown if next == this. The application may call setNextMediaPlayer(null) to indicate no next player should be started at the end of playback. If the current player is looping, it will keep looping and the next player will not be started.
next | the player to start after this one completes playback. |
---|
Register a callback to be invoked when the status of a network stream's buffer has changed.
listener | the callback that will be run. |
---|
Register a callback to be invoked when the end of a media source has been reached during playback.
listener | the callback that will be run |
---|
Register a callback to be invoked when an error has happened during an asynchronous operation.
listener | the callback that will be run |
---|
Register a callback to be invoked when an info/warning is available.
listener | the callback that will be run |
---|
Register a callback to be invoked when the media source is ready for playback.
listener | the callback that will be run |
---|
Register a callback to be invoked when a seek operation has been completed.
listener | the callback that will be run |
---|
Sets the volume on this player. This API is recommended for balancing the
output of audio streams within an application. Unless you are writing an
application to control user settings, this API should be used in
preference to setStreamVolume(int, int, int)
which
sets the volume of ALL streams of a particular type. Note that the passed
volume values are raw scalars in range 0.0 to 1.0. UI controls should be
scaled logarithmically.
leftVolume | left volume scalar |
---|---|
rightVolume | right volume scalar |
Set the low-level power management behavior for this MediaPlayer.
This function has the MediaPlayer access the low-level power manager
service to control the device's power usage while playing is occurring.
The parameter is a combination of android.os.PowerManager wake
flags. Use of this method requires
WAKE_LOCK
permission. By default, no
attempt is made to keep the device awake during playback.
context | the Context to use |
---|---|
mode | the power/wake mode to set |
Starts or resumes playback. If playback had previously been paused, playback will continue from where it was paused. If playback had been stopped, or never started before, playback will start at the beginning.
IllegalStateException |
---|
Stops playback after playback has been stopped or paused.
IllegalStateException |
---|