Pergunta

I have the following code:

mVisualizer = new Visualizer(0);
mVisualizer.setEnabled(false);
int capRate = Visualizer.getMaxCaptureRate();
int capSize = Visualizer.getCaptureSizeRange()[1];
mVisualizer.setCaptureSize(capSize);
Visualizer.OnDataCaptureListener captureListener = new Visualizer.OnDataCaptureListener() {
  public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
  int samplingRate) {   
    for (int i=0;i<bytes.length;i++) {
        if (bytes[i]!=-128) {
            Log.w("Morphyre", "Found Nonzero sample "+bytes[i]);
            break;
        }
    }                   
  }

  public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
    int samplingRate) {
  }       
};

int status = mVisualizer.setDataCaptureListener(captureListener,
    capRate, true/*wave*/, false/*no fft needed*/);
mVisualizer.setEnabled(true);

The app has the 2 required permissions ( MODIFY_AUDIO_SETTINGS and RECORD_AUDIO )

According to the API docs, creating Visualizer(0) will use the 'Audio Output Mix' - however my code appears to initialise just fine (status==0), and the callbacks are called, but I never get data other than 128 (in the case of the wave callback) or 0 (in the case of the FFT) whenever I play with the default media player (on an HTC Sensation XE)

Am I doing something stupid here - or is it likely that my phone doesn't implement the Audio output Mix properly? If I use another audio player then it is fine.

Foi útil?

Solução

It's possible that HTC's media player is applying effects of its own, and in that case they're probably applying it on their player's audio session specifically. The AudioFlinger will suspend all effects on the OUTPUT_MIX session if any effects are being applied on another session. At least that's how it should behave on Jellybean and ICS - having both kinds might work on Gingerbread.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top