|
@@ -1,13 +1,10 @@
|
|
|
package com.yingyangfly.baselib.player;
|
|
|
|
|
|
import android.content.Context;
|
|
|
-import android.content.res.AssetFileDescriptor;
|
|
|
import android.media.AudioManager;
|
|
|
import android.media.MediaPlayer;
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
/**
|
|
|
* @author 王鹏鹏
|
|
|
*/
|
|
@@ -17,7 +14,6 @@ public class VoicePlayer {
|
|
|
private AudioManager audioManager;
|
|
|
private MediaPlayer mediaPlayer;
|
|
|
private boolean isPause;
|
|
|
- private Context mContent;
|
|
|
private MediaPlayer.OnCompletionListener onCompletionListener;
|
|
|
|
|
|
public static VoicePlayer getInstance(Context context) {
|
|
@@ -32,7 +28,6 @@ public class VoicePlayer {
|
|
|
}
|
|
|
|
|
|
private VoicePlayer(Context cxt) {
|
|
|
- mContent = cxt.getApplicationContext();
|
|
|
Context baseContext = cxt.getApplicationContext();
|
|
|
audioManager = (AudioManager) baseContext.getSystemService(Context.AUDIO_SERVICE);
|
|
|
mediaPlayer = new MediaPlayer();
|
|
@@ -48,10 +43,10 @@ public class VoicePlayer {
|
|
|
}
|
|
|
|
|
|
public void play(final String url, final MediaPlayer.OnCompletionListener listener) {
|
|
|
- isPause = false;
|
|
|
- onCompletionListener = listener;
|
|
|
- try {
|
|
|
- if (!TextUtils.isEmpty(url)) {
|
|
|
+ if (!TextUtils.isEmpty(url)) {
|
|
|
+ isPause = false;
|
|
|
+ onCompletionListener = listener;
|
|
|
+ try {
|
|
|
mediaPlayer.reset();
|
|
|
mediaPlayer.setDataSource(url);
|
|
|
mediaPlayer.prepareAsync();
|
|
@@ -62,9 +57,9 @@ public class VoicePlayer {
|
|
|
stop();
|
|
|
onCompletionListener = null;
|
|
|
});
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|