-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVideoCollectionViewCell.swift
More file actions
78 lines (60 loc) · 1.8 KB
/
VideoCollectionViewCell.swift
File metadata and controls
78 lines (60 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// VideoCollectionViewCell.swift
// MomsVideoPlayer
//
// Created by Hardik Parmar on 19/01/21.
//
import UIKit
class VideoCollectionViewCell: UICollectionViewCell {
let containerView:UIView = {
let view = UIView()
view.backgroundColor = .white
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
let playerView:PlayerView = {
let view = PlayerView()
view.clipsToBounds = true
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
var url: URL?
override func awakeFromNib() {
super.awakeFromNib()
self.setUpUI()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.setUpUI()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
self.setUpUI()
}
func setUpUI() {
self.addSubview(containerView)
containerView.applyConstraints(.fitInView(self))
// Setup video views
self.containerView.addSubview(playerView)
playerView.applyConstraints(.fitInView(self.containerView))
}
@objc
func volumeAction(_ sender:UIButton) {
sender.isSelected = !sender.isSelected
playerView.isMuted = sender.isSelected
PlayerView.videoIsMuted = sender.isSelected
}
func play() {
if let url = url {
playerView.prepareToPlay(withUrl: url, shouldPlayImmediately: true)
}
}
func pause() {
playerView.pause()
}
func configure(_ videoUrl: String) {
guard let url = URL(string: videoUrl) else { return }
self.url = url
playerView.prepareToPlay(withUrl: url, shouldPlayImmediately: false)
}
}