在进行本部分前,请确认已阅读《环境配置》相关章节。
本章针对Objective-C 开发者集成QttAudio SDK,适用于iOS应用开发。
一共包含6个关键操作:
- 实现频道事件代理
- 初始化
- 参数配置
- 进入频道
- 离开频道
- 释放资源
1. 实现频道事件代理
实现QttChannelEngineDelegate接口类:
@interface QttChannelEngineDelegateImpl : NSObject<QttChannelEngineDelegate> - (void)onJoinSuccess:(NSString*)channelName uid:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted; - (void)onReJoinSuccess:(NSString*)channelName uid:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted; - (void)onOtherJoin:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted; - (void)onJoinFail:(int)code message:(NSString*)message; - (void)onConnectionBreak; - (void)onConnectionLost; - (void)onWarning:(int)warn message:(NSString*)message; - (void)onError:(int)err message:(NSString*)message; - (void)onLeave; - (void)onOtherLeave:(NSUInteger)uid role:(QttChannelRole)role; - (void)onTalking:(NSArray<QttVolumeInfo*> *_Nonnull)volumeInfos userNum:(NSInteger)userNum; - (void)onMuteStatusChanged:(NSUInteger)uid muted:(bool) muted; - (void)onRoleStatusChanged:(NSUInteger)uid role:(QttChannelRole)role; - (void)onNetworkStats:(NSUInteger)uid txQuality:(QttQualityType)txQuality rxQuality:(QttQualityType)rxQuality stat:(QttRtcStat*)stat; - (void)onAudioRouteChanged:(int)route; - (void)onSoundStateChanged:(int)state; - (void)onEffectFinished:(int)effectId; @end
@implementation QttChannelEngineDelegateImpl - (void)onJoinSuccess:(NSString*)channelName uid:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted { } - (void)onReJoinSuccess:(NSString*)channelName uid:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted { } - (void)onOtherJoin:(NSUInteger)uid role:(QttChannelRole)role muted:(bool)muted { } - (void)onJoinFail:(int)code message:(NSString*)message { } - (void)onConnectionBreak { } - (void)onConnectionLost { } - (void)onWarning:(int)warn message:(NSString*)message { } - (void)onError:(int)err message:(NSString*)message { } - (void)onLeave { } - (void)onOtherLeave:(NSUInteger)uid role:(QttChannelRole)role { } - (void)onTalking:(NSArray<QttVolumeInfo*> *_Nonnull)volumeInfos userNum:(NSInteger)userNum { } - (void)onMuteStatusChanged:(NSUInteger)uid muted:(bool) muted { } - (void)onRoleStatusChanged:(NSUInteger)uid role:(QttChannelRole)role { } - (void)onNetworkStats:(NSUInteger)uid txQuality:(QttQualityType)txQuality rxQuality:(QttQualityType)rxQuality stat:(QttRtcStat*)stat { } - (void)onAudioRouteChanged:(int)route { } - (void)onSoundStateChanged:(int)state { } - (void)onEffectFinished:(int)effectId { } @end
|
2. 初始化
请开发者使用自己的AppKey进行初始化
id<QttChannelEngineDelegate> delegate = [[QttChannelEngineDelegateImpl alloc] init]; QttChannelEngine* engine = [QttChannelEngine GetEngineInstance:@"your AppKey" delegate:delegate]; if (engine == nil) { NSLog(@"QttChannel初始化失败,原因是%@", [QttChannelEngine GetError]); return; } NSLog(@"QttChannel初始化成功");
|
3. 参数设置
[engine changeRole:TALKER];
[engine muteLocalAudio:NO];
|
4. 进入频道
unsigned int uid = 111111;
NSString* channelId = @"test1"; [engine join:@"" channelId:channelId uid:uid];
|
5. 离开频道
6. 释放资源
[QttChannelEngine Destroy];
|