Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black Screen while move next video in Recycleview #188

Open
tyagnesh-mufin opened this issue Feb 10, 2023 · 16 comments
Open

Black Screen while move next video in Recycleview #188

tyagnesh-mufin opened this issue Feb 10, 2023 · 16 comments

Comments

@tyagnesh-mufin
Copy link

[Current Version]
com.google.android.exoplayer:exoplayer:2.17.1
im.ene.kohii:kohii-core:1.4.0.2017001
im.ene.kohii:kohii-exoplayer:1.4.0.2017001

[Problem]
Black Screen within 2-3 seconds while move next video in Recycleview also same in viewpager

[Expected Result]
Can we Load upcoming video so we can preview immediately without black screen

[Code]
Fragment

kohiiManager = kohii.register(this@FullVideoListFragment, MemoryMode.BALANCED).addBucket(getBinding().fullVideoListList)
customAdapter = FullVideoListAdapter(kohii)  

FullVideoListAdapter

kohii.setUp(videoUrl){
                    tag = "${photoUrl}+${adapterPosition}"
                    preload = true
                    repeatMode = Player.REPEAT_MODE_ALL
                    controller = controller(kohiiCanStart = true, kohiiCanPause = true) { playback, _ ->
                        val playable = playback.playable ?: return@controller

                        binding.root.setOnClickListener {
                                        if (playable.isPlaying()) playback.manager.pause(playable)
                                        else playback.manager.play(playable)

                        }
                    }
                }.bind(binding.exoplayerView)
@lantmtekup
Copy link

You should change MemoryMode.BALANCED to "MemoryMode.HIGH"

@tyagnesh-mufin
Copy link
Author

@lantmtekup Thanks for replay, i have also try with MemoryMode.HIGH but i can't see any changes on output

@eneim
Copy link
Owner

eneim commented Feb 14, 2023

Hi @t-yagnesh let me take a look.

By the way, is it possible for you to reproduce the issue using the sample code? It is Ok if not, but it is helpful for me to reproduce it though.

@tyagnesh-mufin
Copy link
Author

android-recording-14-feb-2023_Ay57jdI0.mp4

@eneim i have try with your tiktok-sample you can check in my video, when i scroll to next video every time display black screen

[My Expectation]
Can we Load upcoming video in cache so we can preview immediately without black screen

@eneim
Copy link
Owner

eneim commented Feb 14, 2023

@t-yagnesh Thanks. Can you share your device model and Android OS? I will see what can be done and what may affect the settings. And if it is not private, can you share the URL you used in this demo? (You can send them via email if needed -> nam@ene.im).

@tyagnesh-mufin
Copy link
Author

@eneim
Device : Vivo y15c
Os : Android 12

@tyagnesh-mufin
Copy link
Author

@eneim you can check your sample code apk with my video url, https://drive.google.com/file/d/1ASuimB-9meXDW2KQNdIKSG81Nh3MoohN/view?usp=sharing

@eneim
Copy link
Owner

eneim commented Feb 15, 2023

@t-yagnesh First, it seems to work fine on my test (Pixel 6, Android 13). There is of course a blink of black screen where the video frame is pushed when it is visible, but not as bad as your example.

kohii_issue_188.mp4

I think there are a couple of factors to investigate:

  • Slow loading may cause the black screen because there is not enough buffer to render the frame. Try eliminating the dependency of networking by using offline files (put videos to your assets folders, and access them via Uri) to see if it works better for you. In my test, I limit the device to 5Mbps which may be slow enough. Though I cannot know your testing environment to make any comment. But please try with offline file, to see if the black screen still happen.
  • If you use PlayerView in the xml, try using surface_type of texture_view. It is less performant, but it helps with smoother rendering in some case like this.

Also:

  • If you own the video server, please try some coding parameters so that: using hls or dash to speed up the load by using multiple resolutions. If you are using AVC/HEVC: use more key-frame so that the video can be ready faster (the video size may be increased, so it is kinda a balance problem).

  • If you do not own the video server, and need to access 3rd party video source without any control, I may not be able to help. Maybe in the future, I can integrate the cold download feature so you can pre-download the videos to storage even before the timeline is shown.

@tyagnesh-mufin
Copy link
Author

@eneim I am creating social media platform in which any register user can upload video with any format, so i need to always load video from url

if possible can you give me example source code regarding this point currently i am using "com.google.android.exoplayer2.ui.PlayerView" in adapter xml

If you use PlayerView in the xml, try using surface_type of texture_view. It is less performant, but it helps with smoother rendering in some case like this.

@eneim
Copy link
Owner

eneim commented Feb 15, 2023

What I commented is about finding the root cause. And since you own the video server, please read through the comment, and research about how to optimize the video encoding strategy to make it load faster.

In the VideoViewHolder file of the TikTok sample, you can navigate to the layout and find the text "surface_type". Change it to "texture_view". It is a normal Android View component and the "surface_type" is an attribute with predefined values.

@tyagnesh-mufin
Copy link
Author

@eneim Got it, Thank you for your support

@tyagnesh-mufin
Copy link
Author

hi @eneim

i have updated video formate as HLS with m3u8 based on multiple resolutions still i got black screen when i scroll to nextvideo

i want to load/prepare upcoming item in recycleview, regarding this i have ask to chatGPT

Can you explain me this coding please, i got this example code from chatGPT

Code : https://dpaste.org/B4SVa

i can't able to add this code i think it's not compatible with latest kohii version

@tyagnesh-mufin tyagnesh-mufin reopened this Apr 5, 2023
@tyagnesh-mufin
Copy link
Author

hi @eneim

i have updated video formate as HLS with m3u8 based on multiple resolutions still i got black screen when i scroll to nextvideo

i want to load/prepare upcoming item in recycleview, regarding this i have ask to chatGPT

Can you explain me this coding please, i got this example code from chatGPT

Code : https://dpaste.org/B4SVa

i can't able to add this code i think it's not compatible with latest kohii version

@eneim
Copy link
Owner

eneim commented Apr 6, 2023

@t-yagnesh Does your issue reproducible using the URLs in this repo (this one --> https://github.com/eneim/kohii/blob/a8ed5788a28f3ed8e4580bcc8f41849bc768ce2c/kohii-sample-tiktok/src/main/assets/caminandes.json)? Because I cannot reproduce the issue with it.

If it happens with your videos, then that is definitely the bottleneck. Merely changing the file is not the root cause. Please double check how fast you can download your video using something else. If you have the link to your HLS, I can give it a try, but again please make sure your video is light enough. And also check your network connection and so on. Kohii doesn't help speed up your download speed if it is slow.

@tyagnesh-mufin
Copy link
Author

@eneim please check in attached video, i have added first 3 video url from your repo json file

android-recording-06-apr-2023_3U0f1hvs.mp4

still display black screen while scroll to next video

@eneim
Copy link
Owner

eneim commented Apr 6, 2023

@t-yagnesh What you really should do is to get the playback status, or network activity. The 1st and 2nd video has the black frame by itself. And I think you can see in your video that the 3rd, 4th, 5th video start playback instally. I think it is not that the library or the app doesn't work. Even if you download the video before hand, the scroll speed can impact that.

Screen.Recording.2023-04-06.at.22.34.35.mov

I think if you can customize ExoPlayer to download and render it really fast, then you can provide it to the library's Pool to make it work the way you want. If this is the limitation of ExoPlayer, then I cannot do anything better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants