Swift AVPlayerViewController 删除音频和字幕按钮

Swift AVPlayerViewController Remove Audio & Subtitles Button

我想在使用 AVPlayerViewController 时删除音频和字幕按钮。我按如下方式创建控制器:

// Create the view controller and player
let moviePlayerViewController: AVPlayerViewController = AVPlayerViewController()
let moviePlayer = AVPlayer(url: videoUrl!)

// Initialize the AVPlayer
moviePlayerViewController.player = moviePlayer
moviePlayerViewController.player?.isClosedCaptionDisplayEnabled = false

// Present movie player and play when completion
self.present(moviePlayerViewController, animated: false, completion: {
    moviePlayerViewController.player?.play()
})

我以为 moviePlayerViewController.player?.isClosedCaptionDisplayEnabled = false 会帮我移除按钮,但我错了。谁能帮我找到隐藏音频和字幕按钮的正确设置?

根据 official doc,您无法在默认播放器布局上隐藏音频和字幕按钮。如果您坚持要删除该按钮,请尝试自定义您自己的播放器,或修改 .m3u8 文件以删除多余的字幕选项。