android MediaPlayer TextureView 视频列表播放

需求: 实现视频列表的自动播放,无需用户操作。

在使用Texture遇到一个问题。在RK3288 盒子上,直接AndroidStudio 运行app 播放正常,退出到桌面再次打开还是正常播放。。但是当我打包之后,安装apk运行,重复之前的操作就会频繁出现有声音没有画面的bug。。。

猜想: 就是姿势不对呗,反正就是一顿瞎捣鼓。

kotlin 代码如下,有些无用代码就懒得删除了。
播放帮助类

class MyPlayerHelper {

    companion object {
        const val TAG = "MyPlayerHelper"
        val shared: MyPlayerHelper by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            MyPlayerHelper()
        }
    }

    enum class PlayStatus {
        stop,
        playing,
        paused
    }

    private var mediaPlayer: MediaPlayer? = null
    private var curStatus: PlayStatus = PlayStatus.stop
    private var ltVideoWrapper: LinearLayout? = null
    private var lastPosition: Int = 0


    private var mSurface: Surface? = null
    private var videoList: ArrayList
    /***
     * 增加监听
     */
    private fun addSurfaceTextureListener() {
        textureView?.surfaceTextureListener = object : TextureView.SurfaceTextureListener {
            override fun onSurfaceTextureAvailable(
                surface: SurfaceTexture,
                width: Int,
                height: Int
            ) {
                AppHelper.logD(MyPlayerHelper.TAG, "onSurfaceTextureAvailable")
                MyPlayerHelper.shared.startPlay(surface)
            }

            override fun onSurfaceTextureSizeChanged(
                surface: SurfaceTexture,
                width: Int,
                height: Int
            ) {
                AppHelper.logD(MyPlayerHelper.TAG, "onSurfaceTextureSizeChanged")
            }

            override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {
                AppHelper.logD(MyPlayerHelper.TAG, "onSurfaceTextureDestroyed")
                MyPlayerHelper.shared.stopPlay()
                return true
            }

            override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {

//                MyPlayerHelper.shared.updateSurfaceTexture(surface)
            }

        }

    }

你可能感兴趣的:(android MediaPlayer TextureView 视频列表播放)