iielse / imageviewer

A simple and customizable Android full-screen image viewer 一个简单且可自定义的Android全屏图像浏览器
MIT License
2.23k stars 310 forks source link

您好,请问当中的视频播放器怎么实现全屏播放 #137

Closed SoloLee closed 2 years ago

SoloLee commented 2 years ago

您好,请问这个库当中的视频播放器怎么实现全屏播放

iielse commented 2 years ago

额,在你问这个问题前,我就实现了这个功能,最新代码里面有。 等我发个版

iielse commented 2 years ago

我本来是打算有bug,或者有人提到需要的时候再发,结果才没一天就有人需要了

iielse commented 2 years ago

implementation 'com.github.iielse:imageviewer:2.1.18' 具体使用方法看demo. demo下方有6个按钮,第一排第二个 找个合适的位置设置下 com.github.iielse.imageviewer.utils.Config.VIDEO_SCALE_TYPE = ExoVideoView.SCALE_TYPE_XXX 如果想对单个ExoVideoView特殊配置调用setScaleType方法

SoloLee commented 2 years ago

implementation 'com.github.iielse:imageviewer:2.1.18' 具体使用方法看demo. demo下方有6个按钮,第一排第二个 找个合适的位置设置下 com.github.iielse.imageviewer.utils.Config.VIDEO_SCALE_TYPE = ExoVideoView.SCALE_TYPE_XXX 如果想对单个ExoVideoView特殊配置调用setScaleType方法

OK,感谢,我试试

SoloLee commented 2 years ago

设置scaleType属性,就会把视频画面给裁剪了。 我的想法实现是类似 腾讯等视频 从竖屏小窗口变为横屏大窗口后全屏播放,视频画面不会被裁剪。是不是需要对ExoVideo进行配置?我暂时还没找到ExoVideo配置的api。

iielse commented 2 years ago

横屏大窗口这个只需要新开一个Activity来播放.退出Activity的时候同步video播放的时间轴状态即可

SoloLee commented 2 years ago

嗯,nice!感谢

iielse commented 2 years ago

有个具体的思路你可以尝试 VideoViewHolder 下的 exoVideoView 被点击时刻,将exoVideoView和他的parent脱离,保存到静态变量中 新开的Activity在onCreate时刻 将 exoVideoView粘到新的parent上. 同时将老的parent放在弱引用中保留 在FullVideoActivity finish的时刻,将exoVideoView和他新的parent再次脱离,如果之前的parent还在内存中 粘回之前的parent上.同时将引用置空

这样的好处就是没有创建新的 exoVideoView. 过程始终是一个实例,性能和体验方面当是上佳之选。 伪代码如下:

exoVideoView.setOnClickListener {
    FullVideoActivity.start(it.context, it)
}

class FullVideoActivity extends Activity {
     static WeakRef<ViewGroup> weakRefVideoViewParent;
     static ExoVideoView videoView;

     onCreate() {
         requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
         val view = videoView ?: returnAndFinish()
         weakRefVideoViewParent.put(view.parent)
         view.parent.remove(view)
         contentView.addView(view)
     }

     finish() {
         val view = videoView ?: return
         view.parent.remove(view)
         weakRefVideoViewParent?.get()?.add(view)
         weakRefVideoViewParent = null
     }

     static fun start(Context context, VideoView view) {
            videoView = view
            context.startActivity()
     }
}
iielse commented 2 years ago

不过我写的ExoVideoViewonDetachedFromWindow 的时候会release. 这里还需要提供个变量来控制是否自动release ...

iielse commented 2 years ago

@SoloLee 看下最新代码, 我顺手实现了这个功能,你照着demo抄即可

SoloLee commented 2 years ago

@SoloLee 看下最新代码, 我顺手实现了这个功能,你照着demo抄即可

呀,非常感谢

SoloLee commented 2 years ago

非常感谢,思路有了。赞