Reputation: 11
I would like to know what code to write in order to show the status bar at the top while a video is being played in full screen mode. I've tried everything that has come to mind but the status bar still becomes hidden when the video starts playing.
Here is the current viewcontroller code:
import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
var playerController = AVPlayerViewController()
var player:AVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
let videoString:String? = Bundle.main.path(forResource: "Buspro", ofType: ".mp4")
if let url = videoString {
let videoURL = NSURL(fileURLWithPath: url)
self.player = AVPlayer(url: videoURL as URL)
self.playerController.player = self.player
}
}
@IBAction func Play(_ sender: Any) {
self.playerController.showsPlaybackControls = false
self.present(self.playerController, animated: true, completion: {
self.playerController.player?.play()
})
}
}
Upvotes: 0
Views: 778
Reputation: 6067
AVPlayerViewController is UIViewController Just subclass and override prefersStatusBarHidden
create New file CustomAVPlayerViewController.Swift
import UIKit
import AVKit
class CustomAVPlayerViewController: AVPlayerViewController {
override var prefersStatusBarHidden: Bool {
return false
}
}
Then At your code:
import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
var playerController = CustomAVPlayerViewController()
var player:AVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
let videoString:String? = Bundle.main.path(forResource: "Buspro", ofType: ".mp4")
if let url = videoString {
let videoURL = NSURL(fileURLWithPath: url)
self.player = AVPlayer(url: videoURL as URL)
self.playerController.player = self.player
}
}
@IBAction func Play(_ sender: Any) {
self.playerController.showsPlaybackControls = false
self.present(self.playerController, animated: true, completion: {
self.playerController.player?.play()
})
}
}
Upvotes: 2