소리를 재생하고 멈추는 가장 좋은 방법은 무엇입니까?Android - 소리 재생 및 중지
RingtoneManager, MediaPlayer 및 SoundPool을 사용했지만 사운드를 중지하지 못했습니다.
RingtoneManager TYPE_ALARM을 사용할 때 소리를 멈출 방법이 있습니까?
간단한 코드를 작성하십시오. 내가 여러 번 호출되는이 기능을 믿고있어
SoundPool pool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
List<Integer> streams = new ArrayList<Integer>();
int soundId = pool.load(getApplicationContext(), R.drawable.alarm, 1); //There are several versions of this, pick which fits your sound
try{
if(myWifiInfo.getRssi() < -55)
{
/*
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();*/
Thread.sleep(1000);
int streamId = -1;
streamId = pool.play(soundId, 1.0f, 1.0f, 1, 0, 1.0f);
streams.add(streamId);
textRssi.setText(String.valueOf(myWifiInfo.getRssi() + " WARNING"));
}
else {
Log.e("WIFI","Usao");
for (Integer stream : streams) {
pool.stop(stream);
}
streams.clear();
Log.e("WIFI","Izasao");
}
시도한 코드를 게시하십시오. 미디어 플레이어와 사운드 풀에 대한 중지 방법이 작동하는 것을 보았습니다. –
@GabeSechan이 (가) 게시물을 편집했습니다. 여기 있습니다. –