迁移视频播放组件,SimpleVideoPlayer。使用方式参见V2XCrossRoadVideoView,V2XVoiceCallLiveCarWindow

Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
董宏宇
2021-10-25 16:48:18 +08:00
parent 0626c3d88b
commit 5025bfacc0
7 changed files with 28 additions and 19 deletions

View File

@@ -67,6 +67,11 @@ dependencies {
implementation rootProject.ext.dependencies.androidxrecyclerview
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation rootProject.ext.dependencies.videoarmv7
implementation rootProject.ext.dependencies.videoarm64
implementation rootProject.ext.dependencies.videojava
implementation rootProject.ext.dependencies.livesdk
if (Boolean.valueOf(RELEASE)) {
} else {

View File

@@ -0,0 +1,183 @@
package com.mogo.eagle.core.widget.media.video
import android.content.Context
import android.util.AttributeSet
import android.view.Surface
import android.view.View
import android.widget.ImageView
import com.mogo.eagle.core.widget.R
import com.shuyu.gsyvideoplayer.GSYVideoManager
import com.shuyu.gsyvideoplayer.utils.GSYVideoType
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
import com.shuyu.gsyvideoplayer.video.base.GSYVideoViewBridge
/**
* @author donghongyu
* @since 2021/10/25
*
* 视频播放器直播或者MP4都可支持
*/
class SimpleVideoPlayer : StandardGSYVideoPlayer {
companion object {
const val PLAY_EVT_PLAY_LOADING = 1000
const val PLAY_EVT_PLAY_BEGIN = 2000
const val PLAY_EVT_PLAY_ERROR = 3000
}
private var playListener: PlayListener? = null
private lateinit var start: ImageView
interface PlayListener {
fun onPlayEvent(event: Int)
}
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, fullFlag: Boolean?) : super(context, fullFlag)
override fun init(context: Context) {
super.init(context)
start = findViewById(R.id.start)
if (mThumbImageViewLayout != null
&& (mCurrentState == -1 || mCurrentState == CURRENT_STATE_NORMAL || mCurrentState == CURRENT_STATE_ERROR)
) {
mThumbImageViewLayout.visibility = View.VISIBLE
}
}
override fun getLayoutId(): Int {
return R.layout.item_v2x_crossroad_live_video
}
override fun getGSYVideoManager(): GSYVideoViewBridge {
GSYVideoManager.instance().initContext(context.applicationContext)
return GSYVideoManager.instance()
}
override fun setProgressAndTime(
progress: Int,
secProgress: Int,
currentTime: Int,
totalTime: Int,
forceChange: Boolean
) {
super.setProgressAndTime(progress, secProgress, currentTime, totalTime, forceChange)
if (progress != 0) {
mProgressBar?.progress = progress
}
}
fun setPlayListener(listener: PlayListener) {
this.playListener = listener
}
override fun updateStartImage() {
}
override fun changeUiToCompleteShow() {
super.changeUiToCompleteShow()
mBottomContainer?.visibility = View.INVISIBLE
mProgressBar?.visibility = View.GONE
}
override fun hideAllWidget() {
super.hideAllWidget()
mBottomContainer?.visibility = View.INVISIBLE
mProgressBar?.visibility = View.GONE
}
override fun changeUiToPrepareingClear() {
super.changeUiToPrepareingClear()
mBottomContainer?.visibility = View.INVISIBLE
mProgressBar?.visibility = View.GONE
}
override fun changeUiToPlayingBufferingClear() {
super.changeUiToPlayingBufferingClear()
mBottomContainer?.visibility = View.INVISIBLE
mProgressBar?.visibility = View.GONE
}
override fun changeUiToClear() {
super.changeUiToClear()
mBottomContainer?.visibility = View.INVISIBLE
mProgressBar?.visibility = View.GONE
}
override fun changeUiToCompleteClear() {
super.changeUiToCompleteClear()
mBottomContainer?.visibility = View.INVISIBLE
mProgressBar?.visibility = View.GONE
}
override fun onAutoCompletion() {
super.onAutoCompletion()
mProgressBar?.progress = 0
}
override fun showWifiDialog() {
//直接播放不显示WIFI对话框
startPlayLogic()
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
mProgressBar?.progress = 0
mFullPauseBitmap = null
}
override fun onClick(v: View?) {
super.onClick(v)
}
override fun onCompletion() {
isPostBufferUpdate = false
}
override fun onSurfaceUpdated(surface: Surface) {
super.onSurfaceUpdated(surface)
if (mThumbImageViewLayout != null && mThumbImageViewLayout.visibility == View.VISIBLE) {
mThumbImageViewLayout.visibility = View.INVISIBLE
}
}
override fun onPrepared() {
super.onPrepared()
playListener?.onPlayEvent(PLAY_EVT_PLAY_LOADING)
}
private var isPostBufferUpdate = false
override fun onBufferingUpdate(percent: Int) {
super.onBufferingUpdate(percent)
if (!isPostBufferUpdate && percent == 0) {
isPostBufferUpdate = true
playListener?.onPlayEvent(PLAY_EVT_PLAY_BEGIN)
}
}
override fun onError(what: Int, extra: Int) {
super.onError(what, extra)
playListener?.onPlayEvent(PLAY_EVT_PLAY_ERROR)
isPostBufferUpdate = false
}
override fun setViewShowState(view: View?, visibility: Int) {
if (view === mThumbImageViewLayout && visibility != View.VISIBLE) {
return
}
super.setViewShowState(view, visibility)
}
override fun onSurfaceAvailable(surface: Surface) {
super.onSurfaceAvailable(surface)
mProgressBar?.visibility = View.GONE
if (GSYVideoType.getRenderType() != GSYVideoType.TEXTURE) {
if (mThumbImageViewLayout != null && mThumbImageViewLayout.visibility == View.VISIBLE) {
mThumbImageViewLayout.visibility = View.INVISIBLE
}
}
}
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_video_cover"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
</RelativeLayout>
<ImageView
android:id="@+id/start"
android:layout_width="56px"
android:layout_height="56px"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical" />
</RelativeLayout>