Skip to content

Commit 82e2dde

Browse files
1:fix bugs.
Former-commit-id: 09d53dc
1 parent 1f6a33f commit 82e2dde

File tree

1 file changed

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

1 file changed

+37
-12
lines changed

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

+37-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.yanzhenjie.permission.AndPermission;
2222
import com.yanzhenjie.permission.runtime.Permission;
2323

24+
import io.agora.api.component.Constant;
2425
import io.agora.api.example.R;
2526
import io.agora.api.example.annotation.Example;
2627
import io.agora.api.example.common.BaseFragment;
@@ -66,7 +67,7 @@ public class RTMPStreaming extends BaseFragment implements View.OnClickListener
6667
private int myUid;
6768
private boolean joined = false, publishing = false;
6869
private VideoEncoderConfiguration.VideoDimensions dimensions = VD_640x360;
69-
private LiveTranscoding transcoding = new LiveTranscoding();
70+
private LiveTranscoding transcoding;
7071
/**
7172
* Maximum number of users participating in transcoding (even number)
7273
*/
@@ -177,7 +178,6 @@ private void joinChannel(String channelId) {
177178
if (context == null) {
178179
return;
179180
}
180-
181181
// Create render view by RtcEngine
182182
SurfaceView surfaceView = RtcEngine.CreateRendererView(context);
183183
// Local video is on the top
@@ -239,6 +239,7 @@ private void startPublish() {
239239
if (transCodeSwitch.isChecked()) {
240240
/**LiveTranscoding: A class for managing user-specific CDN live audio/video transcoding settings.
241241
* 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 = new LiveTranscoding();
242243
transcoding.width = dimensions.height;
243244
transcoding.height = dimensions.width;
244245
/**The transcodingUser class which defines the video properties of the user displaying the
@@ -299,12 +300,11 @@ private void startPublish() {
299300
int code = engine.addPublishStreamUrl(et_url.getText().toString(), transCodeSwitch.isChecked());
300301
/**Prevent repeated entry*/
301302
publish.setEnabled(false);
303+
/**Prevent duplicate clicks*/
304+
transCodeSwitch.setEnabled(false);
302305
}
303306

304307
private void stopPublish() {
305-
publishing = false;
306-
publish.setEnabled(true);
307-
publish.setText(getString(R.string.publish));
308308
/**Removes an RTMP stream from the CDN.
309309
* This method removes the RTMP URL address (added by addPublishStreamUrl) from a CDN live
310310
* stream. The SDK reports the result of this method call in the onRtmpStreamingStateChanged callback.
@@ -368,7 +368,6 @@ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
368368
handler.post(new Runnable() {
369369
@Override
370370
public void run() {
371-
transCodeSwitch.setEnabled(false);
372371
join.setEnabled(true);
373372
join.setText(getString(R.string.leave));
374373
publish.setEnabled(true);
@@ -511,12 +510,27 @@ public void onRtmpStreamingStateChanged(String url, int state, int errCode) {
511510
if (state == Constants.RTMP_STREAM_PUBLISH_STATE_RUNNING) {
512511
/**After confirming the successful push, make changes to the UI.*/
513512
publishing = true;
514-
handler.post(new Runnable() {
515-
@Override
516-
public void run() {
517-
publish.setEnabled(true);
518-
publish.setText(getString(R.string.stoppublish));
519-
}
513+
handler.post(() -> {
514+
publish.setEnabled(true);
515+
publish.setText(getString(R.string.stoppublish));
516+
});
517+
} else if (state == Constants.RTMP_STREAM_PUBLISH_STATE_FAILURE) {
518+
/**if failed, make changes to the UI.*/
519+
publishing = true;
520+
handler.post(() -> {
521+
publish.setEnabled(true);
522+
publish.setText(getString(R.string.publish));
523+
transCodeSwitch.setEnabled(true);
524+
publishing = false;
525+
});
526+
} else if (state == Constants.RTMP_STREAM_PUBLISH_STATE_IDLE) {
527+
/**Push stream not started or ended, make changes to the UI.*/
528+
publishing = true;
529+
handler.post(() -> {
530+
publish.setEnabled(true);
531+
publish.setText(getString(R.string.publish));
532+
transCodeSwitch.setEnabled(true);
533+
publishing = false;
520534
});
521535
}
522536
}
@@ -585,6 +599,17 @@ public void run() {
585599
Note: The video will stay at its last frame, to completely remove it you will need to
586600
remove the SurfaceView from its parent*/
587601
engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
602+
if(transcoding != null) {
603+
/**Removes a user from CDN live.
604+
* @return
605+
* 0: Success.
606+
* < 0: Failure.*/
607+
int code = transcoding.removeUser(uid);
608+
if (code == Constants.ERR_OK) {
609+
/**refresh transCoding configuration*/
610+
engine.setLiveTranscoding(transcoding);
611+
}
612+
}
588613
}
589614
});
590615
}

0 commit comments

Comments
 (0)