pangweixin 4 anos atrás
pai
commit
4c8e2239f9

+ 18 - 0
VideoCall/src/main/java/com/tencent/trtc/videocall/VideoCallingActivity.java

@@ -2,6 +2,7 @@ package com.tencent.trtc.videocall;
 
 
 import android.content.Intent;
+import android.media.MediaPlayer;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.util.Log;
@@ -50,6 +51,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
     private String sdkAppId;
     private String privateMapKey;
     private String mIsVideo;
+    private MediaPlayer mMediaPlayer;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -104,6 +106,19 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
         rl_qiehuan.setOnClickListener(this);
     }
 
+    public void playjieting() {
+        //加载res/raw的happyis.mp3文件
+        mMediaPlayer = MediaPlayer.create(this, R.raw.guaduan);
+        mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
+            @Override
+            public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
+                mediaPlayer.seekTo(0);
+                return false;
+            }
+        });
+        mMediaPlayer.start();
+    }
+
     private void enterRoom() {
         mTRTCCloud = TRTCCloud.sharedInstance(getApplicationContext());
         mTRTCCloud.setListener(new TRTCCloudImplListener(VideoCallingActivity.this));
@@ -142,6 +157,9 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
     @Override
     protected void onDestroy() {
         super.onDestroy();
+        if(mMediaPlayer!=null){
+            mMediaPlayer.stop();
+        }
         EventBus.getDefault().unregister(this);
         exitRoom();
     }

BIN
VideoCall/src/main/res/raw/guaduan.mp3


+ 31 - 0
app/src/main/java/com/qingdaofushan/home/event/EventMp3.java

@@ -0,0 +1,31 @@
+package com.qingdaofushan.home.event;
+
+public class EventMp3 {
+    String msg;
+    int code;
+
+    public EventMp3(int code) {
+        this(code, "");
+    }
+
+    public EventMp3(int code, String msg) {
+        this.msg = msg;
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+}

+ 17 - 0
app/src/main/java/com/qingdaofushan/home/weiview/AndroidInterface.java

@@ -8,6 +8,7 @@ import android.webkit.JavascriptInterface;
 
 import com.just.agentweb.AgentWeb;
 import com.qingdaofushan.home.event.EventData;
+import com.qingdaofushan.home.event.EventMp3;
 import com.qingdaofushan.home.utils.SharedPreferenceUtil;
 import com.qingdaofushan.home.utils.ToastUtil;
 import com.qingdaofushan.home.zxing.activity.CaptureActivity;
@@ -150,4 +151,20 @@ public class AndroidInterface {
             }
         });
     }
+
+    @JavascriptInterface
+    public void PlayVoice(String json) {
+        deliver.post(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    JSONObject jsonObject = new JSONObject(json);
+                    int code = jsonObject.getInt("code");
+                    EventBus.getDefault().post(new EventMp3(code));
+                } catch (JSONException e) {
+                    ToastUtil.showToast("参数错误");
+                }
+            }
+        });
+    }
 }

+ 62 - 0
app/src/main/java/com/qingdaofushan/home/weiview/WebViewActivity.java

@@ -10,6 +10,7 @@ import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.graphics.Bitmap;
 import android.icu.text.SimpleDateFormat;
+import android.media.MediaPlayer;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
@@ -40,6 +41,7 @@ import com.just.agentweb.WebViewClient;
 import com.qingdaofushan.home.activity.NfcActivity;
 import com.qingdaofushan.home.event.EventData;
 import com.qingdaofushan.home.R;
+import com.qingdaofushan.home.event.EventMp3;
 import com.tencent.trtc.videocall.TrtcEvent;
 import com.qingdaofushan.home.utils.ToastUtil;
 
@@ -66,6 +68,7 @@ import java.util.Locale;
  */
 public class WebViewActivity extends NfcActivity {
 
+    private MediaPlayer mMediaPlayer = null;//媒体播放器
     LinearLayout linearLayout;
     protected AgentWeb mAgentWeb;
     private String url;
@@ -107,6 +110,54 @@ public class WebViewActivity extends NfcActivity {
         readNfc();
     }
 
+    public void playjieting() {
+        mMediaPlayer = MediaPlayer.create(this, R.raw.jieting);//加载res/raw的happyis.mp3文件
+        mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
+            @Override
+            public void onCompletion(MediaPlayer mediaPlayer) {
+                if(mMediaPlayer!=null){
+                    mMediaPlayer.start();
+                }
+            }
+        });
+        mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
+            @Override
+            public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
+                mediaPlayer.seekTo(0);
+                return false;
+            }
+        });
+        mMediaPlayer.start();
+    }
+
+
+    public void playhujiao() {
+        mMediaPlayer = MediaPlayer.create(this, R.raw.hujiao);//加载res/raw的happyis.mp3文件
+        mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
+            @Override
+            public void onCompletion(MediaPlayer mediaPlayer) {
+                if(mMediaPlayer!=null){
+                    mMediaPlayer.start();
+                }
+            }
+        });
+        mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
+            @Override
+            public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
+                mediaPlayer.seekTo(0);
+                return false;
+            }
+        });
+        mMediaPlayer.start();
+    }
+
+    public void stophujiao() {
+        if (mMediaPlayer != null) {
+            mMediaPlayer.stop();
+            mMediaPlayer = null;
+        }
+    }
+
     public void readNfc() {
         String s = null;
         try {
@@ -353,6 +404,17 @@ public class WebViewActivity extends NfcActivity {
         uploadMessageAboveL = null;
     }
 
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void evemp3(EventMp3 eventData) {
+        if (eventData.getCode() == 1) {
+            playhujiao();
+        } else if (eventData.getCode() == 2) {
+            playjieting();
+        } else if (eventData.getCode() == 3) {
+            stophujiao();
+        }
+    }
+
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void stopServiceEvent(EventData eventData) {
         if (eventData.getCode() == 1) {

BIN
app/src/main/res/raw/hujiao.mp3


BIN
app/src/main/res/raw/jieting.mp3