Skip to content

Commit 9ddf5dc

Browse files
authored
Merge branch 'dev/3.5.1' into feature-351-2
2 parents f234357 + 34e4b08 commit 9ddf5dc

17 files changed

Lines changed: 386 additions & 145 deletions

File tree

-1.85 MB
Binary file not shown.

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ public void onTokenWillExpire() {
7878
@Override
7979
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
8080
{
81-
View view = inflater.inflate(R.layout.fragment_two_process_screen_share, container, false);
82-
return view;
81+
return inflater.inflate(R.layout.fragment_two_process_screen_share, container, false);
8382
}
8483

8584
@Override
@@ -192,7 +191,8 @@ public void onClick(View v)
192191
* triggers the removeInjectStreamUrl method.*/
193192
engine.leaveChannel();
194193
join.setText(getString(R.string.join));
195-
mSSClient.stop(getContext());
194+
if(isSharing)
195+
mSSClient.stop(getContext());
196196
screenShare.setText(getResources().getString(R.string.screenshare));
197197
screenShare.setEnabled(false);
198198
isSharing = false;
@@ -244,9 +244,6 @@ private void joinChannel(String channelId)
244244
fl_local.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
245245
// Setup local video to render your local camera preview
246246
engine.setupLocalVideo(new VideoCanvas(surfaceView, RENDER_MODE_HIDDEN, 0));
247-
// Set audio route to microPhone
248-
engine.disableAudio();
249-
// engine.setDefaultAudioRoutetoSpeakerphone(false);
250247

251248
/** Sets the channel profile of the Agora RtcEngine.
252249
CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
@@ -281,8 +278,8 @@ private void joinChannel(String channelId)
281278
if you do not specify the uid, we will generate the uid for you*/
282279

283280
ChannelMediaOptions option = new ChannelMediaOptions();
284-
option.autoSubscribeAudio = false;
285-
option.autoSubscribeVideo = false;
281+
option.autoSubscribeAudio = true;
282+
option.autoSubscribeVideo = true;
286283
int res = engine.joinChannel(accessToken, channelId, "Extra Optional Data", 0, option);
287284
if (res != 0)
288285
{

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

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

3+
import static io.agora.api.example.common.model.Examples.ADVANCED;
4+
35
import android.content.Context;
4-
import android.os.AsyncTask;
56
import android.os.Bundle;
67
import android.os.Handler;
78
import android.text.TextUtils;
@@ -12,6 +13,7 @@
1213
import android.widget.Button;
1314
import android.widget.EditText;
1415
import android.widget.SeekBar;
16+
import android.widget.TextView;
1517

1618
import androidx.annotation.NonNull;
1719
import androidx.annotation.Nullable;
@@ -20,8 +22,6 @@
2022
import com.yanzhenjie.permission.AndPermission;
2123
import com.yanzhenjie.permission.runtime.Permission;
2224

23-
import java.text.SimpleDateFormat;
24-
2525
import io.agora.api.component.Constant;
2626
import io.agora.api.example.R;
2727
import io.agora.api.example.annotation.Example;
@@ -33,8 +33,6 @@
3333
import io.agora.rtc.RtcEngine;
3434
import io.agora.rtc.models.ChannelMediaOptions;
3535

36-
import static io.agora.api.example.common.model.Examples.ADVANCED;
37-
3836
@Example(
3937
index = 14,
4038
group = ADVANCED,
@@ -47,12 +45,18 @@ public class PlayAudioFiles extends BaseFragment implements View.OnClickListener
4745
private EditText et_channel;
4846
private AppCompatTextView progressText;
4947
private Button join, bgm_start, bgm_resume, bgm_pause, bgm_stop, effect;
50-
private SeekBar mixingPublishVolBar, mixingPlayoutVolBar, mixingVolBar, mixingProgressBar;
48+
private SeekBar mixingPublishVolBar, mixingPlayoutVolBar, mixingVolBar, mixingProgressBar, sliderSpeed;
49+
private TextView titleSpeed;
50+
private TextView titleTrack;
5151
private RtcEngine engine;
5252
private int myUid;
5353
private boolean joined = false;
5454
private IAudioEffectManager audioEffectManager;
5555

56+
private String currentMusic = Constant.URL_PLAY_AUDIO_FILES;
57+
private int currentTrackIndex;
58+
59+
5660
@Override
5761
public void onCreate(@Nullable Bundle savedInstanceState)
5862
{
@@ -64,8 +68,7 @@ public void onCreate(@Nullable Bundle savedInstanceState)
6468
@Override
6569
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
6670
{
67-
View view = inflater.inflate(R.layout.fragment_play_audio_files, container, false);
68-
return view;
71+
return inflater.inflate(R.layout.fragment_play_audio_files, container, false);
6972
}
7073

7174
@Override
@@ -85,6 +88,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
8588
bgm_stop = view.findViewById(R.id.bgmStop);
8689
bgm_stop.setOnClickListener(this);
8790
effect = view.findViewById(R.id.btn_effect);
91+
sliderSpeed = view.findViewById(R.id.slider_speed_fg_audio_file);
92+
titleSpeed = view.findViewById(R.id.title_speed_fg_audio_file);
93+
titleTrack = view.findViewById(R.id.title_track_fg_audio_file);
8894
effect.setOnClickListener(this);
8995
mixingPublishVolBar = view.findViewById(R.id.mixingPublishVolBar);
9096
mixingPlayoutVolBar = view.findViewById(R.id.mixingPlayoutVolBar);
@@ -94,6 +100,36 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
94100
mixingPlayoutVolBar.setOnSeekBarChangeListener(this);
95101
mixingPublishVolBar.setOnSeekBarChangeListener(this);
96102
mixingVolBar.setOnSeekBarChangeListener(this);
103+
sliderSpeed.setOnSeekBarChangeListener(this);
104+
105+
view.findViewById(R.id.btn_to_last_track_fg_audio_file).setOnClickListener(this);
106+
view.findViewById(R.id.btn_to_next_track_fg_audio_file).setOnClickListener(this);
107+
108+
view.findViewById(R.id.btn_channel_left_fg_audio_file).setOnClickListener(this);
109+
view.findViewById(R.id.btn_channel_right_fg_audio_file).setOnClickListener(this);
110+
view.findViewById(R.id.btn_channel_stereo_fg_audio_file).setOnClickListener(this);
111+
view.findViewById(R.id.btn_channel_mix_fg_audio_file).setOnClickListener(this);
112+
113+
updateSpeedTitle();
114+
updateTrackTitle();
115+
}
116+
117+
/**
118+
* 声道切换
119+
*/
120+
private void updateChannel(int index){
121+
int value = Constants.AudioMixingDualMonoMode.getValue(Constants.AudioMixingDualMonoMode.values()[index]);
122+
engine.setAudioMixingDualMonoMode(value);
123+
}
124+
125+
private void updateSpeedTitle(){
126+
titleSpeed.setText(getString(R.string.play_speed,(sliderSpeed.getProgress()+50)/100f));
127+
}
128+
private void updateTrackTitle(){
129+
int count = 0;
130+
if(engine!=null) count = engine.getAudioTrackCount();
131+
String desc = getString(R.string.track_change,count);
132+
titleTrack.setText(desc);
97133
}
98134

99135
@Override
@@ -177,7 +213,8 @@ public void onClick(View v)
177213
{
178214
if (!joined)
179215
{
180-
CommonUtil.hideInputBoard(getActivity(), et_channel);
216+
et_channel.clearFocus();
217+
CommonUtil.hideInputBoard(requireActivity(), et_channel);
181218
// call when join button hit
182219
String channelId = et_channel.getText().toString();
183220
// Check permission
@@ -228,7 +265,9 @@ public void onClick(View v)
228265
}
229266
else if(v.getId() == R.id.bgmStart)
230267
{
231-
engine.startAudioMixing(Constant.MIX_FILE_PATH, false, false, -1, 0);
268+
sliderSpeed.setProgress(50);
269+
engine.startAudioMixing(currentMusic, false, false, -1, 0);
270+
engine.getAudioFileInfo(currentMusic);
232271
startProgressTimer();
233272
}
234273
else if(v.getId() == R.id.bgmStop){
@@ -254,6 +293,33 @@ else if (v.getId() == R.id.btn_effect)
254293
audioEffectManager.pauseAllEffects();
255294
}
256295
}
296+
else{
297+
switch (v.getId()){
298+
case R.id.btn_to_last_track_fg_audio_file:{
299+
updateTrackTitle();
300+
if(currentTrackIndex==0)
301+
currentTrackIndex = engine.getAudioTrackCount() - 1;
302+
else currentTrackIndex--;
303+
engine.selectAudioTrack(currentTrackIndex);
304+
break;
305+
}
306+
case R.id.btn_to_next_track_fg_audio_file:{
307+
updateTrackTitle();
308+
currentTrackIndex = (++currentTrackIndex) % engine.getAudioTrackCount();
309+
engine.selectAudioTrack(currentTrackIndex);
310+
break;
311+
}
312+
313+
case R.id.btn_channel_left_fg_audio_file:updateChannel(1);
314+
break;
315+
case R.id.btn_channel_right_fg_audio_file:updateChannel(2);
316+
break;
317+
case R.id.btn_channel_stereo_fg_audio_file:updateChannel(0);
318+
break;
319+
case R.id.btn_channel_mix_fg_audio_file:updateChannel(3);
320+
break;
321+
}
322+
}
257323
}
258324

259325
private void stopProgressTimer() {
@@ -262,10 +328,12 @@ private void stopProgressTimer() {
262328
}
263329

264330
private void startProgressTimer() {
265-
int currentPosition = engine.getAudioMixingCurrentPosition();
266-
if(mixingProgressBar.getMax()!=0 && !mixingProgressBar.isPressed())
267-
mixingProgressBar.setProgress(currentPosition);
268-
handler.postDelayed(this::startProgressTimer, 1000);
331+
if(engine != null) {
332+
int currentPosition = engine.getAudioMixingCurrentPosition();
333+
if (mixingProgressBar.getMax() != 0 && !mixingProgressBar.isPressed())
334+
mixingProgressBar.setProgress(currentPosition);
335+
handler.postDelayed(this::startProgressTimer, 1000);
336+
}
269337
}
270338

271339
/**
@@ -370,7 +438,6 @@ public void run()
370438
bgm_pause.setEnabled(true);
371439
bgm_stop.setEnabled(true);
372440
effect.setEnabled(true);
373-
engine.getAudioFileInfo(Constant.MIX_FILE_PATH);
374441
}
375442
});
376443
}
@@ -445,7 +512,7 @@ public void onUserOffline(int uid, int reason)
445512

446513
@Override
447514
public void onRequestAudioFileInfo(AudioFileInfo info, int error) {
448-
Log.d(TAG, "onRequestAudioFileInfo: "+info.filePath);
515+
Log.d(TAG, "onRequestAudioFileInfo: "+info.durationMs);
449516
handler.post(()-> mixingProgressBar.setMax(info.durationMs));
450517
}
451518
};
@@ -476,6 +543,8 @@ else if(seekBar.getId() == R.id.mixingVolBar){
476543
}else if(seekBar.getId() == R.id.mixingProgress){
477544
String durationText = io.agora.api.example.utils.TextUtils.durationFormat((long) progress);
478545
progressText.setText(durationText);
546+
}else if(seekBar.getId() == R.id.slider_speed_fg_audio_file){
547+
updateSpeedTitle();
479548
}
480549

481550
}
@@ -492,7 +561,9 @@ public void onStopTrackingTouch(SeekBar seekBar) {
492561
if(seekBar.getId() == R.id.mixingProgress) {
493562
engine.setAudioMixingPosition(seekBar.getProgress());
494563
handler.postDelayed(this::startProgressTimer, 1000);
564+
} else if(seekBar.getId() == R.id.slider_speed_fg_audio_file){
565+
if(sliderSpeed.isPressed())
566+
engine.setAudioMixingPlaybackSpeed(seekBar.getProgress()+50);
495567
}
496568
}
497-
498569
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import io.agora.rtc.Constants;
4343
import io.agora.rtc.IRtcEngineEventHandler;
4444
import io.agora.rtc.RtcEngine;
45-
import io.agora.rtc.models.ChannelMediaOptions;
4645
import io.agora.rtc.video.VideoCanvas;
4746
import io.agora.rtc.video.VideoEncoderConfiguration;
4847

@@ -310,11 +309,7 @@ private void joinChannel(String channelId) {
310309
}
311310
/** Allows a user to join a channel.
312311
if you do not specify the uid, we will generate the uid for you*/
313-
314-
ChannelMediaOptions option = new ChannelMediaOptions();
315-
option.autoSubscribeAudio = true;
316-
option.autoSubscribeVideo = true;
317-
int res = ENGINE.joinChannel(accessToken, channelId, "Extra Optional Data", 0, option);
312+
int res = ENGINE.joinChannel(accessToken, channelId, "Extra Optional Data", 0);
318313
if (res != 0) {
319314
// Usually happens with invalid parameters
320315
// Error code description can be found at:

0 commit comments

Comments
 (0)