liuzhenxing1118 8 ماه پیش
والد
کامیت
80142458fc

+ 3 - 1
app/src/main/AndroidManifest.xml

@@ -32,7 +32,9 @@
         tools:targetApi="31">
         <activity
             android:name=".activity.MainActivity"
-            android:exported="true">
+            android:exported="true"
+            android:configChanges="keyboardHidden|orientation|screenSize"
+            android:launchMode="singleInstance">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />

+ 19 - 24
app/src/main/java/com/xplora/xpvideo/activity/MainActivity.java

@@ -75,7 +75,7 @@ public class MainActivity extends Activity implements Listener.VideoListener {
         requestPermission();
         initView();
         initData();
-        mVideoManager.init(this, mTicket);
+        initVideoManager();
     }
 
     private void initView() {
@@ -115,12 +115,19 @@ public class MainActivity extends Activity implements Listener.VideoListener {
         mHintText.setText(mVideoType == 0 ? R.string.invite : R.string.calling);
     }
 
+    private void initVideoManager() {
+        if (ToolsUtils.isNetworkAvailable(this)) {
+            mVideoManager.init(this, mTicket);
+        } else {
+            showToast(getString(R.string.network_error));
+        }
+    }
+
     @Override
     public void onLoginCallback(boolean isOK) {
         Log.d(TAG, "onLoginCallback: " + isOK);
         if (isOK) {
-            //呼出
-            if (mVideoType == 1) {
+            if (mVideoType == 1) { //呼出
                 mVideoManager.call(mVideoId);
             }
         }
@@ -129,7 +136,6 @@ public class MainActivity extends Activity implements Listener.VideoListener {
     @Override
     public void onCallItemAdd(JCCallItem item) {
         if (item.getDirection() == JCCall.DIRECTION_OUT && item.getVideo()) {
-            Log.d(TAG, "onCallItemAdd: " + item.getUserId());
             mAnswerBtn.setVisibility(View.GONE);
         }
 
@@ -140,25 +146,13 @@ public class MainActivity extends Activity implements Listener.VideoListener {
     @Override
     public void onCallItemUpdate() {
         List<JCCallItem> callItems = mVideoManager.mCall.getCallItems();
-        if (callItems.size() == 0) {
-
-        } else {
-            JCCallItem item = mVideoManager.getActiveCall();
-            if (item == null) {
-                return;
-            }
-            boolean needAnswer = item.getDirection() == JCCall.DIRECTION_IN && item.getState() == JCCall.STATE_PENDING;
-            if (item.getVideo()) {
-                updateLayout(item);
-            } else {
-                removeCanvas();
-            }
-        }
-    }
+        if (callItems.size() <= 0)
+            return;
+        JCCallItem item = mVideoManager.getActiveCall();
+        if (item == null)
+            return;
 
-    private void updateLayout(JCCallItem item) {
-        JCCallItem activeItem = mVideoManager.mCall.getCallItems().get(0);
-        int state = activeItem.getState();
+        int state = item.getState();
         Log.d(TAG, "updateLayout: " + state);
         if (state == JCCall.STATE_INIT || state == JCCall.STATE_PENDING) {
             updateLayout_pending(item);
@@ -214,6 +208,8 @@ public class MainActivity extends Activity implements Listener.VideoListener {
 
     @Override
     public void onCallItemRemove() {
+        stopTimeoutTimer();
+        stopTalkingTimer();
         mMediaPlayerUtils.playSound(this, R.raw.video_cancel, false);
         new Handler().postDelayed(new Runnable() {
             @Override
@@ -319,7 +315,6 @@ public class MainActivity extends Activity implements Listener.VideoListener {
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        stopTimeoutTimer();
-        stopTalkingTimer();
+        removeCanvas();
     }
 }

+ 10 - 0
app/src/main/java/com/xplora/xpvideo/manager/MediaPlayerUtils.java

@@ -24,6 +24,16 @@ public class MediaPlayerUtils {
             mediaPlayer.setDataSource(context, path);
             // 设置循环播放
             mediaPlayer.setLooping(isLoop);
+
+            mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
+                @Override
+                public void onCompletion(MediaPlayer mp) {
+                    if (!isLoop) {
+                        stopSound();
+                    }
+                }
+            });
+
             // 准备播放
             mediaPlayer.prepare();
             // 开始播放

+ 5 - 3
app/src/main/java/com/xplora/xpvideo/manager/VideoManager.java

@@ -123,7 +123,7 @@ public class VideoManager implements JCClientCallback, JCCallCallback, JCMediaDe
     public void onClientStateChange(int state, int oldState) {
         Log.d(TAG, "onClientStateChange: " + state);
         if (state == JCClient.STATE_IDLE) { // 未登录
-            loginJuphoon(this.mUserId);
+            //loginJuphoon(this.mUserId);
         }
     }
 
@@ -139,9 +139,8 @@ public class VideoManager implements JCClientCallback, JCCallCallback, JCMediaDe
 
     @Override
     public void onCallItemAdd(JCCallItem item) {
-        Log.d(TAG, "onCallItemAdd");
+        Log.d(TAG, "onCallItemAdd:" + item.getUserId());
         if (mCall.getCallItems().size() > 0) {
-            String userId = item.getUserId();
             if (mVideoListener != null) {
                 mVideoListener.onCallItemAdd(item);
             }
@@ -155,6 +154,9 @@ public class VideoManager implements JCClientCallback, JCCallCallback, JCMediaDe
         item.stopSelfVideo();
         // 销毁远端视频画面
         item.stopOtherVideo();
+
+        mClient.logout();
+
         if (mVideoListener != null) {
             mVideoListener.onCallItemRemove();
         }

+ 8 - 0
app/src/main/java/com/xplora/xpvideo/utils/ToolsUtils.java

@@ -3,6 +3,8 @@ package com.xplora.xpvideo.utils;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
 import android.widget.ImageView;
 
 import java.io.FileInputStream;
@@ -51,4 +53,10 @@ public class ToolsUtils {
             return null;
         }
     }
+
+    public static boolean isNetworkAvailable(Context context) {
+        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
+        return networkInfo != null && networkInfo.isAvailable();
+    }
 }

+ 0 - 16
app/src/main/res/values-night/themes.xml

@@ -1,16 +0,0 @@
-<resources xmlns:tools="http://schemas.android.com/tools">
-    <!-- Base application theme. -->
-    <style name="Theme.XPVideo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
-        <!-- Primary brand color. -->
-        <item name="colorPrimary">@color/purple_200</item>
-        <item name="colorPrimaryVariant">@color/purple_700</item>
-        <item name="colorOnPrimary">@color/black</item>
-        <!-- Secondary brand color. -->
-        <item name="colorSecondary">@color/teal_200</item>
-        <item name="colorSecondaryVariant">@color/teal_200</item>
-        <item name="colorOnSecondary">@color/black</item>
-        <!-- Status bar color. -->
-        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
-        <!-- Customize your theme here. -->
-    </style>
-</resources>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -4,4 +4,5 @@
     <string name="calling">正在呼叫中</string>
     <string name="connecting">连接中…</string>
     <string name="timeout">超时</string>
+    <string name="network_error">网络错误</string>
 </resources>

+ 7 - 12
app/src/main/res/values/themes.xml

@@ -1,16 +1,11 @@
 <resources xmlns:tools="http://schemas.android.com/tools">
     <!-- Base application theme. -->
-    <style name="Theme.XPVideo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
-        <!-- Primary brand color. -->
-        <item name="colorPrimary">@color/purple_500</item>
-        <item name="colorPrimaryVariant">@color/purple_700</item>
-        <item name="colorOnPrimary">@color/white</item>
-        <!-- Secondary brand color. -->
-        <item name="colorSecondary">@color/teal_200</item>
-        <item name="colorSecondaryVariant">@color/teal_700</item>
-        <item name="colorOnSecondary">@color/black</item>
-        <!-- Status bar color. -->
-        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
-        <!-- Customize your theme here. -->
+    <style name="Theme.XPVideo" parent="android:Theme.Material">
+        <item name="android:windowBackground">@color/black</item>
+        <item name="android:windowIsTranslucent">false</item>
+        <item name="android:windowShowWallpaper">false</item>
+        <item name="android:colorBackgroundCacheHint">@null</item>
+        <item name="android:windowSwipeToDismiss">false</item>
+        <item name="android:statusBarColor">@android:color/transparent</item>
     </style>
 </resources>