Skip to content

Commit 66b0ecd

Browse files
committed
[Android]fix jira problems: NMS-5439, NMS-5460, NMS-5449, NMS-5457, NMS-5435,NMS-5436
1 parent 70a60b9 commit 66b0ecd

6 files changed

Lines changed: 45 additions & 32 deletions

File tree

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
286286
user.height = canvas_height;
287287
user.uid = localUid;
288288
liveTranscoding.addUser(user);
289-
engine.setLiveTranscoding(liveTranscoding);
289+
engine.updateRtmpTranscoding(liveTranscoding);
290290
}
291291

292292

@@ -360,34 +360,32 @@ public void run() {
360360
public void onRtmpStreamingStateChanged(String url, int state, int errCode) {
361361
super.onRtmpStreamingStateChanged(url, state, errCode);
362362
showLongToast(String.format("onRtmpStreamingStateChanged state %s errCode %s", state, errCode));
363+
if(state == Constants.RTMP_STREAM_PUBLISH_STATE_IDLE){
364+
if (cdnStreaming) {
365+
runOnUIThread(() -> {
366+
LeaveChannelOptions leaveChannelOptions = new LeaveChannelOptions();
367+
leaveChannelOptions.stopMicrophoneRecording = false;
368+
engine.leaveChannel(leaveChannelOptions);
369+
fl_remote.removeAllViews();
370+
fl_remote_2.removeAllViews();
371+
fl_remote_3.removeAllViews();
372+
remoteViews.clear();
373+
engine.startPreview();
374+
engine.setDirectCdnStreamingVideoConfiguration(videoEncoderConfiguration);
375+
int ret = startCdnStreaming();
376+
if (ret != 0) {
377+
showLongToast(String.format("startCdnStreaming failed! error code: %d", ret));
378+
stopStreaming();
379+
}
380+
});
381+
}
382+
}
363383
}
364384

365385
@Override
366386
public void onTranscodingUpdated() {
367387
showLongToast("RTMP transcoding updated successfully!");
368388
}
369-
370-
@Override
371-
public void onStreamUnpublished(String url) {
372-
if (cdnStreaming) {
373-
runOnUIThread(() -> {
374-
LeaveChannelOptions leaveChannelOptions = new LeaveChannelOptions();
375-
leaveChannelOptions.stopMicrophoneRecording = false;
376-
engine.leaveChannel(leaveChannelOptions);
377-
fl_remote.removeAllViews();
378-
fl_remote_2.removeAllViews();
379-
fl_remote_3.removeAllViews();
380-
remoteViews.clear();
381-
engine.startPreview();
382-
engine.setDirectCdnStreamingVideoConfiguration(videoEncoderConfiguration);
383-
int ret = startCdnStreaming();
384-
if (ret != 0) {
385-
showLongToast(String.format("startCdnStreaming failed! error code: %d", ret));
386-
stopStreaming();
387-
}
388-
});
389-
}
390-
}
391389
};
392390

393391
private void updateTranscodeLayout() {
@@ -433,7 +431,7 @@ private void updateTranscodeLayout() {
433431
Log.i(TAG, "ignored user as only 2x2 video layout supported in this demo. uid:" + uid);
434432
}
435433
}
436-
engine.setLiveTranscoding(liveTranscoding);
434+
engine.updateRtmpTranscoding(liveTranscoding);
437435
}
438436

