Ich versuche mein Bestes, Video zu holen und abzuspielen, bevor Knopf Aktion. Genau wie Instagram. Aber ich stecke jetzt, bitte hilf mir.Instagram wie Bild/Video-Picker in Swift mit Fusuma
Mein Fehler ist als FSAlbumView
ist eine Ansichtsklasse, also wie kann meine AVPlayerviewcontroller
in UIView-Klasse präsentieren und Video automatisch abspielen.
Schauen Sie sich mein Code:
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
}
done sir zu präsentieren. Entschuldigen Sie die Umstände. eigentlich bin ich neu –