Publishing And Playing Audio And Video Content
publishVideo
- A brief description-Post a local video
The effect takes place after successfully entering the room. After the user successfully posts a video, they receive a success callback function: - (void)onUserVideoStatus(String uid, int state).
- (int)publishVideo(String signalingRole);
Parameter Name |
Required |
Type |
Description |
signalingRole |
Yes |
String |
User Identity |
| int ret =TKRoomManager.getInstance().publishVideo(RoomRole.STUDENT);
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
unPublishVideo
- A brief description - Stop publishing local video
This takes effect after successfully entering the room. After the user successfully stops publishing the video, they receive a success callback function: - onUserVideoStatus(String uid, int state).
- (int)unPublishVideo(String signalingRole);
Parameter Name |
Required |
Type |
Description |
signalingRole |
Yes |
String |
User Identity |
| int ret =TKRoomManager.getInstance().publishVideo(RoomRole.STUDENT);
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
publishAudio
- A brief description - Publishing local audio
The effect takes place after successfully entering the room. After the user successfully publishes the audio, they receive a successful callback function: - (void)onUserAudioStatus(String uid, int state).
- (int)publishAudio(String signalingRole);
Parameter Name |
Required |
Type |
Description |
signalingRole |
Yes |
String |
User Identity |
| int ret =TKRoomManager.getInstance().publishAudio(RoomRole.STUDENT);
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
unPublishAudio
- A brief description - Cease the release of local audio
It needs to be invoked after successfully entering the room. When the user successfully stops publishing audio, they receive a successful callback function: - (void)onUserAudioStatus(String uid, int state).
- (int)unPublishAudio(String signalingRole);
Parameter Name |
Required |
Type |
Description |
signalingRole |
Yes |
String |
User Identity |
| int ret =TKRoomManager.getInstance().unPublishAudio(RoomRole.STUDENT);
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
playVideo
- A brief description - Playing user video
The effect takes place after calling init. This function can be called multiple times for the same user ID. - Multiple calls: 1. When the same peerID and the same view are passed in, the function does not perform any operation and returns success directly; 2. When the same peerID and a different view are passed in, the video will be rendered on the new view, and the previous view that was playing the video will stop rendering; 3. It must be called on the main thread. - After calling this interface, there will be relevant callback notifications for playing the video:1. Callback for receiving the first frame of data-(void)onFirstVideoFrame(String peerId, int mediaType, int width, int height)2. Callback for video interruption during playback-(void)onVideoStateChange(String peerId, String id, TK_VIDEO_STATE state)
-```java - (int)playVideo(String peerId, Object view, RendererCommon.ScalingType mode);
- (int)playVideo(String peerId, Object view, RendererCommon.ScalingType mode, String cameraId);
Parameter Name |
Required |
Type |
Description |
peerID |
Yes |
String |
User ID |
ScalingType |
Yes |
ScalingType |
Rendering mode enumeration, detailed definitions are found in the relevant extension fields |
view |
Yes |
SurfaceViewRenderer |
Rendering window class, please use SurfaceViewRenderer from the SDK |
cameraId |
No |
String |
The device ID of the video capture device. This is applicable when the user is publishing from multiple camera devices simultaneously |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | //Global eglBase eglbase
EglBase eglBase = EglBase.create();
//Create a renderer
TkSurfaceViewRenderer createRender() {
TkSurfaceViewRenderer renderer = new TkSurfaceViewRenderer(this);
try {
renderer.init(eglBase.getEglBaseContext(), null);
} catch (Exception e) {
//Release the renderer
renderer.release();
//Release and recreate
eglBase.release();
eglBase = EglBase.create();
//Reinitialize the renderer
renderer.init(eglBase.getEglBaseContext(), null);
}
return renderer;}
TKRoomManager.getInstance().playVideo("123", createRender(),RendererCommon.ScalingType.SCALE_ASPECT_BALANCED);
OR:
TKRoomManager.getInstance().playVideo("123", createRender(),RendererCommon.ScalingType.SCALE_ASPECT_BALANCED,"1234");
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
playAudio
- A brief description - Playing user audio
The effect takes place after calling init. There is no need to play your own audio; if the playAudio function is called with your own ID as the parameter, the function will return directly. - After calling this interface, there will be relevant callback notifications for playing audio:
1. Callback for receiving the first frame of data: - (void)onFirstAudioFrame(String peerId, int mediaType)
2. Callback for audio interruption during playback: - (void)onAudioStateChange(String peerId, TK_AUDIO_STATE state)
3. Callback for changes in audio volume while playing user audio (including your own volume and remote audio volume): - (void)onAudioVolume(String peerId, int volume)
- (int)playAudio(String peerId);
Parameter Name |
Required |
Type |
Description |
peerID |
Yes |
String |
User ID |
| TKRoomManager.getInstance().playAudio(peerId);
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
unPlayVideo
- A brief description - Stopping user video playback
The effect takes place after calling init. It must be called on the main thread.
parameters
|Parameter Name|Required|Type|Description||:----|:-----|:----- |:----- || peerID |Yes | String | UserID || cameraId |否 | String | The device ID of the video capture device, applicable when the user is publishing from multiple camera devices simultaneously
|
Method Example```java
TKRoomManager.getInstance().unPlayVideo(peerId);OR:
TKRoomManager.getInstance().unPlayVideo(peerId,null);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | - Return Value Description
|Type|Description|
|:----- |:-----|
|int|0: Indicates successful invocation; Non-zero: Indicates invocation failure|
##### unPlayAudio
- A brief description - Stopping user audio playback
- Interface Name
`- (int)unPlayAudio(String peerId);`
- Parameters
|Parameter Name|Required|Type|Description|
|:---- |:---|:----- |----- |
|peerID |Yes|String |User ID |
- Method Example
|
TKRoomManager.getInstance().unPlayAudio(peerId);
| - Return Value Description
|Type|Description|
|:----- |:-----|
|int|0: Indicates successful invocation; Non-zero: Indicates invocation failure|
|