Tuesday, November 5, 2019

Add Loading ActivityIndicator in AVPlayer Video iOS Swift 5



This week, I want to show loading after I have a video player that uses AVPlayer library. If you're curious like me. Stay tuned in this blog or if you're in hurry just scrolling on bottom. I must've given the source code. If you're an expert it must be easy to follow.

So if you don't use playback controller library AVPlayerViewController. I mean maybe you use AVPlayer Layer. It's basically it doesn't have playback controls. It's good to use loading Activity Indicator so the user will have a good expierence to operate our app.

So basically the AVplayer itself has a loading indicator beside play/pause button as you can see on above image. But it's not enough for me because it's too little, I need something on center like I do in UIImageview or loading something like loading API.

And the problem with AVPlayer, it doesn't have delegation to perform loading action so we need to use observer to do it. And don't forget to add the ActivityIndicator itself. Define it on public class but it doesn't matter if it is in method class.






This is code that I mean.



So it's not hard to implement if you know the code right lol. And on google not all the code working so we have to try it one by one. But in this articale I make sure this code working properly in Swift iOS 13.2.

So first you need to initialize the observer in viewDidAppear. Then you need to override observerValue. The code itself is self-explain. So If you have any question please feel free to ask my friends. Thanks for visiting my simple blog.

No comments:

Post a Comment