Browse Source

1.优化游戏介绍页面播放器功能

王鹏鹏 1 year ago
parent
commit
9df7828d14

+ 22 - 11
game/src/main/java/com/yingyangfly/game/introduction/GameIntroductionActivity.kt

@@ -11,8 +11,8 @@ import android.view.MotionEvent
 import android.view.View
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.alibaba.android.arouter.launcher.ARouter
-import com.tencent.liteav.demo.superplayer.SuperPlayerModel
-import com.yingyangfly.baselib.config.AccountConfig
+import com.tencent.rtmp.TXLiveConstants
+import com.tencent.rtmp.TXVodPlayer
 import com.yingyangfly.baselib.db.GameSoundBean
 import com.yingyangfly.baselib.db.VoicePlayerBean
 import com.yingyangfly.baselib.dialog.GameLoadingDialog
@@ -44,6 +44,8 @@ class GameIntroductionActivity :
     private var gameCode: String = ""
     private var playClass: String = ""
     private var gameBean: GameBean? = null
+    private var mVodPlayer: TXVodPlayer? = null
+
     /**
      * 语音合成
      */
@@ -54,6 +56,7 @@ class GameIntroductionActivity :
         gameCode = intent.getStringExtra("gameCode") ?: ""
         playClass = intent.getStringExtra("playClass") ?: ""
         voicePlayer = VoicePlayer.getInstance(mContext)
+        mVodPlayer = TXVodPlayer(mContext)
         if (isEnterGame.not()) {
             val gameLoadingDialog = GameLoadingDialog()
             gameLoadingDialog.onDialogClickListener = {
@@ -79,7 +82,9 @@ class GameIntroductionActivity :
     override fun onNewIntent(intent: Intent?) {
         super.onNewIntent(intent)
         isEnterGame = true
-        binding.playTxCloudView.onResume()
+        if (mVodPlayer != null) {
+            mVodPlayer?.resume()
+        }
         binding.btnStartGame.setBackgroundResource(R.mipmap.icon_game_continue)
     }
 
@@ -108,17 +113,23 @@ class GameIntroductionActivity :
     }
 
     override fun onDestroy() {
-        binding.playTxCloudView.resetPlayer()
         super.onDestroy()
+        if (mVodPlayer != null) {
+            mVodPlayer?.stopPlay(true)
+        }
+        binding.videoView.onDestroy()
+
     }
 
     override fun onPause() {
-        binding.playTxCloudView.onPause()
         if (voicePlayer != null) {
             if (voicePlayer!!.isPlaying) {
                 voicePlayer?.stop()
             }
         }
+        if (mVodPlayer != null) {
+            mVodPlayer?.pause()
+        }
         super.onPause()
     }
 
@@ -308,12 +319,12 @@ class GameIntroductionActivity :
      * 加载游戏视频
      */
     private fun loadVideo(url: String) {
-        binding {
-            val model = SuperPlayerModel()
-            model.appId = AccountConfig.TENCENT_APPID // 配置 AppId
-            model.url = url // 配置您的播放视频 url
-            binding.playTxCloudView.showOrHideBackBtn(false)
-            binding.playTxCloudView.playWithModelNeedLicence(model)
+        if (mVodPlayer != null) {
+            mVodPlayer?.setRenderMode(TXLiveConstants.RENDER_MODE_FULL_FILL_SCREEN)
+            mVodPlayer?.setPlayerView(binding.videoView)
+            mVodPlayer?.isLoop = true
+            mVodPlayer?.setMute(true)
+            mVodPlayer?.startVodPlay(url)
         }
     }
 

+ 2 - 2
game/src/main/res/layout/activity_game_introduction.xml

@@ -125,8 +125,8 @@
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/tvTitle">
 
-                <com.tencent.liteav.demo.superplayer.SuperPlayerView
-                    android:id="@+id/play_tx_cloud_view"
+                <com.tencent.rtmp.ui.TXCloudVideoView
+                    android:id="@+id/videoView"
                     android:layout_width="@dimen/divider_445px"
                     android:layout_height="@dimen/divider_396px"
                     android:layout_marginStart="@dimen/divider_85px"