2013-02-28 2 views
1

사운드 보드를 쓰고 있습니다. 사운드를 재생하기 위해 버튼을 누를 때 소리가 들리는 지 먼저 확인합니다. 그래서 그것은 그 소리를 멈추고 새 소리를 시작할 수 있습니다.Android : SoundPool의 사운드가 여전히 재생 중인지 감지하는 방법이 있습니까

/** The audio stream for phone calls */ 
public static final int STREAM_VOICE_CALL = AudioSystem.STREAM_VOICE_CALL; 
/** The audio stream for system sounds */ 
public static final int STREAM_SYSTEM = AudioSystem.STREAM_SYSTEM; 
/** The audio stream for the phone ring */ 
public static final int STREAM_RING = AudioSystem.STREAM_RING; 
/** The audio stream for music playback */ 
public static final int STREAM_MUSIC = AudioSystem.STREAM_MUSIC; 
/** The audio stream for alarms */ 
public static final int STREAM_ALARM = AudioSystem.STREAM_ALARM; 
/** The audio stream for notifications */ 
public static final int STREAM_NOTIFICATION = AudioSystem.STREAM_NOTIFICATION; 
/** @hide The audio stream for phone calls when connected to bluetooth */ 
public static final int STREAM_BLUETOOTH_SCO = AudioSystem.STREAM_BLUETOOTH_SCO; 
/** @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */ 
public static final int STREAM_SYSTEM_ENFORCED = AudioSystem.STREAM_SYSTEM_ENFORCED; 
/** The audio stream for DTMF Tones */ 
public static final int STREAM_DTMF = AudioSystem.STREAM_DTMF; 
/** @hide The audio stream for text to speech (TTS) */ 
public static final int STREAM_TTS = AudioSystem.STREAM_TTS; 

확인 :

는, 자신의 사운드 ID가 여전히 재생하는 경우, 내 소리를

// Sound code 
void StartSound(int id) 
{ 
    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); 
    float actualVolume = (float) audioManager 
      .getStreamVolume(AudioManager.STREAM_MUSIC); 
    float maxVolume = (float) audioManager 
      .getStreamMaxVolume(AudioManager.STREAM_MUSIC); 

    float volume=(float) ((float)cGlobals.gVol/100.00); 
    // Is the sound loaded already? 

     soundPool.play(id, volume, volume, 1, 0, 1f); 

} 

답변

0
class AudioSystem{ 
    /* 
    * Checks whether the specified stream type is active. 
    * 
    * return true if any track playing on this stream is active. 
    */ 
    public static native boolean isStreamActive(int stream, int inPastMs); 
} 

그리고 스트림을 시작하려면 다음 코드를 jsing있어 볼 수있는 방법이 있나요 확인하려는 오디오 스트림 유형에 관계없이 예를 들어, AudioSystem.isStreamActive(STREAM_MUSIC, 0)은 음악이 활성화되어 있는지 확인합니다.

+1

안드로이드 클래스'AudioSystem'은 이제 [AudioManager'] (http://developer.android.com/reference/android/media/AudioManager.html) 클래스로 바뀌었고' isStreamActive()'. – Micer

+0

작동하지 않음 :(이 방법은 더 이상 사용할 수 없습니다. –

1

isMusicActive() 방법은 AudioManager입니다.

관련 문제