mediaPlayer.start();
2、播放云端MP3文件
===========
1、添加音频播放器依赖
//exoplayer播放器
implementation ‘com.google.android.exoplayer:exoplayer:2.8.4’
// 视频缓存
implementation ‘com.danikula:videocache:2.7.0’
implementation ‘org.greenrobot:greendao:3.2.2’
2、播放云端MP3——文件链接
PlayerView mExoPlay;
private SimpleExoPlayerHelper mMySimpleExoPlayer;
private List mVideoSourseList = new ArrayList<>();
btn_downMP3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String vds = “https://gzlxcdg.https.xiaozhuschool.com/public/uploads/video/20200504/fa530b8ae53f8d2e7698ea0fb22d22d5.mp4”;
String urlStr = “http://zsxyylsb.app.xiaozhuschool.com/public/uploads/imgs/20200902/b04b350875d486b6957973bf7ea56dfc.mp3”;
if (!mVideoSourseList.isEmpty()) {
mVideoSourseList.clear();
}
mVideoSourseList.add(urlStr);
mVideoSourseList.add(vds);
mMySimpleExoPlayer.prepare(mVideoSourseList);
mMySimpleExoPlayer.setRepeatMode(SimpleExoPlayerHelper.RepeatMode.REPEAT_MODE_OFF);
mMySimpleExoPlayer.start();//播放云MP3
}
});
3、播文件夹里面的MP3文件
MediaPlayer medPlay;
medPlay=MediaPlayer.create(this,Uri.parse(“/storage/emulated/0/data/cn.dlc.xiaoyao/msc1/海洋第一集.mp3”));
开始
medPlay.start();
暂停
medPlay.pause();
重新开始
medPlay.stop();
medPlay=MediaPlayer.create(MainActivity.this,Uri.parse(“/storage/emulated/0/data/cn.dlc.xiaoyao/msc1/海洋第二集.mp3”));
medPlay.start();
4、获取MP3文件播放时长
public long getAudioFileVoiceTime(String filePath) {
long mediaPlayerDuration = 0L;
if (filePath == null || filePath.isEmpty()) {
return 0;
}
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(filePath);
mediaPlayer.prepare();
mediaPlayerDuration = mediaPlayer.getDuration();
} catch (IOException ioException) {
LogPlus.i(“lgq”, ioException.getMessage());
}