Skip to content

Commit ca4f7e0

Browse files
committed
[BGF] Push to CDN, Play audio, Set Video Properties crash fixes.
1 parent bdf343b commit ca4f7e0

3 files changed

Lines changed: 52 additions & 43 deletions

File tree

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

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -260,36 +260,40 @@ else if (v.getId() == R.id.btn_effect)
260260
}
261261

262262
private void stopProgressTimer() {
263-
if(!progressTimer.isCancelled()){
264-
progressTimer.cancel(true);
265-
}
263+
handler.removeCallbacksAndMessages(null);
264+
// if(!progressTimer.isCancelled()){
265+
// progressTimer.cancel(true);
266+
// }
266267
}
267268

268269
private void startProgressTimer() {
269-
if(!progressTimer.getStatus().equals(AsyncTask.Status.RUNNING)){
270-
progressTimer.execute();
271-
}
270+
final int result = (int) ((float) engine.getAudioMixingCurrentPosition() / (float) engine.getAudioMixingDuration(Constant.MIX_FILE_PATH) * 100);
271+
mixingProgressBar.setProgress(Long.valueOf(result).intValue());
272+
handler.postDelayed(this::startProgressTimer, 500);
273+
// if(!progressTimer.getStatus().equals(AsyncTask.Status.RUNNING)){
274+
// progressTimer.execute();
275+
// }
272276
}
273277

274-
private final AsyncTask progressTimer = new AsyncTask() {
275-
@Override
276-
protected Object doInBackground(Object[] objects) {
277-
while(true){
278-
try {
279-
handler.post(new Runnable() {
280-
@Override
281-
public void run() {
282-
final int result = (int) ((float) engine.getAudioMixingCurrentPosition() / (float) engine.getAudioMixingDuration(Constant.MIX_FILE_PATH) * 100);
283-
mixingProgressBar.setProgress(Long.valueOf(result).intValue());
284-
}
285-
});
286-
Thread.sleep(500);
287-
} catch (InterruptedException e) {
288-
Log.e(TAG, e.getMessage());
289-
}
290-
}
291-
}
292-
};
278+
// private final AsyncTask progressTimer = new AsyncTask() {
279+
// @Override
280+
// protected Object doInBackground(Object[] objects) {
281+
// while(true){
282+
// try {
283+
// handler.post(new Runnable() {
284+
// @Override
285+
// public void run() {
286+
// final int result = (int) ((float) engine.getAudioMixingCurrentPosition() / (float) engine.getAudioMixingDuration(Constant.MIX_FILE_PATH) * 100);
287+
// mixingProgressBar.setProgress(Long.valueOf(result).intValue());
288+
// }
289+
// });
290+
// Thread.sleep(500);
291+
// } catch (InterruptedException e) {
292+
// Log.e(TAG, e.getMessage());
293+
// }
294+
// }
295+
// }
296+
// };
293297

294298
/**
295299
* @param channelId Specify the channel name that you want to join.

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public void onDestroy() {
137137
if (engine != null) {
138138
engine.leaveChannel();
139139
}
140+
if(retryTask!=null) retryTask.cancel(true);
140141
handler.post(RtcEngine::destroy);
141142
engine = null;
142143
}
@@ -313,6 +314,22 @@ private void startPublish() {
313314
* This method adds only one stream HTTP/HTTPS URL address each time it is called.*/
314315
int code = engine.addPublishStreamUrl(et_url.getText().toString(), transCodeSwitch.isChecked());
315316
if(code == 0){
317+
retryTask = new AsyncTask() {
318+
@Override
319+
protected Object doInBackground(Object[] objects) {
320+
Integer result = null;
321+
for (int i = 0; i < MAX_RETRY_TIMES; i++) {
322+
try {
323+
Thread.sleep(60 * 1000);
324+
} catch (InterruptedException e) {
325+
Log.e(TAG, e.getMessage());
326+
break;
327+
}
328+
result = engine.addPublishStreamUrl(et_url.getText().toString(), transCodeSwitch.isChecked());
329+
}
330+
return result;
331+
}
332+
};
316333
retryTask.execute();
317334
}
318335
/**Prevent repeated entry*/
@@ -338,6 +355,7 @@ private void stopPublish() {
338355
* This method applies to Live Broadcast only.
339356
* This method removes only one stream RTMP URL address each time it is called.*/
340357
unpublishing = true;
358+
retryTask.cancel(true);
341359
int ret = engine.removePublishStreamUrl(et_url.getText().toString());
342360
}
343361

@@ -688,19 +706,5 @@ public void run() {
688706
}
689707
};
690708

691-
private final AsyncTask retryTask = new AsyncTask() {
692-
@Override
693-
protected Object doInBackground(Object[] objects) {
694-
Integer result = null;
695-
for (int i = 0; i < MAX_RETRY_TIMES; i++) {
696-
try {
697-
Thread.sleep(60 * 1000);
698-
} catch (InterruptedException e) {
699-
Log.e(TAG, e.getMessage());
700-
}
701-
result = engine.addPublishStreamUrl(et_url.getText().toString(), transCodeSwitch.isChecked());
702-
}
703-
return result;
704-
}
705-
};
709+
private AsyncTask retryTask;
706710
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
3939
import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
4040
import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
41+
import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_LANDSCAPE;
4142
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
4243
import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
4344

@@ -277,9 +278,9 @@ private void joinChannel(String channelId)
277278

278279
engine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
279280
value,
280-
VideoEncoderConfiguration.FRAME_RATE.valueOf(framerate.getSelectedItem().toString()),
281-
Integer.valueOf(et_bitrate.getText().toString()),
282-
VideoEncoderConfiguration.ORIENTATION_MODE.valueOf(orientation.getSelectedItem().toString())
281+
VideoEncoderConfiguration.FRAME_RATE.values()[framerate.getSelectedItemPosition()],
282+
Integer.parseInt(et_bitrate.getText().toString()),
283+
VideoEncoderConfiguration.ORIENTATION_MODE.values()[orientation.getSelectedItemPosition()]
283284
));
284285

285286
/**Please configure accessToken in the string_config file.

0 commit comments

Comments
 (0)