439437
private final IDirectCdnStreamingEventHandler iDirectCdnStreamingEventHandler = new IDirectCdnStreamingEventHandler() {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ public void onLeaveChannel(RtcStats stats) {
287287
Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
288288
showLongToast(String.format("local user %d leaveChannel!", myUid));
289289
lastI420Frame = null;
290-
mSurfaceView.requestRender();
290+
if(mSurfaceView != null){
291+
mSurfaceView.requestRender();
292+
}
291293
}
292294

293295
/**Occurs when the local user joins a specified channel.
@@ -439,7 +441,9 @@ public void onUserJoined(int uid, int elapsed)
439441
public void onUserOffline(int uid, int reason) {
440442
Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
441443
showLongToast(String.format("user %d offline! reason:%d", uid, reason));
442-
mSurfaceView.requestRender();
444+
if(mSurfaceView != null){
445+
mSurfaceView.requestRender();
446+
}
443447
remoteUid = 0;
444448
}
445449
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public void onClick(View v) {
174174
* the onLeaveChannel callback.
175175
* 2:If you call the leaveChannel method during CDN live streaming, the SDK
176176
* triggers the removeInjectStreamUrl method.*/
177+
engine.stopPreview();
177178
engine.leaveChannel();
178179
join.setText(getString(R.string.join));
179180
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
128128
publish = view.findViewById(R.id.publish);
129129

130130
progressBar = view.findViewById(R.id.ctrl_progress_bar);
131+
progressBar.setMax(100);
131132
progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
132133
@Override
133134
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@@ -204,8 +205,6 @@ public void onClick(View v) {
204205
engine.stopPreview();
205206
join.setText(getString(R.string.join));
206207
mediaPlayer.stop();
207-
mediaPlayer.destroy();
208-
mediaPlayer.unRegisterPlayerObserver(this);
209208
open.setEnabled(false);
210209
setMediaPlayerViewEnable(false);
211210
}
@@ -514,7 +513,7 @@ public void run() {
514513

515514
@Override
516515
public void onPlayerStateChanged(io.agora.mediaplayer.Constants.MediaPlayerState mediaPlayerState, io.agora.mediaplayer.Constants.MediaPlayerError mediaPlayerError) {
517-
Log.e(TAG, "onPlayerStateChanged mediaPlayerState " + mediaPlayerState);
516+
Log.e(TAG, "onPlayerStateChanged mediaPlayerState " + mediaPlayerState + ", error=" + mediaPlayerError);
518517
if (mediaPlayerState.equals(PLAYER_STATE_OPEN_COMPLETED)) {
519518
setMediaPlayerViewEnable(true);
520519
} else if (mediaPlayerState.equals(PLAYER_STATE_IDLE) || mediaPlayerState.equals(PLAYER_STATE_STOPPED) || mediaPlayerState.equals(PLAYER_STATE_PLAYBACK_COMPLETED) ) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ else if (v.getId() == R.id.btn_speaker)
246246
speaker.setActivated(!speaker.isActivated());
247247
speaker.setText(getString(speaker.isActivated() ? R.string.speaker : R.string.earpiece));
248248
/**Turn off / on the speaker and change the audio playback route.*/
249-
engine.setDefaultAudioRoutetoSpeakerphone(speaker.isActivated());
249+
engine.setEnableSpeakerphone(speaker.isActivated());
250250
}
251251
else if(v.getId() == R.id.btn_bgm)
252252
{

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class CustomAudioSource extends BaseFragment implements View.OnClickListe
6464
private static final Integer PUSH_INTERVAL = SAMPLES * 1000 / SAMPLE_RATE;
6565

6666
private InputStream inputStream;
67-
private Thread pushingTask = new Thread(new PushingTask());
67+
private Thread pushingTask;
6868
private boolean pushing = false;
6969

7070
@Override
@@ -251,6 +251,14 @@ public void onClick(View v) {
251251
join.setText(getString(R.string.join));
252252
mic.setEnabled(false);
253253
pcm.setEnabled(false);
254+
if(pushingTask != null){
255+
try {
256+
pushingTask.join();
257+
pushingTask = null;
258+
} catch (InterruptedException e) {
259+
// do nothing
260+
}
261+
}
254262
}
255263
}
256264
}
@@ -341,7 +349,10 @@ public void run() {
341349
join.setEnabled(true);
342350
join.setText(getString(R.string.leave));
343351
pushing = true;
344-
pushingTask.start();
352+
if(pushingTask == null){
353+
pushingTask = new Thread(new PushingTask());
354+
pushingTask.start();
355+
}
345356
}
346357
});
347358
}

0 commit comments

Comments
 (0)