I'm developing custom audio player for streaming music for my app and I need it to be present on every screen in my app at the bottom. For this I used UIContainerView
and later xib
but faced same issue in both cases:
AudioPlayer
- time presented in label and progress bar don't get updated, however music is playing.Moreover, if I press play after segue was performed in that container with player audio starts to play another track together with previous playing.
At this point I have developed player and it's working fine only in one VC.
My question is how to make it work on every screen?
Structure of my app: 7 VC connected with segues and at the bottom of each screen there's container view connected to one VC with player.
Thanks in advance for your help!
Each time you use a segue, you are loading a new view on top of your old view- which is why you can hear the audio playing still playing in a hidden view.
When you segue back and forth between views, you are not actually moving back and forth between views, you are loading new views on top of of old views- and this can cause serious problems as your app grows and gets more complicated.
So I would change the structure of the app, instead of 7 VC connected by Segues- have 1 Master VC with a large container view and load those 6 other VCs into the container view.
Start off by creating a new view controller on the Storyboard, and put a container view in your new View Controller. Have the Container fill up most of the view except where your music player will be. Delete the View Controller that was created by dragging the Container in- you don't need it.
To make this real easy, drag a navigation controller onto your Storyboard, its going to spawn 2 views, but go ahead and delete the table view. Control+Drag from the ContainerView to the Navigation controller, and select the "Embed" option. Then control drag from the navigation controller to your original main ViewController and select the "Root View Controller". Now when you click on a segue within the container- it will just change the view in the container.