gpt4 book ai didi

安卓闹钟调整闹钟音量

转载 作者:太空狗 更新时间:2023-10-29 15:21:57 26 4
gpt4 key购买 nike

我正在创建一个闹钟应用程序。我列出了所有可用的铃声(不仅是标准的闹钟铃声)。当用户单击列表中的音调时,我使用 MediaPlayer 播放它。在此期间,我还希望能够使用音量按钮(在电话上)调整闹钟音量。但是当我按下这些按钮时,我调整的是媒体音量,而不是警报音量。

有什么办法解决这个问题吗?

这是我用来显示音调的代码

private void chooseTone(final ArrayList<String> tones, final ArrayList<String> paths) {
//final String lastRingtone = tuneName.getText().toString();
//int i = tones.indexOf(lastRingtone);
int i ;
try {
i = paths.indexOf(crt.tune);
} catch (NullPointerException ex) {
i = -1;
}
final AlertDialog alert = new AlertDialog.Builder(this).setTitle("Ringtone").
setSingleChoiceItems(tones.toArray(new String[]{}), i, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int index) {
String currentPath = paths.get(index);
try {
if (mp != null)
mp.stop();
mp = new MediaPlayer();
mp.setDataSource(currentPath);
mp.prepare();
mp.seekTo(0);
mp.start();
} catch (Exception ex) {
}
selectedRingtoneIndex = index;
}
}).create();

alert.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
tuneName.setText(tones.get(selectedRingtoneIndex));
//uri = Uri.parse(paths.get(selectedRingtoneIndex));
crt.tune = paths.get(selectedRingtoneIndex);
try {
mp.stop();
} catch (Exception ex) {}
}
});
alert.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
try {
mp.stop();
} catch (Exception ex) {}
}
});
alert.show();
}

最佳答案

使用:

setVolumeControlStream(AudioManager.STREAM_ALARM);

关于安卓闹钟调整闹钟音量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6791241/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com