소스 검색

1.优化游戏音效

王鹏鹏 1 년 전
부모
커밋
d5e94d9e37

+ 6 - 11
baselib/src/main/java/com/yingyangfly/baselib/player/VoicePlayer.java

@@ -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();
         }
     }
 

+ 1 - 2
game/src/main/java/com/yingyangfly/game/dialog/GameResultDialog.kt

@@ -128,7 +128,6 @@ class GameResultDialog : DialogFragment() {
                 imageGameResult!!.post {
                     if (voicePlayer != null) {
                         voicePlayer?.play(gameSuccess) {
-                            voicePlayer?.stop()
                         }
                     }
                 }
@@ -174,7 +173,7 @@ class GameResultDialog : DialogFragment() {
     }
 
     override fun dismiss() {
-        if (voicePlayer != null && voicePlayer?.isPlaying == true) {
+        if (voicePlayer != null) {
             voicePlayer?.stop()
         }
         super.dismiss()

+ 1 - 1
game/src/main/java/com/yingyangfly/game/play/PlayGameActivity.kt

@@ -459,7 +459,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
                     val msg = it.split("voice:")
                     if (msg.isNullOrEmpty().not()) {
                         binding.tvIntroduce.text = msg[1]
-                        if (voicePlayer != null && voicePlayer!!.isPlaying.not()) {
+                        if (voicePlayer != null) {
                             speak(msg[1])
                         }
                     }