4

Can any one please help me to find any way to find amplitude of different audioPlayer with in app? I need to know the amplitude of videoCall's audio in my app.

Example in my app I have a videoPlayer (youtube) and videoCall feature. So when I get videoCall, I need to slow/stop the videoPlayer's sound when someOne speaks on videoCall. Is there any way to find that?

I found a method to get amplitude of phone's audioPlayer, but this provides amplitude of all kind of audios playing in app without sending any identifier of source or streamType(MUSIC_STREAM or CALL_STREAM) or any thing different using which I can identify source of given amplitude like its of player or videoCalls.

This will only help if I will provide audioSessionId of AudioPlayer in Visualizer(audioSessionId), but I can't get audioSessionId of any player (videoCall, youtube), because of ThirdPartySDK.

private void createVisualizer(){
    int rate = Visualizer.getMaxCaptureRate();
    Visualizer audioOutput = new Visualizer(0); //  get output audio stream
    audioOutput.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {
        @Override
        public void onWaveFormDataCapture(Visualizer visualizer, byte[] waveform, int samplingRate) {
            float intensity = ((float) waveform[0] + 128f) / 256;
            Log.d("visualizer = ", "visualizer = "+visualizer+ "visualizer = "+String.valueOf(intensity));
        }

        @Override
        public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate) {

        }
    },rate , true, false); // waveform not freq data
    Log.d("rate", String.valueOf(Visualizer.getMaxCaptureRate()));
    audioOutput.setEnabled(true);
}

Any suggestion would be helpful, Thanks in advance.

NehaK
  • 2,639
  • 1
  • 15
  • 31
  • 1
    why someone gave -1 point? – NehaK Jul 18 '17 at 06:59
  • This question shows how difficult this is:- https://stackoverflow.com/questions/31616084/retrieving-the-application-name-that-has-audio-focus-change – Jon Goodwin Jul 31 '17 at 11:32
  • @NehaK What are you trying to accomplish? Are both players part of your app? Or you are indeed talking about other apps? – Ashish Pathak Aug 02 '17 at 10:18
  • no I want to get them in one app, both players are in one app – NehaK Aug 02 '17 at 12:12
  • i think Android is capable of doing this. I experience this everytime im playing music on my phone, then suddenly an SMS comes in. Music audio lowers a bit so you can hear the SMS notification. But I don't think you can do this from an app. I think Android framework does this automatically for you. I am interested how you solve this though. +1 – user1506104 Aug 03 '17 at 09:13

1 Answers1

0

I found solution, the SDK I used for VideoCall provides all user's voice level, So I used that to implement my feature.

And other solution I found was to use MediaRecorder, which provides sound's level of different sources like - MIC, VOICE_CALL etc. But as SDK was already using MediaRecorder internally and android doesn't allow to use 2 instances of MediaRecorder at a same time So it didn't work for me.

android: Detect sound level

NehaK
  • 2,639
  • 1
  • 15
  • 31