Skip to content

Commit

Permalink
Merge branch 'dev/4.3.0' of github.com:AgoraIO/API-Examples into dev/…
Browse files Browse the repository at this point in the history
…4.3.0
  • Loading branch information
xgfd3 committed Nov 20, 2023
2 parents f057980 + 199f5c5 commit e18d64a
Show file tree
Hide file tree
Showing 69 changed files with 1,615 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class SpatialAudioMain: BaseViewController {
var currentAngle = 0.0
var currentDistance = 0.0
var maxDistance: CGFloat = 10
let forward = [NSNumber(1.0), NSNumber(0.0), NSNumber(0.0)]
let right = [NSNumber(0.0), NSNumber(1.0), NSNumber(0.0)]
let up = [NSNumber(0.0), NSNumber(0.0), NSNumber(1.0)]
let forward = simd_float3(1.0, 0.0, 0.0)
let right = simd_float3(0.0, 1.0, 0.0)
let up = simd_float3(0.0, 0.0, 1.0)

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -182,7 +182,10 @@ class SpatialAudioMain: BaseViewController {
localSpatial.setZones([audioZone])
}
let pos = getViewCenterPostion(view: selfPostionView)
localSpatial.updateSelfPosition(pos, axisForward: forward, axisRight: right, axisUp: up)
localSpatial.updateSelfPosition(pos,
axisForward: forward,
axisRight: right,
axisUp: up)
}

