Answer the question
In order to leave comments, you need to log in
Playing the player in only one cell?
Friends, tell me, I'm looking for a solution, how to play audio / video in only one cell. Since there can be 10-20 different videos/music in a section, the user can run the play function everywhere. Interested in how to implement such solutions
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: videCellId, for: indexPath) as! InsideVideoCell
cell.playButton.tag = indexPath.row // 05.01
cell.playButton.addTarget(self, action: #selector(playpause), for: .touchUpInside) // 05.01
if let videosArray = videos?[indexPath.item] {
queueUtility.async {
let url = URL(string: videosArray)
let playerItem = AVPlayerItem(url: url!)
DispatchQueue.main.async {
self.player = AVPlayer(playerItem: playerItem)
self.player.actionAtItemEnd = .none
let videoPlayerLayer = AVPlayerLayer(player: self.player)
videoPlayerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
videoPlayerLayer.frame = cell.bounds
cell.insertSubview(cell.videoPlayerController.view, at: 0)
cell.contentView.addSubview(cell.playButton)
cell.videoPlayerController.player = self.player
cell.videoPlayerController.view.frame = videoPlayerLayer.frame
}
}
} else {
print("Нет Видео")
}
return cell
}
Answer the question
In order to leave comments, you need to log in
Have you tried reading the documentation?
----------------------------------------------------
https://golang .org/pkg/encoding/json/
https://blog.golang.org/json-and-go
https://gobyexample.com/json
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question