不能播放音乐。。。
04-10 10:16:21.146 10669-10669/com.studes.reoger.guessmusic E/MediaPlayer: start called in state 1
04-10 10:16:21.146 10669-10669/com.studes.reoger.guessmusic E/MediaPlayer: error (-38, 0)
04-10 10:16:21.146 10669-10669/com.studes.reoger.guessmusic W/Paly: 播放指令执行了
04-10 10:16:21.146 10669-10669/com.studes.reoger.guessmusic W/textMediaPaly: __00000.m4a我运行了
04-10 10:16:21.151 10669-10669/com.studes.reoger.guessmusic E/MediaPlayer: Error (-38,0)
上面是:错误Log日志
下面是主要的逻辑代码:
调用:
MusicPlayerUtil.playSong(MainActivity.this, mCurrentSong.getFileName(), new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mViewBan.clearAnimation();//播放结束 关闭动画
}
});
public static void playSong(Context context,String fileName,
MediaPlayer.OnCompletionListener listener){
mMediaPalyer = initMediaPalyer(context,mMediaPalyer,fileName);
mMediaPalyer.start();
LogUtil.w("Paly", "播放指令执行了");
//设置歌曲播放完毕的回调
mMediaPalyer.setOnCompletionListener(listener);
}
private static MediaPlayer initMediaPalyer(Context context, MediaPlayer mediaPlayer, String fileName) {
if (mediaPlayer == null) {
mediaPlayer = new MediaPlayer();
}
//强制重置,在非首次播放的时需要强制重置
mediaPlayer.reset();
//加载声音文件
AssetManager assetManager = context.getAssets();
try {
AssetFileDescriptor fileDescriptor = assetManager.openFd(fileName);
mediaPlayer.setDataSource(fileDescriptor.getFileDescriptor(),
fileDescriptor.getStartOffset(), fileDescriptor.getLength());
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}finally {
}
return mediaPlayer;
}