Skip to content

Commit 5a4f221

Browse files
author
zhaoyongqiang
committed
视频自定义采集添加切换摄像头
1 parent b1199fb commit 5a4f221

5 files changed

Lines changed: 50 additions & 10 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "camera.svg",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Loading

iOS/APIExample/Common/ExternalVideo/AgoraCameraSourcePush.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private extension AgoraCameraSourcePush {
133133
}
134134

135135
func captureDevice(atIndex index: Int) -> AVCaptureDevice? {
136-
let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .back)
136+
let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: index == 1 ? .front : .back)
137137
let devices = deviceDiscoverySession.devices
138138

139139
let count = devices.count

iOS/APIExample/Examples/Advanced/CustomVideoSourcePush/Base.lproj/CustomVideoSourcePush.storyboard

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
89
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
910
</dependencies>
1011
<scenes>
@@ -24,15 +25,15 @@
2425
<fontDescription key="fontDescription" type="system" pointSize="14"/>
2526
<textInputTraits key="textInputTraits"/>
2627
</textField>
27-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kbN-ZR-nNn" userLabel="joinBtn">
28+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kbN-ZR-nNn" userLabel="joinBtn">
2829
<rect key="frame" x="172" y="74" width="30" height="30"/>
2930
<state key="normal" title="Join"/>
3031
<connections>
3132
<action selector="doJoinPressedWithSender:" destination="O0d-ef-mTa" eventType="touchUpInside" id="pdy-Tj-ycl"/>
3233
</connections>
3334
</button>
3435
</subviews>
35-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
36+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
3637
<constraints>
3738
<constraint firstItem="kbN-ZR-nNn" firstAttribute="centerX" secondItem="GWc-L5-fZV" secondAttribute="centerX" id="B5x-LS-GFH"/>
3839
<constraint firstItem="kbN-ZR-nNn" firstAttribute="top" secondItem="GWc-L5-fZV" secondAttribute="bottom" constant="20" id="LVQ-Cs-yOU"/>
@@ -43,13 +44,13 @@
4344
</constraints>
4445
</view>
4546
</subviews>
46-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
47+
<viewLayoutGuide key="safeArea" id="wDs-Gr-g1S"/>
48+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
4749
<constraints>
4850
<constraint firstItem="UzG-zY-iSA" firstAttribute="centerY" secondItem="wDs-Gr-g1S" secondAttribute="centerY" multiplier="0.8" id="8bT-wH-NDK"/>
4951
<constraint firstItem="UzG-zY-iSA" firstAttribute="leading" secondItem="wDs-Gr-g1S" secondAttribute="leading" constant="20" id="BQh-SU-OA6"/>
5052
<constraint firstItem="wDs-Gr-g1S" firstAttribute="trailing" secondItem="UzG-zY-iSA" secondAttribute="trailing" constant="20" id="gHu-5I-6Gb"/>
5153
</constraints>
52-
<viewLayoutGuide key="safeArea" id="wDs-Gr-g1S"/>
5354
</view>
5455
<connections>
5556
<outlet property="channelTextField" destination="GWc-L5-fZV" id="xDy-ai-JdS"/>
@@ -70,19 +71,19 @@
7071
<subviews>
7172
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Dhe-dP-S21" customClass="AGEVideoContainer" customModule="AGEVideoLayout">
7273
<rect key="frame" x="0.0" y="44" width="414" height="233"/>
73-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
74+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
7475
<constraints>
7576
<constraint firstAttribute="width" secondItem="Dhe-dP-S21" secondAttribute="height" multiplier="16:9" id="zvH-0k-xq5"/>
7677
</constraints>
7778
</view>
7879
</subviews>
79-
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
80+
<viewLayoutGuide key="safeArea" id="sNP-3V-smz"/>
81+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
8082
<constraints>
8183
<constraint firstItem="sNP-3V-smz" firstAttribute="trailing" secondItem="Dhe-dP-S21" secondAttribute="trailing" id="JFK-11-DEk"/>
8284
<constraint firstItem="Dhe-dP-S21" firstAttribute="top" secondItem="sNP-3V-smz" secondAttribute="top" id="cXZ-dI-sqt"/>
8385
<constraint firstItem="Dhe-dP-S21" firstAttribute="leading" secondItem="sNP-3V-smz" secondAttribute="leading" id="mnA-US-hxx"/>
8486
</constraints>
85-
<viewLayoutGuide key="safeArea" id="sNP-3V-smz"/>
8687
</view>
8788
<navigationItem key="navigationItem" title="Join Channel" id="a4k-1t-KLv"/>
8889
<connections>
@@ -94,4 +95,9 @@
9495
<point key="canvasLocation" x="118.84057971014494" y="930.80357142857133"/>
9596
</scene>
9697
</scenes>
98+
<resources>
99+
<systemColor name="systemBackgroundColor">
100+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
101+
</systemColor>
102+
</resources>
97103
</document>

iOS/APIExample/Examples/Advanced/CustomVideoSourcePush/CustomVideoSourcePush.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class CustomVideoSourcePushMain: BaseViewController {
6363

6464
override func viewDidLoad() {
6565
super.viewDidLoad()
66+
setuoNavigationBar()
67+
6668
// layout render view
6769
remoteVideo.setPlaceholder(text: "Remote Host".localized)
6870
container.layoutStream(views: [localVideo, remoteVideo])
@@ -126,6 +128,16 @@ class CustomVideoSourcePushMain: BaseViewController {
126128
}
127129
}
128130

131+
private func setuoNavigationBar() {
132+
navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "camera"),
133+
style: .done, target: self,
134+
action: #selector(clickChangeCamera))
135+
}
136+
137+
@objc
138+
private func clickChangeCamera() {
139+
customCamera?.switchCamera()
140+
}
129141

130142
override func willMove(toParent parent: UIViewController?) {
131143
if parent == nil {

0 commit comments

Comments
 (0)