Skip to content

Commit 1f6a33f

Browse files
1:add transCoding function. 2:organized code.
Former-commit-id: 1603d8f
1 parent 6c3beae commit 1f6a33f

File tree

1 file changed

+37
-36
lines changed
  • Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced

1 file changed

+37
-36
lines changed

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/RTMPStreaming.java

+37-36
Original file line numberDiff line numberDiff line change
@@ -236,41 +236,42 @@ private void joinChannel(String channelId) {
236236
}
237237

238238
private void startPublish() {
239-
/**LiveTranscoding: A class for managing user-specific CDN live audio/video transcoding settings.
240-
* See <a href="https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1live_1_1_live_transcoding.html"></a>*/
241-
transcoding.width = dimensions.height;
242-
transcoding.height = dimensions.width;
243-
transcoding.backgroundColor = getResources().getColor(R.color.colorAccent);
244-
/**The transcodingUser class which defines the video properties of the user displaying the
245-
* video in the CDN live. Agora supports a maximum of 17 transcoding users in a CDN live streaming channel.
246-
* See <a href="https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1live_1_1_live_transcoding_1_1_transcoding_user.html"></a>*/
247-
localTranscodingUser = new LiveTranscoding.TranscodingUser();
248-
localTranscodingUser.x = 0;
249-
localTranscodingUser.y = 0;
250-
localTranscodingUser.width = transcoding.width;
251-
localTranscodingUser.height = transcoding.height / MAXUserCount;
252-
localTranscodingUser.uid = myUid;
253-
/**Adds a user displaying the video in CDN live.
254-
* @return
255-
* 0: Success.
256-
* <0: Failure.*/
257-
int ret = transcoding.addUser(localTranscodingUser);
258-
/**Sets the video layout and audio settings for CDN live.
259-
* The SDK triggers the onTranscodingUpdated callback when you call this method to update
260-
* the LiveTranscodingclass. If you call this method to set the LiveTranscoding class for
261-
* the first time, the SDK does not trigger the onTranscodingUpdated callback.
262-
* @param transcoding Sets the CDN live audio/video transcoding settings See
263-
* <a href="https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1live_1_1_live_transcoding.html"></a>
264-
* @return
265-
* 0: Success.
266-
* <0: Failure.
267-
* PS:
268-
* This method applies to Live Broadcast only.
269-
* Ensure that you enable the RTMP Converter service before using this function. See
270-
* Prerequisites in Push Streams to CDN.
271-
* Ensure that you call the setClientRole method and set the user role as the host.
272-
* Ensure that you call the setLiveTranscoding method before calling the addPublishStreamUrl method.*/
273-
engine.setLiveTranscoding(transcoding);
239+
if (transCodeSwitch.isChecked()) {
240+
/**LiveTranscoding: A class for managing user-specific CDN live audio/video transcoding settings.
241+
* See <a href="https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1live_1_1_live_transcoding.html"></a>*/
242+
transcoding.width = dimensions.height;
243+
transcoding.height = dimensions.width;
244+
/**The transcodingUser class which defines the video properties of the user displaying the
245+
* video in the CDN live. Agora supports a maximum of 17 transcoding users in a CDN live streaming channel.
246+
* See <a href="https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1live_1_1_live_transcoding_1_1_transcoding_user.html"></a>*/
247+
localTranscodingUser = new LiveTranscoding.TranscodingUser();
248+
localTranscodingUser.x = 0;
249+
localTranscodingUser.y = 0;
250+
localTranscodingUser.width = transcoding.width;
251+
localTranscodingUser.height = transcoding.height / MAXUserCount;
252+
localTranscodingUser.uid = myUid;
253+
/**Adds a user displaying the video in CDN live.
254+
* @return
255+
* 0: Success.
256+
* <0: Failure.*/
257+
int ret = transcoding.addUser(localTranscodingUser);
258+
/**Sets the video layout and audio settings for CDN live.
259+
* The SDK triggers the onTranscodingUpdated callback when you call this method to update
260+
* the LiveTranscodingclass. If you call this method to set the LiveTranscoding class for
261+
* the first time, the SDK does not trigger the onTranscodingUpdated callback.
262+
* @param transcoding Sets the CDN live audio/video transcoding settings See
263+
* <a href="https://docs.agora.io/en/Video/API%20Reference/java/classio_1_1agora_1_1rtc_1_1live_1_1_live_transcoding.html"></a>
264+
* @return
265+
* 0: Success.
266+
* <0: Failure.
267+
* PS:
268+
* This method applies to Live Broadcast only.
269+
* Ensure that you enable the RTMP Converter service before using this function. See
270+
* Prerequisites in Push Streams to CDN.
271+
* Ensure that you call the setClientRole method and set the user role as the host.
272+
* Ensure that you call the setLiveTranscoding method before calling the addPublishStreamUrl method.*/
273+
engine.setLiveTranscoding(transcoding);
274+
}
274275
/**Publishes the local stream to the CDN.
275276
* The addPublishStreamUrl method call triggers the onRtmpStreamingStateChanged callback on
276277
* the local client to report the state of adding a local stream to the CDN.
@@ -295,7 +296,7 @@ private void startPublish() {
295296
* This method applies to Live Broadcast only.
296297
* Ensure that the user joins a channel before calling this method.
297298
* This method adds only one stream HTTP/HTTPS URL address each time it is called.*/
298-
int code = engine.addPublishStreamUrl(et_url.getText().toString(), true);
299+
int code = engine.addPublishStreamUrl(et_url.getText().toString(), transCodeSwitch.isChecked());
299300
/**Prevent repeated entry*/
300301
publish.setEnabled(false);
301302
}

0 commit comments

Comments
 (0)