adamzarn / AZVideoPlayer

An alternative to SwiftUI's VideoPlayer that includes an overlay button that will transition the player to be presented full screen.
26 stars 5 forks source link

README example - init run multiple times #5

Open fidesachates opened 11 months ago

fidesachates commented 11 months ago

I used the example code (the Advanced Ussage one) from the README and modified it slightly to add on a .onAppear{self.player?.play). When you I did this, I noticed something interesting. Sometimes video will start playing (you can hear the audio), but the video isn't playing. I deduced this to be because the init is actually run multiple times ( in my case 3 times ) and the .onAppear will run in between inits (meaning the video that's playing not actually shown in the view). I googled around and found support for my diagnosis.

I modified the code to store the url in the init and then in the onAppear, I create the AVPlayer if it's nil. This solved my problem. Wondering if this was the right thing to do and warrants a PR to fix the example in the README.

Thanks again for writing this library! Really useful especially to those of us learning swift for fun in our spare time!

adamzarn commented 11 months ago

@fidesachates The example works if you don't start playback in .onAppear and just allow the user to play/pause with the playback controls.

I did try to reproduce your issue but haven't seen the init called multiple times. I'm assuming there is something else about the way you're using the AZVideoPlayer that is causing the issue.