📅  最后修改于: 2023-12-03 15:13:21.916000             🧑  作者: Mango
dependencies {
implementation 'com.google.android.exoplayer:exoplayer:$latestVersion'
}
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(dataSourceString);
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// 准备完成
}
});
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// 播放完成
}
});
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// 播放出错
return false;
}
});
mediaPlayer.start(); // 播放
mediaPlayer.pause(); // 暂停
mediaPlayer.seekTo(msec); // 跳转到指定位置