- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用以下代码在我的 Swift 应用程序 (iOS 9) 中播放视频:
let fileUrl = NSBundle.mainBundle().URLForResource("welcome", withExtension: ".mp4")
videoItem = AVPlayerItem(URL: fileUrl!)
videoPlayer = AVPlayer(playerItem: videoItem)
videoPlayer.addObserver(self, forKeyPath: "rate", options: [.New], context: nil)
videoPlayerController.player = videoPlayer
videoPlayerController.showsPlaybackControls = false
videoPlayerController.view.frame = CGRectMake(0, 0, playerView.frame.size.width, playerView.frame.size.height)
playerView.insertSubview(videoPlayerController.view, belowSubview: videoCoverView)
videoPlayerController.willMoveToParentViewController(self)
addChildViewController(videoPlayerController)
videoPlayerController.didMoveToParentViewController(self)
playerView.bringSubviewToFront(btnPlay)
let asset = AVAsset(URL: fileUrl!)
let imageGenerator = AVAssetImageGenerator(asset: asset)
let time = CMTime(seconds: asset.duration.seconds/2.0, preferredTimescale: 1)
do {
let imageRef = try imageGenerator.copyCGImageAtTime(time, actualTime: nil)
let coverImage = UIImage(CGImage: imageRef)
videoCoverView.image = coverImage
} catch {
}
videoPlayerController
是 AVPlayerViewController
的实例。 playerView
是通过 Storyboard添加的,并在其上设置了自动布局。一旦 AVPlayerViewController 的播放器控件出现,以及当我尝试通过播放器控件进入全屏模式时,我都会遇到 Autloayout 问题。这是打印的日志。
2016-05-07 15:18:19.325 VoxTrain[2085:66307] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x7fb6a2a3f2c0 h=-&- v=-&- _UIBackdropContentView:0x7fb6a2a02310.width == _UIBackdropView:0x7fb6a053bf90.width>",
"<NSLayoutConstraint:0x7fb6a2992800 H:|-(14)-[UILabel:0x7fb6a2991220'Hi-Speed Scrubbing'] (Names: '|':_UIBackdropContentView:0x7fb6a2a02310 )>",
"<NSLayoutConstraint:0x7fb6a2992850 H:[UILabel:0x7fb6a2991220'Hi-Speed Scrubbing']-(14)-| (Names: '|':_UIBackdropContentView:0x7fb6a2a02310 )>",
"<NSLayoutConstraint:0x7fb6a29649a0 H:|-(0)-[_UIBackdropView:0x7fb6a053bf90] (Names: '|':UIView:0x7fb6a0549220 )>",
"<NSLayoutConstraint:0x7fb6a298b8a0 H:[_UIBackdropView:0x7fb6a053bf90]-(0)-| (Names: '|':UIView:0x7fb6a0549220 )>",
"<NSLayoutConstraint:0x7fb6a296f440 H:|-(0)-[UIView:0x7fb6a0549220] (Names: '|':AVAlphaUpdatingView:0x7fb6a053dae0 )>",
"<NSLayoutConstraint:0x7fb6a296f490 H:[UIView:0x7fb6a0549220]-(0)-| (Names: '|':AVAlphaUpdatingView:0x7fb6a053dae0 )>",
"<NSLayoutConstraint:0x7fb6a2a40cc0 'UIView-Encapsulated-Layout-Width' H:[AVAlphaUpdatingView:0x7fb6a053dae0(0)]>"
)
在最初的方法之后,我尝试在 videoPlayerController 的
View 上设置 autolayout
,并将 translatesAutoresizingMaskIntoConstraints
设置为 false。但问题仍然存在。我该如何解决这些问题?
最佳答案
使用此代码,
viewDidLoad 方法:
let type : String! = "mp4"
let targetURL : String? = NSBundle.mainBundle().pathForResource("Welcome", ofType: type)
let videoURL = NSURL(fileURLWithPath:targetURL!)
let player = AVPlayer(URL: videoURL)
let playerController = AVPlayerViewController()
playerController.player = player
self.addChildViewController(playerController)
self.playView.addSubview(playerController.view)
playerController.view.frame = playView.bounds
player.play()
我的 Storyboard View 如下所示,
我已经创建了 UIView,然后设置解决的顶部、左侧、右侧和高度。它对我有用
希望对你有帮助
关于ios - AVPlayerController : Full screen Autolayout issues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37087319/
我正在尝试了解 AVPlayer 和 AVPlayerController 的工作原理。我将我的播放器嵌入到一个 View 中,所以我的播放器有两种模式:小屏幕和全屏。当它很小时,播放/暂停按钮和全屏
我遇到了与此问题相同的问题,但我不知道我错在哪里。 它仍然保留在外部显示器上视频的最后一帧。 iOS Swift App AVPlayerController dismiss not working
iOS 11 引入了滑动关闭 AVPlayerController 的功能。我有一个针对幼儿的应用程序,因此很容易滑动屏幕导致视频关闭。有什么方法可以去掉关闭播放器的手势吗? 我已尝试将手势覆盖添加到
我在指定的 UIView 上加载我的 AVPlayerController。有没有办法只隐藏 AVPlayerController 上显示的全屏按钮? 最佳答案 您可以使用以下方法隐藏所有控件: Yo
取决于PlaybackControl Visibity 如何显示和隐藏contentOverlayView中添加的自定义 subview ? 我想像 Youtube TVOS 应用那样做。 我尝试使用
我构建了一个应用程序来显示展览的几部短片,该应用程序在 iPad 上功能齐全,但在外部显示器上,视频将停留在最后一帧。我们想使用 iPad 作为显示器的外部控制,但是当没有视频播放时,用户应该总是看到
我有三个网址,必须检查这些网址是否有可播放的视频链接。如果 url 中不包含视频,我必须退出链接并从下一个 url 播放视频。以下代码将有助于跟踪播放状态。 let playerAV = AVPlay
我正在使用以下代码在我的 Swift 应用程序 (iOS 9) 中播放视频: let fileUrl = NSBundle.mainBundle().URLForResource("w
我有一个 tableview,我正在尝试加载视频并在 viewdidLoad() 上播放它们 Viewdidload加载视频的代码如下 func playVideo(viewController:U
我是一名优秀的程序员,十分优秀!