forked from AgoraIO/API-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoView.swift
More file actions
115 lines (99 loc) · 3.14 KB
/
VideoView.swift
File metadata and controls
115 lines (99 loc) · 3.14 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// VideoView.swift
// APIExample
//
// Created by 张乾泽 on 2020/9/16.
// Copyright © 2020 Agora Corp. All rights reserved.
//
import UIKit
extension Bundle {
static func loadView<T>(fromNib name: String, withType type: T.Type) -> T {
if let view = Bundle.main.loadNibNamed(name, owner: nil, options: nil)?.first as? T {
return view
}
fatalError("Could not load view with type " + String(describing: type))
}
static func loadVideoView(type: VideoView.StreamType, audioOnly: Bool) -> VideoView {
let view = Bundle.loadView(fromNib: "VideoView", withType: VideoView.self)
view.audioOnly = audioOnly
view.type = type
if type.isLocal() {
view.statsInfo = StatisticsInfo(type: .local(StatisticsInfo.LocalInfo()))
} else {
view.statsInfo = StatisticsInfo(type: .remote(StatisticsInfo.RemoteInfo()))
}
return view
}
}
class VideoView: UIView {
@IBOutlet weak var videoView: UIView!
@IBOutlet weak var placeholderLabel: UILabel!
@IBOutlet weak var infoLabel: UILabel!
@IBOutlet weak var statsLabel: UILabel!
var audioOnly: Bool = false
var uid: UInt = 0
enum StreamType {
case local
case remote
func isLocal() -> Bool {
switch self {
case .local: return true
case .remote: return false
}
}
}
var statsInfo: StatisticsInfo? {
didSet {
if Thread.isMainThread {
statsLabel.text = statsInfo?.description(audioOnly: audioOnly)
} else {
DispatchQueue.main.async {
self.statsLabel.text = self.statsInfo?.description(audioOnly: self.audioOnly)
}
}
}
}
var type: StreamType?
func setPlaceholder(text: String) {
placeholderLabel.text = text
}
func setInfo(text: String) {
infoLabel.text = text
}
override func awakeFromNib() {
super.awakeFromNib()
statsLabel.layer.shadowColor = UIColor.appColor(.textShadow)?.cgColor
statsLabel.layer.shadowOffset = CGSize(width: 1, height: 1)
statsLabel.layer.shadowRadius = 1.0
statsLabel.layer.shadowOpacity = 0.7
statsLabel.preferredMaxLayoutWidth = frame.width * 0.7
}
}
class MetalVideoView: UIView {
@IBOutlet weak var placeholder: UILabel!
@IBOutlet weak var videoView: AgoraMetalRender!
@IBOutlet weak var infolabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
func setPlaceholder(text: String) {
placeholder.text = text
}
func setInfo(text: String) {
infolabel.text = text
}
}
class SampleBufferDisplayView: UIView {
@IBOutlet weak var placeholder: UILabel!
@IBOutlet weak var videoView: AgoraSampleBufferRender!
@IBOutlet weak var infolabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
func setPlaceholder(text: String) {
placeholder.text = text
}
func setInfo(text: String) {
infolabel.text = text
}
}