Skip to content

Commit 6f25f65

Browse files
author
xianing
committed
fix set audio profile
1 parent 3a0cde0 commit 6f25f65

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
)
4141
public class SetAudioProfile extends BaseFragment implements View.OnClickListener {
4242
private static final String TAG = JoinChannelAudio.class.getSimpleName();
43+
private Spinner audioProfileInput;
4344
private Spinner audioScenarioInput;
4445
private EditText et_channel;
4546
private Button mute, join, speaker;
@@ -68,6 +69,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
6869
super.onViewCreated(view, savedInstanceState);
6970
join = view.findViewById(R.id.btn_join);
7071
et_channel = view.findViewById(R.id.et_channel);
72+
audioProfileInput = view.findViewById(R.id.audio_profile_spinner);
7173
audioScenarioInput = view.findViewById(R.id.audio_scenario_spinner);
7274
view.findViewById(R.id.btn_join).setOnClickListener(this);
7375
mute = view.findViewById(R.id.microphone);
@@ -110,7 +112,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState)
110112
* The SDK uses this class to report to the app on SDK runtime events.
111113
*/
112114
config.mEventHandler = iRtcEngineEventHandler;
113-
config.mAudioScenario = Constants.AudioScenario.getValue(Constants.AudioScenario.HIGH_DEFINITION);
115+
config.mAudioScenario = Constants.AudioScenario.valueOf(audioScenarioInput.getSelectedItem().toString()).ordinal();
114116
engine = RtcEngine.create(config);
115117
}
116118
catch (Exception e)
@@ -147,6 +149,7 @@ public void onClick(View v)
147149
if (AndPermission.hasPermissions(this, Permission.Group.STORAGE, Permission.Group.MICROPHONE, Permission.Group.CAMERA))
148150
{
149151
joinChannel(channelId);
152+
audioProfileInput.setEnabled(false);
150153
audioScenarioInput.setEnabled(false);
151154
return;
152155
}
@@ -158,6 +161,7 @@ public void onClick(View v)
158161
{
159162
// Permissions Granted
160163
joinChannel(channelId);
164+
audioProfileInput.setEnabled(false);
161165
audioScenarioInput.setEnabled(false);
162166
}).start();
163167
}
@@ -187,6 +191,7 @@ public void onClick(View v)
187191
speaker.setEnabled(false);
188192
mute.setText(getString(R.string.closemicrophone));
189193
mute.setEnabled(false);
194+
audioProfileInput.setEnabled(true);
190195
audioScenarioInput.setEnabled(true);
191196
}
192197
}
@@ -223,8 +228,8 @@ private void joinChannel(String channelId)
223228
{
224229
accessToken = null;
225230
}
226-
int scenario = Constants.AudioScenario.valueOf(audioScenarioInput.getSelectedItem().toString()).ordinal();
227-
engine.setAudioProfile(scenario);
231+
int profile = Constants.AudioProfile.valueOf(audioProfileInput.getSelectedItem().toString()).ordinal();
232+
engine.setAudioProfile(profile);
228233
/** Allows a user to join a channel.
229234
if you do not specify the uid, we will generate the uid for you*/
230235

Android/APIExample/app/src/main/res/layout/fragment_set_audio_profile.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
android:layout_marginEnd="16dp"
2828
android:layout_marginBottom="16dp"/>
2929

30+
<Spinner
31+
android:id="@+id/audio_profile_spinner"
32+
android:layout_width="match_parent"
33+
android:layout_height="48dp"
34+
android:layout_above="@id/audio_scenario_spinner"
35+
android:layout_marginBottom="16dp"
36+
android:entries="@array/audioProfile"
37+
android:hint="Select an Audio Profile"
38+
android:spinnerMode="dropdown" />
3039

3140
<Spinner
3241
android:id="@+id/audio_scenario_spinner"

0 commit comments

Comments
 (0)