JZVideo icon indicating copy to clipboard operation
JZVideo copied to clipboard

上下滑动刚好某条视频在列表最后可见的底部时,出现黑屏但有声音的情况,请问如何解决

Open wammy-h opened this issue 4 years ago • 6 comments

jzvd7.7.0

JZMediaSystem.class

无报错log

demo中无视频和图文混合列表

RecyclerView列表滑动自动播放 视频和图文混合出现

上下滑动刚好某条视频在列表最后可见的底部时,出现黑屏但有声音的情况

android 10,vivo v1838a

**截图或者视频说明情况

wammy-h avatar Dec 01 '21 03:12 wammy-h

优先考虑是否复用问题。

Liberations avatar Dec 01 '21 06:12 Liberations

我禁止了复用还是有这个问题

wammy-h avatar Dec 01 '21 08:12 wammy-h

如果你是仿抖音的那种上下扒拉,我这边是这么做的.重点在那个滑动距离上,判断上下滑动50像素才算上下扒拉,这样就不会重新再去创建开始播放视频,而是JZVD的video还是原来那个.我估摸着大概可能也许是因为对同一个Jzvd没有销毁就直接在赋值使用造成的,但我在之前调用了Jzvd.releaseAllVideos()依旧没有生效,所以,如果有思路可以再回一下. `class NewViewPagerLayoutManager : LinearLayoutManager {

private var mPagerSnapHelper: PagerSnapHelper? = null
private var mListener: OnNewViewPagerListener? = null
private var mRecyclerView: RecyclerView? = null
private var mDrift = 0 //位移,判断移动方向

constructor(context: Context, orientation: Int) : super(context, orientation, false) {
    init()
}

constructor(context: Context, orientation: Int, reverseLayout: Boolean) : super(
    context,
    orientation,
    reverseLayout
) {
    init()
}

private fun init() {
    mPagerSnapHelper = PagerSnapHelper()
}

override fun onAttachedToWindow(view: RecyclerView?) {
    super.onAttachedToWindow(view)
    mPagerSnapHelper?.attachToRecyclerView(view)
    this.mRecyclerView = view
    mRecyclerView?.addOnChildAttachStateChangeListener(mChildAttachStateChangeListener)
}

private val mChildAttachStateChangeListener =
    object : RecyclerView.OnChildAttachStateChangeListener {
        override fun onChildViewAttachedToWindow(view: View) {
            if (mListener != null && childCount == 1) {
                mListener?.onInitComplete(view, getPosition(view))
            }
        }

        override fun onChildViewDetachedFromWindow(view: View) {
            if (mDrift > 50) {
                mListener?.onPageRelease(view, true, getPosition(view))
            } else if (mDrift < -50) {
                mListener?.onPageRelease(view, false, getPosition(view))
            }
        }
    }

override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) {
    super.onLayoutChildren(recycler, state)
    //
}

override fun onScrollStateChanged(state: Int) {
    when (state) {
        RecyclerView.SCROLL_STATE_IDLE -> {
            //空闲停止
            val view = mPagerSnapHelper?.findSnapView(this)
            val position = view?.let { getPosition(it) }
            if (mListener != null && childCount == 1) {
                if (position != null) {
                    mListener?.onPageSelected(view, position, position == itemCount - 1)
                }
            }
        }
        RecyclerView.SCROLL_STATE_DRAGGING -> {
            //缓慢拖拽
            val view = mPagerSnapHelper?.findSnapView(this)
            if (view != null) {
                val positionDrag = getPosition(view)
            }
        }
        RecyclerView.SCROLL_STATE_SETTLING -> {
            //快速滑动
            val view = mPagerSnapHelper?.findSnapView(this)
            if (view != null) {
                val positionSetting = getPosition(view)
            }
        }
    }
}

/**
 * 竖直方向偏移量
 */
override fun scrollVerticallyBy(
    dy: Int,
    recycler: RecyclerView.Recycler?,
    state: RecyclerView.State?
): Int {
    this.mDrift = dy
    return super.scrollVerticallyBy(dy, recycler, state)
}

/**
 * 水平方向偏移量
 */
override fun scrollHorizontallyBy(
    dx: Int,
    recycler: RecyclerView.Recycler?,
    state: RecyclerView.State?
): Int {
    this.mDrift = dx
    return super.scrollHorizontallyBy(dx, recycler, state)
}

/**
 * 设置监听
 */
fun setOnViewPagerListener(listener: OnNewViewPagerListener) {
    this.mListener = listener
}

}`

Caishuchun avatar Jan 18 '22 07:01 Caishuchun

我的是类似皮皮虾那种视频 图片 文字混合的列表 发现log中执行到onStatePlaying时textureViewContainer的宽高为0了 当我滑动列表中断视频播放后 在重新滑回来时 重复2到3次 就会出现此问题

wammy-h avatar Apr 12 '22 03:04 wammy-h

public void onStatePlaying() { Log.i(TAG, "onStatePlaying " + " [" + this.hashCode() + "] "); if(null!=textureViewContainer.getChildAt(0)){ Log.d(TAG, "让我看看你的宽"+textureViewContainer.getChildAt(0).getWidth()); Log.d(TAG, "让我看看你的高"+textureViewContainer.getChildAt(0).getHeight()); if(0==textureViewContainer.getChildAt(0).getWidth()&&0==textureViewContainer.getChildAt(0).getHeight()){ state = STATE_NORMAL; clickStart(); }else { if (state == STATE_PREPARED) {//如果是准备完成视频后第一次播放,先判断是否需要跳转进度。 Log.d(TAG, "onStatePlaying:STATE_PREPARED "); mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); if (seekToInAdvance != 0) { mediaInterface.seekTo(seekToInAdvance); seekToInAdvance = 0; } else { long position = JZUtils.getSavedProgress(getContext(), jzDataSource.getCurrentUrl()); if (position != 0) { mediaInterface.seekTo(position);//这里为什么区分开呢,第一次的播放和resume播放是不一样的。 这里怎么区分是一个问题。然后 } } } state = STATE_PLAYING; startProgressTimer(); } }

// if (state == STATE_PREPARED) {//如果是准备完成视频后第一次播放,先判断是否需要跳转进度。 // Log.d(TAG, "onStatePlaying:STATE_PREPARED "); // // Log.d(TAG, "让我看看你的宽"+textureViewContainer.getChildAt(0).getWidth()); // Log.d(TAG, "让我看看你的高"+textureViewContainer.getChildAt(0).getHeight()); // // mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); // mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); // if (seekToInAdvance != 0) { // mediaInterface.seekTo(seekToInAdvance); // seekToInAdvance = 0; // } else { // long position = JZUtils.getSavedProgress(getContext(), jzDataSource.getCurrentUrl()); // if (position != 0) { // mediaInterface.seekTo(position);//这里为什么区分开呢,第一次的播放和resume播放是不一样的。 这里怎么区分是一个问题。然后 // } // } // } // state = STATE_PLAYING; // startProgressTimer(); }

wammy-h avatar Apr 12 '22 03:04 wammy-h

2022-04-12 10:59:04.230 20025-20025/com.gtgy.countryn D/JZVD: 让我看看你的宽0 2022-04-12 10:59:04.230 20025-20025/com.gtgy.countryn D/JZVD: 让我看看你的高0

wammy-h avatar Apr 12 '22 03:04 wammy-h