Player Bar Part 1

We have a player but there's currently no way to bring it back up after dismissing it. In this episode we'll design a persistent player bar that will control the player and will be allowed to live outside its view controller.

Designing the Player Bar

We will start by creating a subclass for the player bar. In the storyboard we will create a view and drag it under the "Player View Controller Scene", this will create a reference. We will set the width and height of the view based on the screen width.

Next, we will add an image view, and a button to open up the player. To enable the voice over functionality we will set the accessibility label on the button.

Next we will add a skip back, skip forward and play/pause buttons along with the image and open up button in a stack view, embedded them in a view and update their constraints.

UIView Settings Of Player Bar

We will now create the two outlets for the image view and Play/Pause button. We will set the rounded corners to the image view by setting the cornerRadius and clipToBounds properties. Also to make the view available in the entire application we will install the player view on the top of the tab bar and set its background color to clear.

To maintain the consistency between the play/pause button in the player view controller and player bar, we will set image and image view of the play/pause button in the player bar with similar settings used in playerViewController.

Next we will set the visibility of the player bar just before we start playing the player bar. We use asyncAfter 1 second here to allow the player to be presented first before we show the player bar. Doing so eliminates a distracting flash of UI during the player view controller presentation.

Finally, we need to have a reference to some view controller that we can present from, since the player bar button can be tapped from anywhere. We will create an optional weak reference of UIViewController to set the state of the player bar in other application. We will then hook up the open player button to the presentPlayer action in playerViewController using our storyboard.