Skip to content

Commit ffcb275

Browse files
authored
Merge pull request #278 from AgoraIO/jira/MS-170833_MS-170820_MS-170804_MS-170803
[Android]fix crash and etc.
2 parents 4727eb9 + c573f43 commit ffcb275

6 files changed

Lines changed: 66 additions & 68 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/MainActivity.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import android.content.Intent;
44
import android.os.Bundle;
5+
import android.util.Log;
56
import android.view.Menu;
67
import android.view.MenuItem;
78

89
import androidx.annotation.NonNull;
910
import androidx.appcompat.app.AppCompatActivity;
10-
import androidx.constraintlayout.solver.GoalRow;
11-
import androidx.navigation.ActionOnlyNavDirections;
1211
import androidx.navigation.NavController;
1312
import androidx.navigation.Navigation;
1413
import androidx.navigation.ui.AppBarConfiguration;
@@ -46,8 +45,12 @@ public void onListFragmentInteraction(Example item) {
4645
ExampleBean exampleBean = new ExampleBean(item.index(), item.group(), item.name(), item.actionId(), item.tipsId());
4746
Bundle bundle = new Bundle();
4847
bundle.putParcelable(Constant.DATA, exampleBean);
49-
Navigation.findNavController(this, R.id.nav_host_fragment)
50-
.navigate(R.id.action_mainFragment_to_Ready, bundle);
48+
try {
49+
Navigation.findNavController(this, R.id.nav_host_fragment)
50+
.navigate(R.id.action_mainFragment_to_Ready, bundle);
51+
} catch (Exception e) {
52+
Log.e(this.getClass().getSimpleName(), "", e);
53+
}
5154
}
5255

