Skip to content

pausing video shows black screen instead of video frame #196

Open
@rahul-sysquare

Description

Hi all,

I'm using framelayout to show/render videos in my recyclerview. The issue is when I pause the video I'm getting a black screen over the video instead of video frame itself. Anyone knows any fix?

Here is the code

kohii.setUp(media.getMediaUrl()) {
                    tag = "video::$position"
                    threshold = 0.5F
                    preload = true
                    repeatMode = Player.REPEAT_MODE_ONE
                    controller = object : Playback.Controller {
                        override fun kohiiCanStart(): Boolean = true
                        override fun kohiiCanPause(): Boolean = true
                        override fun setupRenderer(playback: Playback, renderer: Any?) {
                            binding.playerContainer.setOnClickListener {
                                binding.playIcon.visibility = View.VISIBLE
                                Handler().postDelayed({
                                    binding.playIcon.visibility = View.GONE
                                    //doSomethingHere()
                                }, 1000)
                                val playable = playback.playable ?: return@setOnClickListener
                                
                                if (playable.isPlaying()) {
                                    Log.d("Paying1111", "pause"+holder.binding.container.isVisible)
                                    playback.manager.pause(playable)
                                    binding.playIcon.setImageResource(R.mipmap.video_play_icon)
                                } else {
                                    binding.playIcon.setImageResource(R.mipmap.timeline)
                                    Log.d("Paying1111", "play"+holder.binding.container.isVisible)
                                    playback.manager.play(playable)
                                }
                            }
                            val volume = holder.binding.muteButton as ImageButton
                            volume.isSelected = playback.volumeInfo.mute
                            volume.setOnClickListener {
                                volume.isSelected = !playback.volumeInfo.mute
                                kohii.applyVolumeInfo(
                                    VolumeInfo(mute = !playback.volumeInfo.mute),
                                    playback.manager,
                                    Scope.GLOBAL
                                )
                            }
                            val fullScreen = holder.binding.fullScreen as ImageButton
                            fullScreen.setOnClickListener {
                                val intent = Intent(mContext, VideoPlayerActivity::class.java)
                                val bundle = Bundle().apply {
                                    putParcelable(Constants.URL, media.uri)
                                    putLong("playbackPosition", /*playback.manager?.currentPosition ?: 0*/
                                        0L
                                    )
                                    putInt("currentWindow", position ?: 0)
                                }
                                intent.putExtra(Constants.DATA, bundle)
                                intent.putExtra(Constants.MODEL, media)
                                intent.putExtra(Constants.POST_ID, postModel.postId)
                                intent.putExtra("itemPosition", position)
                            }

                        }

                    }
                }.bind(binding.container);

Here is the XML file code

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <variable
            name="avm"
            type="com.buddynation.dronenation.view.newsfeed.modal.VideoPostViewModal" />

        <import type="android.view.View" />
    </data>

    <FrameLayout
        android:id="@+id/parent_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:orientation="vertical">

            <include
                layout="@layout/post_item_header"
                app:avm="@{avm}" />

            <com.buddynation.dronenation.view.custom.TextViewRegular
                android:id="@+id/postText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/post_margin_left"
                android:layout_marginRight="@dimen/post_margin_left"
                android:layout_marginBottom="10dp"
                android:paddingLeft="2dp"
                android:textColor="@color/white"
                android:textSize="@dimen/post_title_text_size" />

           
            <com.google.android.exoplayer2.ui.AspectRatioFrameLayout
                android:id="@+id/playerContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="4dp"
                android:clickable="true"
                android:focusable="true"
                android:minHeight="240dp"
                app:resize_mode="fixed_width">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <ImageView
                        android:id="@+id/postImage"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_gravity="center"
                        android:paddingTop="4dp"
                        android:paddingBottom="4dp"
                        app:loadMediaPhoto="@{avm.mediaPhoto}" />

                    <FrameLayout
                        android:id="@+id/container"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_gravity="center"
                        app:setVideoViewHeight="@{avm.mediaPhoto}" />

                    <androidx.appcompat.widget.AppCompatImageView
                        android:id="@+id/playIcon"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:adjustViewBounds="true"
                        android:gravity="center"
                        android:src="@mipmap/video_play_icon"
                        android:tint="@color/white"
                        android:visibility="gone"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent" />

                    <ProgressBar
                        android:id="@+id/indeterminateBar"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:indeterminateTint="@color/yello"
                        android:visibility="gone" />
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="end">

                    <ImageButton
                        android:id="@+id/muteButton"
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:backgroundTint="@color/transparent"
                        android:padding="4dp"
                        android:src="@drawable/mute_unmute" />

                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="bottom|end">

                    <ImageButton
                        android:id="@+id/fullScreen"
                        android:layout_width="48dp"
                        android:layout_height="48dp"
                        android:padding="4dp"
                        android:backgroundTint="@color/white"
                        android:src="@drawable/fullscreen_no_white" />

                </RelativeLayout>

            </com.google.android.exoplayer2.ui.AspectRatioFrameLayout>

            <include
                layout="@layout/post_item_footer"
                app:avm="@{avm}" />

            <include
                android:id="@+id/lastMessage"
                layout="@layout/post_item_last_comment"
                app:avm="@{avm}" />

            <include
                layout="@layout/post_item_write_comment"
                app:avm="@{avm}" />
        </LinearLayout>
    </FrameLayout>
</layout>

Here are the screenshots
Screenshot_1721319002
Screenshot_1721319005

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions