Skip to content

Commit aa002d9

Browse files
committed
[Android]fix jira problems: NMS-5478、NMS-5484
1 parent da6cc96 commit aa002d9

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public void onClick(View v) {
177177
engine.stopPreview();
178178
engine.leaveChannel();
179179
join.setText(getString(R.string.join));
180+
remoteUid = 0;
180181
}
181182
} else if (v.getId() == R.id.btn_publish) {
182183
isHost = !isHost;
@@ -236,7 +237,10 @@ public void onClick(View v) {
236237
}
237238
} else if (v.getId() == R.id.btn_take_shot) {
238239
if (remoteUid != 0) {
239-
engine.takeSnapshot(remoteUid, "/sdcard/APIExample_snapshot_" + et_channel.getText().toString() + "_" + remoteUid + ".png");
240+
int ret = engine.takeSnapshot(remoteUid, "/sdcard/APIExample_snapshot_" + et_channel.getText().toString() + "_" + remoteUid + ".png");
241+
if(ret != Constants.ERR_OK){
242+
showLongToast("takeSnapshot error code=" + ret + ",msg=" + RtcEngine.getErrorDescription(ret));
243+
}
240244
} else {
241245
showLongToast(getString(R.string.remote_screenshot_tip));
242246
}
@@ -454,16 +458,18 @@ public void onUserJoined(int uid, int elapsed) {
454458
public void onUserOffline(int uid, int reason) {
455459
Log.i(TAG, String.format("user %d offline! reason:%d", uid, reason));
456460
showLongToast(String.format("user %d offline! reason:%d", uid, reason));
457-
if(uid == remoteUid)
458-
handler.post(new Runnable() {
459-
@Override
460-
public void run() {
461-
/**Clear render view
462-
Note: The video will stay at its last frame, to completely remove it you will need to
463-
remove the SurfaceView from its parent*/
464-
engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
465-
}
466-
});
461+
if(uid == remoteUid) {
462+
remoteUid = 0;
463+
runOnUIThread(new Runnable() {
464+
@Override
465+
public void run() {
466+
/**Clear render view
467+
Note: The video will stay at its last frame, to completely remove it you will need to
468+
remove the SurfaceView from its parent*/
469+
engine.setupRemoteVideo(new VideoCanvas(null, RENDER_MODE_HIDDEN, uid));
470+
}
471+
});
472+
}
467473
}
468474

469475
/**

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
)
4242
public class PlayAudioFiles extends BaseFragment implements View.OnClickListener, SeekBar.OnSeekBarChangeListener {
4343
private static final String TAG = PlayAudioFiles.class.getSimpleName();
44+
private static final int EFFECT_SOUND_ID = 0;
4445
private EditText et_channel;
4546
private Button mute, join, speaker, bgm, effect;
4647
private SeekBar mixingPublishVolBar, mixingPlayoutVolBar, mixingVolBar;
@@ -143,24 +144,31 @@ private void preloadAudioEffect(){
143144
// Only mp3, aac, m4a, 3gp, and wav files are supported.
144145
// You may need to record the sound IDs and their file paths.
145146
int id = 0;
146-
int preloadRet = audioEffectManager.preloadEffect(id++, Constant.EFFECT_FILE_PATH);
147+
audioEffectManager.preloadEffect(id++, Constant.EFFECT_FILE_PATH);
148+
}
149+
150+
private void playEffect() {
147151
/** Plays an audio effect file.
148152
* Returns
149153
* 0: Success.
150154
* < 0: Failure.
151155
*/
152156
int playRet = audioEffectManager.playEffect(
153-
0, // The sound ID of the audio effect file to be played.
157+
EFFECT_SOUND_ID, // The sound ID of the audio effect file to be played.
154158
Constant.EFFECT_FILE_PATH, // The file path of the audio effect file.
155159
-1, // The number of playback loops. -1 means an infinite loop.
156160
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.
157161
0.0, // Sets the spatial position of the effect. 0 means the effect shows ahead.
158162
100, // Sets the volume. The value ranges between 0 and 100. 100 is the original volume.
159163
true // Sets whether to publish the audio effect.
160164
);
161-
// Pauses all audio effects.
162-
int pauseRet = audioEffectManager.pauseAllEffects();
163-
Log.i(TAG, "result preloadRet:" + preloadRet + ", playRet:"+ playRet + ", pauseRet:"+ pauseRet);
165+
Log.i(TAG, "result playRet:"+ playRet);
166+
}
167+
168+
private void stopEffect() {
169+
audioEffectManager.stopEffect(
170+
EFFECT_SOUND_ID // The sound ID of the audio effect file to be played.
171+
);
164172
}
165173

166174
@Override
@@ -266,11 +274,11 @@ else if (v.getId() == R.id.btn_effect)
266274
effect.setText(!effect.isActivated() ? getString(R.string.effect_on): getString(R.string.effect_off));
267275
if(effect.isActivated()){
268276
// Resumes playing all audio effects.
269-
audioEffectManager.resumeAllEffects();
277+
playEffect();
270278
}
271279
else {
272280
// Pauses all audio effects.
273-
audioEffectManager.pauseAllEffects();
281+
stopEffect();
274282
}
275283
}
276284
}

0 commit comments

Comments
 (0)