5356
@Override

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState)
154154
* The SDK uses this class to report to the app on SDK runtime events.*/
155155
String appId = getString(R.string.agora_app_id);
156156
engine = RtcEngine.create(getContext().getApplicationContext(), appId, iRtcEngineEventHandler);
157-
157+
preloadAudioEffect();
158158
}
159159
catch (Exception e)
160160
{
@@ -173,25 +173,7 @@ private void preloadAudioEffect(){
173173
// Preloads the audio effect (recommended). Note the file size, and preload the file before joining the channel.
174174
// Only mp3, aac, m4a, 3gp, and wav files are supported.
175175
// You may need to record the sound IDs and their file paths.
176-
int id = 0;
177176
audioEffectManager.preloadEffect(0, Constant.EFFECT_FILE_PATH);
178-
/** Plays an audio effect file.
179-
* Returns
180-
* 0: Success.
181-
* < 0: Failure.
182-
*/
183-
audioEffectManager.playEffect(
184-
0, // The sound ID of the audio effect file to be played.
185-
Constant.EFFECT_FILE_PATH, // The file path of the audio effect file.
186-
-1, // The number of playback loops. -1 means an infinite loop.
187-
1, // pitch The pitch of the audio effect. The value ranges between 0.5 and 2. The default value is 1 (no change to the pitch). The lower the value, the lower the pitch.
188-
0.0, // Sets the spatial position of the effect. 0 means the effect shows ahead.
189-
100, // Sets the volume. The value ranges between 0 and 100. 100 is the original volume.
190-
true, // Sets whether to publish the audio effect.
191-
0 // Start position
192-
);
193-
// Pauses all audio effects.
194-
audioEffectManager.pauseAllEffects();
195177
}
196178

197179
@Override
@@ -286,12 +268,25 @@ else if (v.getId() == R.id.btn_effect)
286268
effect.setActivated(!effect.isActivated());
287269
effect.setText(!effect.isActivated() ? getString(R.string.effect_on): getString(R.string.effect_off));
288270
if(effect.isActivated()){
289-
// Resumes playing all audio effects.
290-
audioEffectManager.resumeAllEffects();
271+
/** Plays an audio effect file.
272+
* Returns
273+
* 0: Success.
274+
* < 0: Failure.
275+
*/
276+
audioEffectManager.playEffect(
277+
0, // The sound ID of the audio effect file to be played.
278+
Constant.EFFECT_FILE_PATH, // The file path of the audio effect file.
279+
-1, // The number of playback loops. -1 means an infinite loop.
280+
1, // pitch The pitch of the audio effect. The value ranges between 0.5 and 2. The default value is 1 (no change to the pitch). The lower the value, the lower the pitch.
281+
0.0, // Sets the spatial position of the effect. 0 means the effect shows ahead.
282+
effectVolBar.getProgress(), // Sets the volume. The value ranges between 0 and 100. 100 is the original volume.
283+
true, // Sets whether to publish the audio effect.
284+
0 // Start position
285+
);
291286
}
292287
else {
293-
// Pauses all audio effects.
294-
audioEffectManager.pauseAllEffects();
288+
// Stop audio effects.
289+
audioEffectManager.stopEffect(0);
295290
}
296291
}
297292
else{
@@ -424,7 +419,7 @@ public void onLeaveChannel(RtcStats stats)
424419
public void onJoinChannelSuccess(String channel, int uid, int elapsed)
425420
{
426421
Log.i(TAG, String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
427-
preloadAudioEffect();
422+
428423
showLongToast(String.format("onJoinChannelSuccess channel %s uid %d", channel, uid));
429424
myUid = uid;
430425
joined = true;

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package io.agora.api.example.examples.advanced;
22

3+
import static io.agora.api.example.common.model.Examples.ADVANCED;
4+
import static io.agora.rtc.Constants.RAW_AUDIO_FRAME_OP_MODE_READ_ONLY;
5+
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
6+
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
7+
38
import android.content.ContentResolver;
49
import android.content.ContentValues;
510
import android.content.Context;
@@ -34,8 +39,6 @@
3439
import java.io.OutputStream;
3540
import java.nio.ByteBuffer;
3641

37-
import io.agora.advancedvideo.rawdata.MediaDataAudioObserver;
38-
import io.agora.advancedvideo.rawdata.MediaDataVideoObserver;
3942
import io.agora.api.example.MainApplication;
4043
import io.agora.api.example.R;
4144
import io.agora.api.example.annotation.Example;
@@ -53,11 +56,6 @@
5356
import io.agora.rtc.video.VideoCanvas;
5457
import io.agora.rtc.video.VideoEncoderConfiguration;
5558

56-
import static io.agora.api.example.common.model.Examples.ADVANCED;
57-
import static io.agora.rtc.Constants.RAW_AUDIO_FRAME_OP_MODE_READ_ONLY;
58-
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
59-
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
60-
6159
@Example(
6260
index = 10,
6361
group = ADVANCED,
@@ -468,8 +466,11 @@ public void onLeaveChannel(RtcStats stats) {
468466
super.onLeaveChannel(stats);
469467
Log.i(TAG, String.format("local user %d leaveChannel!", myUid));
470468
showLongToast(String.format("local user %d leaveChannel!", myUid));
471-
snapshot.setEnabled(false);
472-
audioMixingBtn.setEnabled(false);
469+
handler.post(() -> {
470+
snapshot.setEnabled(false);
471+
audioMixingBtn.setEnabled(false);
472+
});
473+
473474
}
474475

475476
/**Occurs when the local user joins a specified channel.

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package io.agora.api.example.examples.advanced;
22

3+
import static io.agora.api.example.common.model.Examples.ADVANCED;
4+
import static io.agora.rtc.Constants.ERR_OK;
5+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT;
6+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR;
7+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_NET_DOWN;
8+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_OK;
9+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR;
10+
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND;
11+
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
12+
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
13+
import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
14+
315
import android.content.Context;
416
import android.os.AsyncTask;
517
import android.os.Bundle;
@@ -34,22 +46,6 @@
3446
import io.agora.rtc.video.VideoCanvas;
3547
import io.agora.rtc.video.VideoEncoderConfiguration;
3648

37-
import static io.agora.api.example.common.model.Examples.ADVANCED;
38-
import static io.agora.rtc.Constants.ERR_FAILED;
39-
import static io.agora.rtc.Constants.ERR_OK;
40-
import static io.agora.rtc.Constants.ERR_PUBLISH_STREAM_INTERNAL_SERVER_ERROR;
41-
import static io.agora.rtc.Constants.ERR_PUBLISH_STREAM_NOT_FOUND;
42-
import static io.agora.rtc.Constants.ERR_TIMEDOUT;
43-
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT;
44-
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR;
45-
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_NET_DOWN;
46-
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_OK;
47-
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR;
48-
import static io.agora.rtc.Constants.RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND;
49-
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
50-
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
51-
import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
52-
5349
/**
5450
* This example demonstrates how to push a stream to an external address.
5551
* <p>
@@ -327,6 +323,7 @@ private void stopPublish() {
327323
* This method removes only one stream RTMP URL address each time it is called.*/
328324
unpublishing = true;
329325
retryTask.cancel(true);
326+
localTranscodingUser = null;
330327
int ret = engine.stopRtmpStream(et_url.getText().toString());
331328
}
332329

@@ -597,7 +594,7 @@ public void onUserJoined(int uid, int elapsed) {
597594
});
598595
/**Determine whether to open transcoding service and whether the current number of
599596
* transcoding users exceeds the maximum number of users*/
600-
if (transCodeSwitch.isChecked() && transcoding.getUserCount() < MAXUserCount) {
597+
if (transCodeSwitch.isChecked() && localTranscodingUser != null && transcoding.getUserCount() < MAXUserCount) {
601598
/**The transcoding images are arranged vertically according to the adding order*/
602599
LiveTranscoding.TranscodingUser transcodingUser = new LiveTranscoding.TranscodingUser();
603600
transcodingUser.x = 0;

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package io.agora.api.example.examples.advanced;
22

3+
import static io.agora.api.example.common.model.Examples.ADVANCED;
4+
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
5+
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
6+
37
import android.content.Context;
48
import android.os.Bundle;
59
import android.text.TextUtils;
@@ -30,13 +34,6 @@
3034
import io.agora.rtc.video.VideoCanvas;
3135
import io.agora.rtc.video.VideoEncoderConfiguration;
3236

33-
import static io.agora.api.example.common.model.Examples.ADVANCED;
34-
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
35-
import static io.agora.rtc.video.VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15;
36-
import static io.agora.rtc.video.VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
37-
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
38-
import static io.agora.rtc.video.VideoEncoderConfiguration.VD_640x360;
39-
4037
/**This demo demonstrates how to make a one-to-one video call*/
4138
@Example(
4239
index = 21,
@@ -488,7 +485,12 @@ public void onUserSuperResolutionEnabled(int uid, boolean enabled, int reason) {
488485
showLongToast(String.format("Super Resolution can't enabled because of reason code: %d", reason));
489486
}
490487
enableSuperResolution = enabled;
491-
btnSuperResolution.setText(enableSuperResolution?getText(R.string.closesuperr):getText(R.string.opensuperr));
488+
handler.post(new Runnable() {
489+
@Override
490+
public void run() {
491+
btnSuperResolution.setText(enableSuperResolution?getText(R.string.closesuperr):getText(R.string.opensuperr));
492+
}
493+
});
492494
}
493495
}
494496
};

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package io.agora.api.example.examples.advanced;
22

3+
import static io.agora.api.example.common.model.Examples.ADVANCED;
4+
import static io.agora.rtc.Constants.REMOTE_VIDEO_STATE_DECODING;
5+
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
6+
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
7+
38
import android.content.Context;
49
import android.os.Bundle;
510
import android.text.TextUtils;
@@ -34,11 +39,6 @@
3439
import io.agora.rtc.video.VideoCanvas;
3540
import io.agora.rtc.video.VideoEncoderConfiguration;
3641

37-
import static io.agora.api.example.common.model.Examples.ADVANCED;
38-
import static io.agora.rtc.Constants.REMOTE_VIDEO_STATE_DECODING;
39-
import static io.agora.rtc.video.VideoCanvas.RENDER_MODE_HIDDEN;
40-
import static io.agora.rtc.video.VideoEncoderConfiguration.STANDARD_BITRATE;
41-
4242
/**---------------------------------------Important!!!----------------------------------------------
4343
* This example demonstrates how audience can quickly switch channels. The following points need to be noted:
4444
1: You can only access the channel as an audience{@link VideoQuickSwitch#joinChannel(String)}.
@@ -250,7 +250,7 @@ private final void joinChannel(String channelId)
250250
an audience can only receive streams.*/
251251
engine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
252252
/**In the demo, the default is to enter as the broadcaster.*/
253-
engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_BROADCASTER);
253+
engine.setClientRole(IRtcEngineEventHandler.ClientRole.CLIENT_ROLE_AUDIENCE);
254254
// Enable video module
255255
engine.enableVideo();
256256
// Setup video encoding configs

0 commit comments

Comments
 (0)