private func updateMediaPlayerParams(mediaPlayer: AgoraRtcMediaPlayerProtocol,
Expand All @@ -209,7 +212,10 @@ class SpatialAudioMain: BaseViewController {

func updatePosition() {
let pos = getViewCenterPostion(view: selfPostionView)
localSpatial.updateSelfPosition(pos, axisForward: forward, axisRight: right, axisUp: up)
localSpatial.updateSelfPosition(pos,
axisForward: forward,
axisRight: right,
axisUp: up)
}

private func getPlayerPostion(view: UIView) -> AgoraRemoteVoicePositionInfo {
Expand All @@ -220,8 +226,8 @@ class SpatialAudioMain: BaseViewController {
positionInfo.forward = forward
return positionInfo
}
private func getViewCenterPostion(view: UIView) -> [NSNumber] {
[NSNumber(value: Double(view.center.x)), NSNumber(value: Double(view.center.y)), NSNumber(0.0)]
private func getViewCenterPostion(view: UIView) -> simd_float3 {
simd_float3(Float(view.center.x), Float(view.center.y), 0.0)
}

private func updateSpatialAngle(objectCenter: CGPoint) -> AgoraRemoteVoicePositionInfo {
Expand All @@ -248,8 +254,8 @@ class SpatialAudioMain: BaseViewController {

let posForward = spatialDistance * cos(currentAngle);
let posRight = spatialDistance * sin(currentAngle);
let position = [NSNumber(value: posForward), NSNumber(value: posRight), NSNumber(0.0)]
let forward = [NSNumber(1.0), NSNumber(0.0), NSNumber(0.0)]
let position = simd_float3(Float(posForward), Float(posRight), 0.0)
let forward = simd_float3(1.0, 0.0, 0.0)

let positionInfo = AgoraRemoteVoicePositionInfo()
positionInfo.position = position
Expand Down Expand Up @@ -291,8 +297,8 @@ extension SpatialAudioMain: AgoraRtcEngineDelegate {
}

extension SpatialAudioMain: AgoraRtcMediaPlayerDelegate {
func AgoraRtcMediaPlayer(_ playerKit: AgoraRtcMediaPlayerProtocol, didChangedTo state: AgoraMediaPlayerState, error: AgoraMediaPlayerError) {
print("didChangedTo: \(state.rawValue), \(error.rawValue)")
func AgoraRtcMediaPlayer(_ playerKit: AgoraRtcMediaPlayerProtocol, didChangedTo state: AgoraMediaPlayerState, reason: AgoraMediaPlayerReason) {
print("didChangedTo: \(state.rawValue), \(reason.rawValue)")
if state == .openCompleted || state == .playBackAllLoopsCompleted || state == .playBackCompleted {
playerKit.play()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ class VoiceChangerMain: BaseViewController {
// parameter of setAudioProfile to AUDIO_PROFILE_MUSIC_HIGH_QUALITY(4)
// or AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO(5), and to set
// scenario parameter to AUDIO_SCENARIO_GAME_STREAMING(3).
agoraKit.setAudioProfile(.musicHighQualityStereo, scenario: .gameStreaming)
agoraKit.setAudioProfile(.musicHighQualityStereo)
agoraKit.setAudioScenario(.gameStreaming)

// make myself a broadcaster
agoraKit.setChannelProfile(.liveBroadcasting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ - (void)onVideoFrame:(CVPixelBufferRef)buffer size:(CGSize)size trackId:(NSUInte
videoFrame.format = 12;
videoFrame.textureBuf = buffer;
videoFrame.rotation = rotation;
[self.agoraKit pushExternalVideoFrame:videoFrame];
[self.agoraKit pushExternalVideoFrame:videoFrame videoTrackId:trackId];

AgoraOutputVideoFrame *outputVideoFrame = [[AgoraOutputVideoFrame alloc] init];
outputVideoFrame.width = size.width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ - (void)viewDidDisappear:(BOOL)animated {
[AgoraRtcEngineKit destroy];
}

- (void)onDirectCdnStreamingStateChanged:(AgoraDirectCdnStreamingState)state error:(AgoraDirectCdnStreamingError)error message:(NSString *)message {
- (void)onDirectCdnStreamingStateChanged:(AgoraDirectCdnStreamingState)state reason:(AgoraDirectCdnStreamingReason)reason message:(NSString *)message {
dispatch_async(dispatch_get_main_queue(), ^{
switch (state) {
case AgoraDirectCdnStreamingStateRunning:
Expand All @@ -294,7 +294,7 @@ - (void)onDirectCdnStreamingStateChanged:(AgoraDirectCdnStreamingState)state err
case AgoraDirectCdnStreamingStateFailed:
[self showAlertWithTitle:@"Error" message:@"Start Streaming failed, please go back to previous page and check the settings."];
default:
[LogUtil log:[NSString stringWithFormat:@"onDirectCdnStreamingStateChanged: %ld, %ld %@", state, error, message] level:(LogLevelDebug)];
[LogUtil log:[NSString stringWithFormat:@"onDirectCdnStreamingStateChanged: %ld, %ld %@", state, reason, message] level:(LogLevelDebug)];
break;
}
});
Expand Down Expand Up @@ -328,8 +328,8 @@ - (void)rtcEngine:(AgoraRtcEngineKit *)engine streamUnpublishedWithUrl:(NSString
[self.containerView layoutStream:@[self.localView]];
}

- (void)rtcEngine:(AgoraRtcEngineKit *)engine rtmpStreamingChangedToState:(NSString *)url state:(AgoraRtmpStreamingState)state errCode:(AgoraRtmpStreamingErrorCode)errCode {
[LogUtil log:[NSString stringWithFormat:@"On rtmpStreamingChangedToState, state: %ld errCode: %ld", state, errCode] level:(LogLevelDebug)];
- (void)rtcEngine:(AgoraRtcEngineKit *)engine rtmpStreamingChangedToState:(NSString *)url state:(AgoraRtmpStreamingState)state reason:(AgoraRtmpStreamingReason)reason {
[LogUtil log:[NSString stringWithFormat:@"On rtmpStreamingChangedToState, state: %ld reason: %ld", state, reason] level:(LogLevelDebug)];
}

/// callback when a remote user is joinning the channel, note audience in live broadcast mode will NOT trigger this event
Expand Down Expand Up @@ -601,12 +601,12 @@ - (void)rtcEngine:(AgoraRtcEngineKit *)engine didOfflineOfUid:(NSUInteger)uid re
[LogUtil log:[NSString stringWithFormat:@"remote user left: %lu", uid] level:(LogLevelDebug)];
}

- (void)AgoraRtcMediaPlayer:(id<AgoraRtcMediaPlayerProtocol>)playerKit didChangedToState:(AgoraMediaPlayerState)state error:(AgoraMediaPlayerError)error {
[LogUtil log:[NSString stringWithFormat:@"player rtc channel publish helper state changed to: %ld error: %ld", state, error] level:(LogLevelDebug)];
- (void)AgoraRtcMediaPlayer:(id<AgoraRtcMediaPlayerProtocol>)playerKit didChangedToState:(AgoraMediaPlayerState)state reason:(AgoraMediaPlayerReason)reason {
[LogUtil log:[NSString stringWithFormat:@"player rtc channel publish helper state changed to: %ld error: %ld", state, reason] level:(LogLevelDebug)];
dispatch_async(dispatch_get_main_queue(), ^{
switch (state) {
case AgoraMediaPlayerStateFailed:
[self showAlertWithTitle:[NSString stringWithFormat:@"media player error: %ld", error]];
[self showAlertWithTitle:[NSString stringWithFormat:@"media player error: %ld", reason]];
break;

case AgoraMediaPlayerStateOpenCompleted:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ - (IBAction)onTapWatermarkSwitch:(UISwitch *)sender {
}

- (IBAction)onTapDualStreamSwitch:(UISwitch *)sender {
[self.agoraKit enableDualStreamMode:sender.isOn];
[self.agoraKit setDualStreamMode:sender.isOn ? AgoraEnableSimulcastStream : AgoraDisableSimulcastStream];
self.dualStreamTipsLabel.text = sender.isOn ? @"已开启" : @"默认: 大流";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ - (void)viewDidDisappear:(BOOL)animated {
[AgoraRtcEngineKit destroy];
}

- (void)AgoraRtcMediaPlayer:(id<AgoraRtcMediaPlayerProtocol>)playerKit didChangedToState:(AgoraMediaPlayerState)state error:(AgoraMediaPlayerError)error {
[LogUtil log:[NSString stringWithFormat:@"player rtc channel publish helper state changed to: %ld error: %ld", state, error]];
- (void)AgoraRtcMediaPlayer:(id<AgoraRtcMediaPlayerProtocol>)playerKit didChangedToState:(AgoraMediaPlayerState)state reason:(AgoraMediaPlayerReason)reason {
[LogUtil log:[NSString stringWithFormat:@"player rtc channel publish helper state changed to: %ld error: %ld", state, reason]];
__weak MediaPlayer *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
switch (state) {
case AgoraMediaPlayerStateFailed:
[weakSelf showAlertWithTitle:[NSString stringWithFormat:@"media player error: %ld", error]];
[weakSelf showAlertWithTitle:[NSString stringWithFormat:@"media player error: %ld", reason]];
break;

case AgoraMediaPlayerStateOpenCompleted:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ - (void)rtcEngine:(AgoraRtcEngineKit *)engine didOfflineOfUid:(NSUInteger)uid re
}
}

- (void)rtcEngine:(AgoraRtcEngineKit *)engine rtmpStreamingChangedToState:(NSString *)url state:(AgoraRtmpStreamingState)state errCode:(AgoraRtmpStreamingErrorCode)errCode {
[LogUtil log:[NSString stringWithFormat:@"streamStateChanged: %@ state %ld error %ld", url, state, errCode] level:(LogLevelDebug)];
-(void)rtcEngine:(AgoraRtcEngineKit *)engine rtmpStreamingChangedToState:(NSString *)url state:(AgoraRtmpStreamingState)state reason:(AgoraRtmpStreamingReason)reason {
[LogUtil log:[NSString stringWithFormat:@"streamStateChanged: %@ state %ld reason %ld", url, state, reason] level:(LogLevelDebug)];
if (state == AgoraRtmpStreamingStateRunning) {
[self showAlertWithTitle:@"Notice" message:@"RTMP Publish SUccess"];
self.isPublished = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ - (void)rtcEngine:(AgoraRtcEngineKit *)engine didOfflineOfUid:(NSUInteger)uid re
self.remoteView.uid = 0;
[LogUtil log:[NSString stringWithFormat:@"remote user left: %lu", uid] level:(LogLevelDebug)];
}
- (void)rtcEngine:(AgoraRtcEngineKit *)engine localVideoStateChangedOfState:(AgoraVideoLocalState)state error:(AgoraLocalVideoStreamError)error sourceType:(AgoraVideoSourceType)sourceType {

- (void)rtcEngine:(AgoraRtcEngineKit *)engine localVideoStateChangedOfState:(AgoraVideoLocalState)state reason:(AgoraLocalVideoStreamReason)reason sourceType:(AgoraVideoSourceType)sourceType {
if (state == AgoraVideoLocalStateCapturing && sourceType == AgoraVideoSourceTypeScreen) {
self.option.publishScreenCaptureAudio = YES;
self.option.publishScreenCaptureVideo = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ @interface SpatialAudio ()<AgoraRtcEngineDelegate, AgoraRtcMediaPlayerDelegate>
@property (nonatomic, assign) CGFloat currentAngle;
@property (nonatomic, assign) CGFloat currentDistance;
@property (nonatomic, assign) CGFloat maxDistance;
@property (nonatomic, strong) NSArray<NSNumber *> *forward;
@property (nonatomic, strong) NSArray<NSNumber *> *right;
@property (nonatomic, strong) NSArray<NSNumber *> *up;
@property (nonatomic, assign) simd_float3 forward;
@property (nonatomic, assign) simd_float3 right;
@property (nonatomic, assign) simd_float3 up;

@end

Expand All @@ -79,9 +79,9 @@ - (void)viewDidLoad {
self.currentAngle = 0;
self.currentDistance = 0;
self.maxDistance = 10;
self.forward = @[@(1.0), @(0.0), @(0.0)];
self.right = @[@(0.0), @(1.0), @(0.0)];
self.up = @[@(0.0), @(0.0), @(1.0)];
self.forward = simd_make_float3(1.0, 0.0, 0.0);
self.right = simd_make_float3(0.0, 1.0, 0.0);
self.up = simd_make_float3(0.0, 0.0, 1.0);

self.infoLabel.text = @"Please move the red icon to experience the 3D audio effect".localized;
[self.voiceButton1 setTitle:@"" forState:(UIControlStateNormal)];
Expand Down Expand Up @@ -168,8 +168,11 @@ - (IBAction)onTapAudioAttenuationSwitch:(UISwitch *)sender {
audioZone.upLength = self.maxDistance;
[self.localSpatial setZones:@[audioZone]];
}
NSArray *pos = [self getViewCenterPostion:self.selfPostionView];
[self.localSpatial updateSelfPosition:pos axisForward:self.forward axisRight:self.right axisUp:self.up];
simd_float3 pos = [self getViewCenterPostion:self.selfPostionView];
[self.localSpatial updateSelfPosition:pos
axisForward:self.forward
axisRight:self.right
axisUp:self.up];
}


Expand Down Expand Up @@ -250,19 +253,22 @@ - (void)updateMediaPlayerParams: (id<AgoraRtcMediaPlayerProtocol>)mediaPlayer ac
}

- (void)updatePosition {
NSArray *pos = [self getViewCenterPostion:self.selfPostionView];
[self.localSpatial updateSelfPosition:pos axisForward:self.forward axisRight:self.right axisUp:self.up];
simd_float3 pos = [self getViewCenterPostion:self.selfPostionView];
[self.localSpatial updateSelfPosition:pos
axisForward:self.forward
axisRight:self.right
axisUp:self.up];
}

- (AgoraRemoteVoicePositionInfo *)getPlayerPostion: (UIView *)view {
NSArray *postion = [self getViewCenterPostion:view];
simd_float3 postion = [self getViewCenterPostion:view];
AgoraRemoteVoicePositionInfo *postionInfo = [[AgoraRemoteVoicePositionInfo alloc] init];
postionInfo.position = postion;
postionInfo.forward = self.forward;
return postionInfo;
}
- (NSArray <NSNumber *> *)getViewCenterPostion: (UIView *)view {
return @[@(view.center.x), @(view.center.y), @(0.0)];
- (simd_float3)getViewCenterPostion: (UIView *)view {
return simd_make_float3(view.center.x, view.center.y, 0.0);
}

/// callback when error occured for agora sdk, you are recommended to display the error descriptions on demand
Expand Down Expand Up @@ -314,7 +320,7 @@ - (void)rtcEngine:(AgoraRtcEngineKit *)engine didOfflineOfUid:(NSUInteger)uid re
}
}

- (void)AgoraRtcMediaPlayer:(id<AgoraRtcMediaPlayerProtocol>)playerKit didChangedToState:(AgoraMediaPlayerState)state error:(AgoraMediaPlayerError)error {
- (void)AgoraRtcMediaPlayer:(id<AgoraRtcMediaPlayerProtocol>)playerKit didChangedToState:(AgoraMediaPlayerState)state reason:(AgoraMediaPlayerReason)reason {
if (state == AgoraMediaPlayerStateOpenCompleted || state == AgoraMediaPlayerStatePlayBackAllLoopsCompleted || state == AgoraMediaPlayerStatePlayBackCompleted) {
[playerKit play];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ - (void)mediaRecorder:(AgoraMediaRecorder *)recorder informationDidUpdated:(NSSt
NSLog(@"uid == %lu info == %@", uid, info.description);
}

- (void)mediaRecorder:(AgoraMediaRecorder *)recorder stateDidChanged:(NSString *)channelId uid:(NSUInteger)uid state:(AgoraMediaRecorderState)state error:(AgoraMediaRecorderErrorCode)error {
- (void)mediaRecorder:(AgoraMediaRecorder * _Nonnull)recorder stateDidChanged:(NSString * _Nonnull)channelId uid:(NSUInteger)uid state:(AgoraMediaRecorderState)state reason:(AgoraMediaRecorderReasonCode)reason {
[LogUtil log: [NSString stringWithFormat:@"stateDidChanged uid == %lu state == %ld reason == %ld", uid, state, reason]];
}


- (void)mediaRecorder:(AgoraMediaRecorder *)recorder stateDidChanged:(NSString *)channelId uid:(NSUInteger)uid state:(AgoraMediaRecorderState)state {
NSLog(@"uid == %lu state == %ld", uid, state);
}

Expand Down
Loading

0 comments on commit e18d64a

Please sign in to comment.