跳转至
400-881-9892

文档中心

官方文档,可查阅产品介绍、快速入门、用户指南、开发指南、API参考、SDK参考、帮助等信息。

文档中心 互动课堂

Server Recording and Local Recording

startServerRecord
  • Brief description

Enable server recording

We provide a course recording function that can fully reproduce the teaching process. By calling this interface, you can record the course. After enabling the recording, the callback is: The callback for the recording status is -(void)roomManagerOnServerRecordStateChanged:(TKRecordState)state fromID:(NSString )peerID extension:(NSDictionary )extension

  • Interface name
1
2
3
- (int)startServerRecord:(NSDictionary<NSString *, id> *)spec
              expiresabs:(NSInteger)expiresabs
                 expires:(NSInteger)expires;
  • Parameter
Parameter Name Required Type Description
spec Yes NSDictionary Recording Parameters
expiresabs Yes NSInteger Recording duration. 0 indicates no time limit until the stop recording API is called
expires Yes NSInteger The timestamp when the recording ends. 0 indicates that no end time is set
  • Method Example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---------------------------------standard mode---------------------------------
The standard mode is the default mode for standard and regular recording.
objc NSDictionary *spec = @{@"recordMode" : @"standard"}; 
---------------------------------mix mode----------------------------------
The mix mode is for custom mixed-stream recording and requires the following parameters.
You can customize the layout style for user objects.
```objc
NSDictionary *userVideoLayout = @{
    @"uid": @"1131223463fff",    // User ID. If it is a shared desktop video stream, the ID is 'UserID:screen'
    @"x_coord": @(0.1),  // Window x-coordinate, value is a percentage of the total video width
    @"y_coord": @(0.1),  // Window y-coordinate, value is a percentage of the total video height
    @"width": @(0.18),    // Window width, value is a percentage of the total video width
    @"height": @(0.24),   // Window height, value is a percentage of the total video height
    @"alpha": @(1),  // Window transparency
    @"play_video" : @(YES),  // Default value YES; YES: Display video window, NO: Do not display video window
    @"play_audio" : @(YES),  // Default value YES; YES: Play audio, NO: Do not play audio
};
 
NSMutableArray *videoLayoutList = [NSMutableArray array];
[videoLayoutList addObject:userVideoLayout];
NSDictionary *customConfigParams = @{
    @"noStreamTimeout_s" : @(30),   // After starting the mixed stream, if there is no stream from the specified users in the room, stop the mixed stream after 30 seconds
    @"backgroundColor" : @"#0d69fb",   // For compatibility, if specified, this has higher priority than the outer background color configuration
    @"videoLayout" : videoLayoutList
};
NSDictionary *spec = @{
    @"recordMode" : @"mix",
    @"mixStreamParams" : @{
        @"template": @2,     // Required. Mixed stream layout template ID. 0 indicates equal distribution layout; 1 indicates picture-in-picture layout; 2 indicates custom layout
        @"backgroundColor": @"#0d69fb",     // Color value
        @"customConfig": customConfigParams
    }   // If template is 2, this parameter takes effect for custom layout, including layout parameters and other additional parameters. If template is any value other than 2, this parameter is invalid and can be omitted
};

⚠️ Note: If `spec` is `nil`, the default mode is standard.
```objc
[_roomMgr startServerRecord:spec
                 expiresabs:0];
  • Return Value Description
Type Description
int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

stopServerRecord

  • Brief description

Stop server recording

  • Interface name

- (int)stopServerRecord;

  • Method Example

[_roomMgr stopServerRecord];

  • Return Value Description
Type Description
int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

pauseServerRecord

  • Brief description

Pause server recording

  • Interface name

- (int)pauseServerRecord;

  • Method Example

[_roomMgr pauseServerRecord];

  • Return Value Description
Type Description
int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

resumeServerRecord

  • Brief description

Resume server recording

  • Interface name

- (int)resumeServerRecord;

  • Method Example

[_roomMgr resumeServerRecord];

  • Return Value Description
Type Description
int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

startAudioRecord

  • Brief description

Enable local audio recording

It will record all the audio data in the room and then save it to the sandbox.

  • Interface name

- (int)startAudioRecord:(NSString *)sandboxPath;

  • Parameter
Parameter Name Required Type Description
sandboxPath Yes NSString The path for saving the recorded file must be a valid sandbox file path, such as xxx/Library/Caches/audioRecord.mp3.Notes:1.  The audio file is saved in MP3 format.2.  If the same path is provided twice, the recorded data will overwrite the existing file.3.  The file path must be valid; otherwise, the recording will fail. For example, if the path does not exist or is a directory path instead of a file path, the recording will fail.
  • Method Example
1
2
3
4
5
6
7
8
     NSArray *cachesPathArr = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
     NSString *cachesPath = cachesPathArr.firstObject;
     NSString *path = [cachesPath stringByAppendingPathComponent:@"audioRecord.mp3"];
     BOOL exist = [[NSFileManager defaultManager] fileExistsAtPath:path];
     if (!exist) {
         [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
     }
     [_roomMgr startAudioRecord:path];
  • Return Value Description
Type Description
int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

pauseAudioRecord

  • Brief description

Whether to pause local audio recording

  • Interface name

- (int)pauseAudioRecord:(BOOL)pause;

  • Parameter
Parameter Name Required Type Description
pause Yes BOOL Whether to pause the recording
  • Method Example

[_roomMgr pauseAudioRecord:YES];

  • Return Value Description
Type Description
int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

stopAudioRecord

  • Brief description

Stop local audio recording

  • Interface name

- (int)stopAudioRecord;

  • Method Example

[_roomMgr stopAudioRecord];

  • Return Value Description
Type Description
int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

Notes

For more return error codes, please refer to the description of TKRoomErrorCode error codes