|
|
@@ -2,6 +2,7 @@ package com.yingyang.livebroadcast.activity.detail
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
import android.os.Bundle
|
|
|
+import android.text.TextUtils
|
|
|
import android.util.Log
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
@@ -14,7 +15,6 @@ import com.tencent.live2.V2TXLivePlayerObserver
|
|
|
import com.tencent.live2.impl.V2TXLivePlayerImpl
|
|
|
import com.yingyang.livebroadcast.R
|
|
|
import com.yingyang.livebroadcast.databinding.ActivityLiveBroadcastBinding
|
|
|
-import com.yingyangfly.baselib.config.AccountConfig
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
@@ -30,7 +30,6 @@ class LiveBroadcastActivity :
|
|
|
BaseMVVMActivity<ActivityLiveBroadcastBinding, LiveBroadcastDetailViewModel>(),
|
|
|
View.OnTouchListener {
|
|
|
|
|
|
- private val TAG = "LiveBroadcastActivity"
|
|
|
private var url: String = ""
|
|
|
private var mLivePlayer: V2TXLivePlayer? = null
|
|
|
private var mPlayFlag = false
|
|
|
@@ -44,7 +43,7 @@ class LiveBroadcastActivity :
|
|
|
//初始化直播
|
|
|
initPlayer()
|
|
|
//初始化IM
|
|
|
- initIm()
|
|
|
+ getUserSign()
|
|
|
}
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
@@ -105,51 +104,6 @@ class LiveBroadcastActivity :
|
|
|
if (result == 0) {
|
|
|
mPlayFlag = true
|
|
|
}
|
|
|
- Log.d(TAG, "startLivePlay : $result")
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化IM
|
|
|
- */
|
|
|
- private fun initIm() {
|
|
|
- // 初始化 config 对象
|
|
|
- val config = V2TIMSDKConfig()
|
|
|
- // 指定 log 输出级别
|
|
|
- config.setLogLevel(V2TIMSDKConfig.V2TIM_LOG_DEBUG)
|
|
|
- V2TIMManager.getInstance().initSDK(
|
|
|
- this, AccountConfig.TENCENT_IM_APPID.toInt(),
|
|
|
- config, listener
|
|
|
- )
|
|
|
- getUserSign()
|
|
|
- }
|
|
|
-
|
|
|
- private val listener = object : V2TIMSDKListener() {
|
|
|
- override fun onConnecting() {
|
|
|
- //正在链接
|
|
|
- }
|
|
|
-
|
|
|
- override fun onConnectSuccess() {
|
|
|
- //链接成功
|
|
|
- }
|
|
|
-
|
|
|
- override fun onConnectFailed(code: Int, error: String?) {
|
|
|
- //链接断开
|
|
|
- CrashReport.postCatchedException(Throwable(User.getName() + "IM 链接断开,错误码:" + code + " ,错误信息:" + error))
|
|
|
- }
|
|
|
-
|
|
|
- override fun onKickedOffline() {
|
|
|
- //已脱机
|
|
|
- CrashReport.postCatchedException(Throwable(User.getName() + "IM 已脱机"))
|
|
|
- }
|
|
|
-
|
|
|
- override fun onUserSigExpired() {
|
|
|
- //用户sig过期
|
|
|
- CrashReport.postCatchedException(Throwable(User.getName() + "IM sig过期"))
|
|
|
- }
|
|
|
-
|
|
|
- override fun onSelfInfoUpdated(info: V2TIMUserFullInfo?) {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -159,8 +113,8 @@ class LiveBroadcastActivity :
|
|
|
viewModel.getUserSign(User.getUserId(), fail = {
|
|
|
it.toast()
|
|
|
}, success = {
|
|
|
- if (it != null) {
|
|
|
- loginIm(it)
|
|
|
+ if (TextUtils.isEmpty(it).not()) {
|
|
|
+ loginIm(it!!)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -173,35 +127,31 @@ class LiveBroadcastActivity :
|
|
|
}
|
|
|
|
|
|
override fun onSuccess() {
|
|
|
-
|
|
|
+ Log.e("wpp", "IM登陆成功")
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
-// runOnUiThread {
|
|
|
-// V2TIMManager.getInstance().logout(object : V2TIMCallback {
|
|
|
-// override fun onError(p0: Int, p1: String?) {
|
|
|
-// //用户登录IM失败
|
|
|
-// CrashReport.postCatchedException(Throwable(User.getName() + "用户退出IM失败,错误码:" + p0 + " ,错误信息:" + p1))
|
|
|
-// }
|
|
|
-//
|
|
|
-// override fun onSuccess() {
|
|
|
-// Log.e("wpp", "IM退出成功")
|
|
|
-// }
|
|
|
-// })
|
|
|
-//
|
|
|
-// // 反初始化 SDK
|
|
|
-// V2TIMManager.getInstance().unInitSDK()
|
|
|
-// }
|
|
|
+ runOnUiThread {
|
|
|
+ V2TIMManager.getInstance().logout(object : V2TIMCallback {
|
|
|
+ override fun onError(p0: Int, p1: String?) {
|
|
|
+ //用户登录IM失败
|
|
|
+ CrashReport.postCatchedException(Throwable(User.getName() + "用户退出IM失败,错误码:" + p0 + " ,错误信息:" + p1))
|
|
|
+ }
|
|
|
|
|
|
- super.onDestroy()
|
|
|
- if (mLivePlayer != null) {
|
|
|
- if (mPlayFlag) {
|
|
|
- mLivePlayer!!.stopPlay()
|
|
|
+ override fun onSuccess() {
|
|
|
+ Log.e("wpp", "IM退出成功")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (mLivePlayer != null) {
|
|
|
+ if (mPlayFlag) {
|
|
|
+ mLivePlayer!!.stopPlay()
|
|
|
+ }
|
|
|
+ mLivePlayer = null
|
|
|
}
|
|
|
- mLivePlayer = null
|
|
|
}
|
|
|
+ super.onDestroy()
|
|
|
}
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|