我希望状态栏在全屏视频播放期间可见
I want the status bar to be visible during full screen video playback
我想知道要写什么代码才能在全屏模式下播放视频时在顶部显示状态栏。我已经尝试了所有想到的方法,但是当视频开始播放时状态栏仍然隐藏。
这是当前的 viewcontroller 代码:
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()
})
}
}
AVPlayerViewController 是 UIViewController 只是子类化和覆盖 prefersStatusBarHidden
创建新文件CustomAVPlayerViewController.Swift
import UIKit
import AVKit
class CustomAVPlayerViewController: AVPlayerViewController {
override var prefersStatusBarHidden: Bool {
return false
}
}
然后在您的代码处:
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()
})
}
}
我想知道要写什么代码才能在全屏模式下播放视频时在顶部显示状态栏。我已经尝试了所有想到的方法,但是当视频开始播放时状态栏仍然隐藏。
这是当前的 viewcontroller 代码:
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()
})
}
}
AVPlayerViewController 是 UIViewController 只是子类化和覆盖 prefersStatusBarHidden
创建新文件CustomAVPlayerViewController.Swift
import UIKit
import AVKit
class CustomAVPlayerViewController: AVPlayerViewController {
override var prefersStatusBarHidden: Bool {
return false
}
}
然后在您的代码处:
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()
})
}
}