youtube / youtube-ios-player-helper

Lightweight helper library that allows iOS developers to add inline playback of YouTube videos through a WebView
Other
1.64k stars 677 forks source link

Need DispatchQueue.main.asyncAfter(.now() + 1) before playVideo works #460

Open ristkof opened 2 years ago

ristkof commented 2 years ago

I embedded the view in a UIViewController that is presented full screen.

When I call load(withVideoId:"xxxxx") and immediately call playVideo(), this does not work upon first presentation. Successive presentations of the view controller do work though.

My workaround is to do DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self.ytView.playVideo() }

This is hacky though, it looks like something needs loading for about 1 second on my network connection before the playVideo works. I tried looking at the states I receive in the delegates after calling load(withVideoId:), but... I get no state changes on first load.

Am I doing it wrong or is this a bug?

brol1dev commented 2 years ago

Hi @ristkof ,

We will try to reproduce this one and come up with a solution if we identify there is an issue. Thanks for filing the issue!

jasonszheng commented 2 years ago

Hi @ristkof issue is reproduced; however, taking advantage of

You are right that the player needs to load before the view is able to receive api calls. Please call playVideo from within this delegate method.