public class MediaMusicPlayer extends AbstractMusicPlayer
构造器和说明 |
---|
MediaMusicPlayer(android.content.Context context,
android.net.Uri uri)
创建一个
MediaMusicPlayer 对象。 |
MediaMusicPlayer(android.content.Context context,
android.net.Uri uri,
java.util.Map<java.lang.String,java.lang.String> headers)
创建一个
MediaMusicPlayer 对象。 |
MediaMusicPlayer(android.content.Context context,
android.net.Uri uri,
java.util.Map<java.lang.String,java.lang.String> headers,
java.util.List<java.net.HttpCookie> cookies)
创建一个
MediaMusicPlayer 对象。 |
dismissQuiet, pause, quiet, release, start, stop
public MediaMusicPlayer(@NonNull android.content.Context context, @NonNull android.net.Uri uri)
MediaMusicPlayer
对象。context
- Context 对象,不能为 nulluri
- 要播放的歌曲的 URI,不能为 nullpublic MediaMusicPlayer(@NonNull android.content.Context context, @NonNull android.net.Uri uri, @Nullable java.util.Map<java.lang.String,java.lang.String> headers)
MediaMusicPlayer
对象。context
- Context 对象,不能为 nulluri
- 要播放的歌曲的 URI,不能为 nullheaders
- HTTP 首部public MediaMusicPlayer(@NonNull android.content.Context context, @NonNull android.net.Uri uri, @Nullable java.util.Map<java.lang.String,java.lang.String> headers, @Nullable java.util.List<java.net.HttpCookie> cookies)
MediaMusicPlayer
对象。context
- Context 对象,不能为 nulluri
- 要播放的歌曲的 URI,不能为 nullheaders
- HTTP 首部cookies
- HTTP cookiespublic void prepare() throws java.lang.Exception
MusicPlayer
该方法会在主线程上执行,如果准备操作是个耗时操作,你应该在异步线程中执行它。
在实现该方法时,建议先检查 MusicPlayer.isInvalid()
状态,如果返回 true
,说明当前
MusicPlayer
已失效,此时因立即从该方法中返回,不应该再调用任何方法。
java.lang.Exception
public void setLooping(boolean looping)
MusicPlayer
如果播放器处于循环播放状态,则应返回 true,否则返回 false。对于新创建的 MusicPlayer
对象来说,
该方法默认返回 false。
looping
- 是否循环播放(默认返回 false)。public boolean isLooping()
MusicPlayer
public boolean isStalled()
MusicPlayer
stalled 状态用于表示当前缓冲区是否有足够的数据继续播放,如果缓冲区没有足够的数据支撑继续播放, 则该方法会返回 true,如果缓冲区有足够的数据可以继续播放,则返回 false。
public boolean isPlaying()
MusicPlayer
该方法的返回值只受 MusicPlayer.start()
、MusicPlayer.pause()
、MusicPlayer.stop()
、发生错误或者 MusicPlayer.release()
的影响。
调用 MusicPlayer.start()
方法后,该方法应该返回 true,并且只在调用 MusicPlayer.pause()
、
MusicPlayer.stop()
、播放器发生错误或者调用了 MusicPlayer.release()
方法时才返回 false。
调用了 MusicPlayer.start()
方法后,即使缓冲区没有足够的数据支持继续播放,只要没有没有调用
MusicPlayer.pause()
、MusicPlayer.stop()
、发生错误或者调用 MusicPlayer.release()
方法,
该方法就应该返回 true,即使当前缓冲区没有足够的数据,播放器正在缓冲。
public int getDuration()
MusicPlayer
public int getProgress()
MusicPlayer
public void startEx()
AbstractMusicPlayer
startEx
在类中 AbstractMusicPlayer
public void pauseEx()
AbstractMusicPlayer
pauseEx
在类中 AbstractMusicPlayer
public void stopEx()
AbstractMusicPlayer
stopEx
在类中 AbstractMusicPlayer
public void seekTo(int pos)
MusicPlayer
pos
- 要调整到的播放位置(单位:毫秒)public void setVolume(float leftVolume, float rightVolume)
MusicPlayer
如果你的播放器实现不打算支持单独分别设置左右声道的音量,则全部使用 leftVolume 参数的值即可。
leftVolume
- 左声道的音量百分比(范围为 [0.0 ~ 1.0] 的闭区间)rightVolume
- 右声道的音量百分比(范围为 [0.0 ~ 1.0] 的闭区间)public void setSpeed(float speed)
MusicPlayer
speed
- 播放速度,最小值为 0.1。public void releaseEx()
AbstractMusicPlayer
releaseEx
在类中 AbstractMusicPlayer
public boolean isInvalid()
MusicPlayer
当播放器发生错误,或者调用 MusicPlayer.release()
方法后,该方法应该返回 true。如果该方法返回 true,则不
应再调用除 MusicPlayer.release()
方法以外的任何其他方法。
MusicPlayer.release()
方法以外的任何其他方法public int getAudioSessionId()
MusicPlayer
public void setOnPreparedListener(@Nullable MusicPlayer.OnPreparedListener listener)
MusicPlayer
MusicPlayer.OnPreparedListener
监听器。listener
- 监听器对象,可为 null。为 null 时将清除上次设置的监听器。public void setOnCompletionListener(@Nullable MusicPlayer.OnCompletionListener listener)
MusicPlayer
MusicPlayer.OnCompletionListener
监听器。listener
- 监听器对象,可为 null。为 null 时将清除上次设置的监听器。public void setOnRepeatListener(@Nullable MusicPlayer.OnRepeatListener listener)
MusicPlayer
MusicPlayer.OnRepeatListener
监听器。listener
- 监听器对象,可为 null。为 null 时将清除上次设置的监听器。public void setOnSeekCompleteListener(@Nullable MusicPlayer.OnSeekCompleteListener listener)
MusicPlayer
MusicPlayer.OnSeekCompleteListener
监听器。listener
- 监听器对象,可为 null。为 null 时将清除上次设置的监听器。public void setOnStalledListener(@Nullable MusicPlayer.OnStalledListener listener)
MusicPlayer
MusicPlayer.OnStalledListener
监听器。listener
- 监听器对象,可为 null。为 null 时将清除上次设置的监听器。public void setOnBufferingUpdateListener(@Nullable MusicPlayer.OnBufferingUpdateListener listener)
MusicPlayer
MusicPlayer.OnBufferingUpdateListener
监听器。listener
- 监听器对象,可为 null。为 null 时将清除上次设置的监听器。public void setOnErrorListener(@Nullable MusicPlayer.OnErrorListener listener)
MusicPlayer
MusicPlayer.OnErrorListener
监听器。listener
- 监听器对象,可为 null。为 null 时将清除上次设置的监听器。