Skip to content

Commit 8cda794

Browse files
author
qinhui
committed
Bugfix
1 parent d414556 commit 8cda794

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

iOS/APIExample-OC/APIExample-OC/Examples/Advanced/LocalCompositeGraph/LocalCompositeGraph.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ @interface LocalCompositeGraph ()<AgoraRtcEngineDelegate>
4545
@property (nonatomic, strong)AgoraScreenCaptureParameters2 *screenParams;
4646
@property (nonatomic, strong)RPSystemBroadcastPickerView *systemBroadcastPicker;
4747
@property (nonatomic, strong)AgoraRtcChannelMediaOptions *option;
48+
@property (weak, nonatomic) IBOutlet UISwitch *virtualBackgroundSwitch;
4849

4950
@end
5051

5152
@implementation LocalCompositeGraph
5253

5354
- (void)viewDidLoad {
5455
[super viewDidLoad];
56+
[self.virtualBackgroundSwitch setOn:NO];
5557
[self.localView setPlaceholder:@"Local Host".localized];
5658
[self.container layoutStream:@[self.localView]];
5759

@@ -128,6 +130,19 @@ - (VideoView *)localView {
128130
return _localView;
129131
}
130132

133+
- (IBAction)virtualBackgroundAction:(UISwitch *)sender {
134+
[self changeVirtualBackground];
135+
}
136+
137+
- (void)changeVirtualBackground {
138+
AgoraVirtualBackgroundSource *source = [[AgoraVirtualBackgroundSource alloc] init];
139+
source.backgroundSourceType = AgoraVirtualBackgroundColor;
140+
source.color = 0xFFFFFF;
141+
source.backgroundSourceType = self.virtualBackgroundSwitch.isOn ? source.backgroundSourceType : AgoraVirtualBackgroundNone;
142+
[self.agoraKit enableVirtualBackground:self.virtualBackgroundSwitch.isOn backData:source segData:[AgoraSegmentationProperty new]];
143+
}
144+
145+
131146
- (AgoraScreenCaptureParameters2 *)screenParams {
132147
if (_screenParams == nil) {
133148
_screenParams = [[AgoraScreenCaptureParameters2 alloc] init];

iOS/APIExample-OC/APIExample-OC/Examples/Advanced/LocalCompositeGraph/LocalCompositeGraph.storyboard

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,27 @@
5959
<rect key="frame" x="0.0" y="59" width="393" height="759"/>
6060
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
6161
</view>
62+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vyQ-ls-der">
63+
<rect key="frame" x="172" y="423" width="51" height="31"/>
64+
<connections>
65+
<action selector="virtualBackgroundAction:" destination="33B-rf-jso" eventType="valueChanged" id="ep8-WW-XPI"/>
66+
</connections>
67+
</switch>
6268
</subviews>
6369
<viewLayoutGuide key="safeArea" id="3wQ-o6-eNJ"/>
6470
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
6571
<constraints>
72+
<constraint firstItem="vyQ-ls-der" firstAttribute="centerX" secondItem="3wQ-o6-eNJ" secondAttribute="centerX" id="13s-SP-fQe"/>
6673
<constraint firstItem="V7v-fP-Wu3" firstAttribute="top" secondItem="3wQ-o6-eNJ" secondAttribute="top" id="Ffo-li-75j"/>
6774
<constraint firstItem="3wQ-o6-eNJ" firstAttribute="trailing" secondItem="V7v-fP-Wu3" secondAttribute="trailing" id="IGi-o6-DhD"/>
6875
<constraint firstItem="V7v-fP-Wu3" firstAttribute="leading" secondItem="3wQ-o6-eNJ" secondAttribute="leading" id="Ne4-hM-RXb"/>
76+
<constraint firstItem="vyQ-ls-der" firstAttribute="centerY" secondItem="3wQ-o6-eNJ" secondAttribute="centerY" id="k3B-wJ-s6t"/>
6977
<constraint firstItem="3wQ-o6-eNJ" firstAttribute="bottom" secondItem="V7v-fP-Wu3" secondAttribute="bottom" id="oFs-Rq-l0y"/>
7078
</constraints>
7179
</view>
7280
<connections>
7381
<outlet property="container" destination="V7v-fP-Wu3" id="jZh-u3-jyT"/>
82+
<outlet property="virtualBackgroundSwitch" destination="vyQ-ls-der" id="S0j-4Q-fxP"/>
7483
</connections>
7584
</viewController>
7685
<placeholder placeholderIdentifier="IBFirstResponder" id="Lws-GF-lGx" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>

iOS/APIExample-SwiftUI/APIExample-SwiftUI/Examples/Advanced/LocalVideoComposition/LocalCompositeGraph.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ struct LocalCompositeGraphEntry: View {
3535
struct LocalCompositeGraph: View {
3636
@State var configs: [String: Any] = [:]
3737
@ObservedObject private var agoraKit = LocalCompositeGraphRTC()
38-
38+
@State private var toggleState: Bool = false
39+
3940
var localView = VideoView()
4041

4142
var body: some View {
@@ -44,6 +45,14 @@ struct LocalCompositeGraph: View {
4445
localView
4546
}
4647
Spacer()
48+
HStack {
49+
Toggle("", isOn: $toggleState)
50+
.onChange(of: toggleState) { newValue in
51+
agoraKit.updateToggleState(isOn: newValue)
52+
}
53+
Spacer()
54+
}
55+
.padding()
4756
}.onAppear(perform: {
4857
agoraKit.setupRTC(configs: configs,
4958
localView: localView.videoView)

iOS/APIExample-SwiftUI/APIExample-SwiftUI/Examples/Advanced/LocalVideoComposition/LocalCompositeGraphRTC.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ class LocalCompositeGraphRTC: NSObject, ObservableObject {
176176
agoraKit.startPreview()
177177
}
178178

179+
func updateToggleState(isOn: Bool) {
180+
let source = AgoraVirtualBackgroundSource()
181+
source.backgroundSourceType = .color
182+
source.color = 0xFFFFFF
183+
source.backgroundSourceType = isOn ? source.backgroundSourceType : .none
184+
let result = agoraKit.enableVirtualBackground(isOn, backData: source, segData: AgoraSegmentationProperty())
185+
print("result == \(result)")
186+
}
187+
188+
179189
func onDestory() {
180190
agoraKit.disableAudio()
181191
agoraKit.disableVideo()

0 commit comments

Comments
 (0)