我正在創建鬧鐘應用程序。我列出了所有可用的鈴聲(不僅是標準鬧鐘鈴聲)。當用戶從列表中點擊音調時,我使用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();
}
加百列,你有沒有解決過這個問題? – pgsandstrom
@sandis不是真的:(我終於讓它成爲了,並添加了一個選項來配置設置中的鬧鐘音量。希望我已經能夠做到這一點,儘管 – Gabriel