Skip to content

Commit 58b3bdf

Browse files
author
xia ning
authored
Merge pull request #126 from AgoraIO/dev/macos
Add mediaIO video source switching example for macOS
2 parents 1176083 + 6faa0c3 commit 58b3bdf

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

macOS/APIExample/Examples/Advanced/CustomVideoSourceMediaIO/Base.lproj/CustomVideoSourceMediaIO.storyboard

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17506"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<scenes>
@@ -77,6 +77,10 @@
7777
<rect key="frame" x="27" y="330" width="260" height="50"/>
7878
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
7979
</view>
80+
<view id="q1j-uo-tMi" customClass="Picker" customModule="APIExample" customModuleProvider="target">
81+
<rect key="frame" x="27" y="279" width="260" height="50"/>
82+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
83+
</view>
8084
</subviews>
8185
</view>
8286
</subviews>
@@ -116,6 +120,7 @@
116120
<outlet property="selectFpsPicker" destination="ddH-cU-D74" id="G81-jb-kIg"/>
117121
<outlet property="selectLayoutPicker" destination="IUu-Lm-BTO" id="55M-bG-2ib"/>
118122
<outlet property="selectResolutionPicker" destination="nN4-UK-bQr" id="1SY-Qr-9Bo"/>
123+
<outlet property="videoSourceSwitcher" destination="q1j-uo-tMi" id="mZh-9Y-SrK"/>
119124
</connections>
120125
</viewController>
121126
<customObject id="S9U-UI-b0n" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>

macOS/APIExample/Examples/Advanced/CustomVideoSourceMediaIO/CustomVideoSourceMediaIO.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ class CustomVideoSourceMediaIO: BaseViewController {
117117
}
118118
}
119119

120+
@IBOutlet weak var videoSourceSwitcher: Picker!
121+
let sources = [Layout("AVCaptureDevice", 1), Layout("AgoraRtcDefaultCamera", 2)]
122+
var selectedSource: Layout? {
123+
let index = self.videoSourceSwitcher.indexOfSelectedItem
124+
if index >= 0 && index < sources.count {
125+
return sources[index]
126+
} else {
127+
return nil
128+
}
129+
}
130+
func initVideoSourceSwitcher() {
131+
videoSourceSwitcher.label.stringValue = "Video Source".localized
132+
videoSourceSwitcher.picker.addItems(withTitles: sources.map { $0.label })
133+
videoSourceSwitcher.onSelectChanged {
134+
guard let source = self.selectedSource else { return }
135+
if source.value == 2 {
136+
self.agoraKit.setVideoSource(AgoraRtcDefaultCamera())
137+
} else if source.value == 1 {
138+
self.agoraKit.setVideoSource(self.customCamera)
139+
}
140+
}
141+
}
142+
120143
/**
121144
--- Channel TextField ---
122145
*/
@@ -164,6 +187,7 @@ class CustomVideoSourceMediaIO: BaseViewController {
164187
initSelectLayoutPicker()
165188
initChannelField()
166189
initJoinChannelButton()
190+
initVideoSourceSwitcher()
167191
}
168192

169193
override func viewWillBeRemovedFromSplitView() {

macOS/APIExample/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,4 @@
153153
"Send" = "发送";
154154
"Sending" = "发送中";
155155
"Raw Audio Data" = "音频裸数据";
156+
"Video Source" = "视频源选择";

0 commit comments

Comments
 (0)