PierfrancescoSoffritti / android-youtube-player

YouTube Player library for Android and Chromecast, stable and customizable.
https://pierfrancescosoffritti.github.io/android-youtube-player/
MIT License
3.44k stars 765 forks source link

Problem #1135

Closed Vatsal3009 closed 6 months ago

Vatsal3009 commented 7 months ago

Question / Problem

Summary

Hello,

In my project, the requirement is to simply display a YouTube video with a play icon. I believe this feature is not available in the current library.

What I've tried

Now i just load video using if and pause this video and manage my issue.

PierfrancescoSoffritti commented 7 months ago

I don't understand what the issue is. This library provides a Youtube Player to play Youtube videos.

MahmoudMabrok commented 7 months ago

@Vatsal3009 do you mean that view initially display play icon, then video starts when user click on play icon ? also, you can share a design/screenshot from what exactly needed

Vatsal3009 commented 7 months ago

Screenshot from 2024-04-26 16-20-51

I'd like to display a view like this in my RecyclerView using our library, where the video plays automatically. However, I need the ability to pause the video afterward. I've noticed there's an "app:autoPlay=false" attribute, but it doesn't seem to be working. Please let me know if you need any further information from my end. Thank you for your response!

I have use below code

binding?.playerView?.addYouTubePlayerListener(object : AbstractYouTubePlayerListener() { override fun onReady(@NonNull youTubePlayer: YouTubePlayer) { item.source?.let { youTubePlayer.loadVideo(it, 0f) youTubePlayer.pause() } } })

MahmoudMabrok commented 6 months ago

@Vatsal3009 you can use cueVideo instead of mix of "load & pause".

I tried now, and youTubePlayer.cueVideo(it. 0f) worked as you want.

Vatsal3009 commented 6 months ago

20240429_111021

Hello @MahmoudMabrok ,

Thank you for your resposne. I have check with "cueVideo" but as you can see in the screenshort by using this first time it will take 1-2 sec to display image and after scroll the recyclerview and again go bottom to top than it will show error in player view in most of the video. can you help me with this ?