如果视频媒体文件不可用,我试图用ImageView替换ExoPlayer2视图。

    if(stepVideo != null) {
        mPlaceHolderIv.setVisibility(View.GONE);
        exoPlayerView.setVisibility(View.VISIBLE);
        initializePlayer(Uri.parse(stepVideo));
        //initialize MediaSession
        initializeMediaSession();
    } else if(stepThumbUrl != null) {
        mPlaceHolderIv.setVisibility(View.GONE);
        exoPlayerView.setVisibility(View.VISIBLE);
        initializePlayer(Uri.parse(stepThumbUrl));
        //initialize MediaSession
        initializeMediaSession();
    } else {
        exoPlayerView.setVisibility(View.GONE);
        releasePlayer();
        mPlaceHolderIv.setVisibility(View.VISIBLE);
        Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(mPlaceHolderIv);
    }


我知道其他人正在被调用,因为正在显示占位符图像。但是,播放控件仍然可见。我已经尝试了所有答案here,但仍然显示控件视图(播放,暂停等)。有任何想法吗?

注意:我已经用标签为exo_playback_control_view.xml的文件覆盖了自定义控件。

编辑:修复了视图消失时显示控件的问题,但是新问题是为什么SimpleExoPlayerView的xml需要具有app:use_controller="false",然后在初始化时在Java中将其设置为true,而在发布时再次设置为false?为什么控件视图没有在其余的SimpleExoPlayerView中消失?

最佳答案

不确定这是否有帮助,但是如果您只想用另一个视图替换视图,为什么不使用ViewSwitcher或ViewAnimator?

这两个子视图(占位符和播放器视图/布局)将在您之间切换,然后调用showNext切换到另一个视图。

您还可以使用以下出色的帮助器功能:

fun ViewAnimator.setViewToSwitchTo(viewToSwitchTo: View, animate: Boolean = true): Boolean {
    if (currentView === viewToSwitchTo)
        return false
    for (i in 0 until childCount) {
        if (getChildAt(i) !== viewToSwitchTo)
            continue
        if (animate)
            displayedChild = i
        else {
            val outAnimation = this.outAnimation
            val inAnimation = this.inAnimation
            this.inAnimation = null
            this.outAnimation = null
            displayedChild = i
            this.inAnimation = inAnimation
            this.outAnimation = outAnimation
        }
        return true
    }
    return false
}

fun ViewAnimator.setViewToSwitchTo(@IdRes viewIdToSwitchTo: Int, animate: Boolean = true): Boolean {
    if (currentView.id == viewIdToSwitchTo)
        return false
    for (i in 0 until childCount) {
        if (getChildAt(i).id != viewIdToSwitchTo)
            continue
        if (animate)
            displayedChild = i
        else {
            val outAnimation = this.outAnimation
            val inAnimation = this.inAnimation
            this.inAnimation = null
            this.outAnimation = null
            displayedChild = i
            this.inAnimation = inAnimation
            this.outAnimation = outAnimation
        }
        return true
    }
    return false
}

关于android - 如何隐藏所有的ExoPlayer2?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51037463/

10-09 03:40