我正在尽力在完成按钮操作之前获取并播放视频。完全像Instagram。但我现在被困住请帮助我。
我的错误是FSAlbumView
是一个视图类,因此如何在UIView类中显示我的AVPlayerviewcontroller
并自动播放视频。
查看我的代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FSAlbumViewCell", for: indexPath) as! FSAlbumViewCell
let currentTag = cell.tag + 1
cell.tag = currentTag
let asset = self.images[(indexPath as NSIndexPath).item]
print(self.images)
print(asset.mediaType.rawValue)
if asset.mediaType.rawValue==1
{
// IMAGES
self.imageManager?.requestImage(for: asset,
targetSize: cellSize,
contentMode: .aspectFill,
options: nil) {
result, info in
if cell.tag == currentTag {
cell.image = result
}
}
}
if asset.mediaType.rawValue==2
{
// For Video
PHImageManager.default().requestAVAsset(forVideo: asset, options: nil, resultHandler: { (video, audioMix, info) in
let urlAsset = video as! AVURLAsset
print(urlAsset)
var StaticURLForNow = URL.init(string: "http://techslides.com/demos/sample-videos/small.mp4")
let player = AVPlayer(url: StaticURLForNow!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
})
}
return cell
}
答案 0 :(得分:0)
首先,您需要正确提供代码,而不是图像。
要回答您的问题,看起来您正试图让#scrollbar1 .viewport { width: 80%; height: 200px;}
呈现新的控制器,这就是您遇到错误的原因。只有UIView
才能显示新的控制器。
您需要将某种委托使用回父视图控制器来呈现新的UIViewController