Equalizers, bassboost and reverb effect not working (using FFmpegMediaPlayer)

时间:2018-02-01 18:28:48

标签: android c++ ffmpeg android-mediaplayer android-ffmpeg

I'm currently using FFmpegMediaPlayer from github and the effects are not working in the phone but works perfectly in the emulator which of both are the same API 22.

The strange thing is that when I switch the code from FFmpegMediaplayer to standard android media player the effects start working again in the real phone device. But when I switch back to ffpmeg the effect only works in the emulator and not in the real device. My code is as below,

 public void setupVisualizerFxAndUI() {

    try {
        mVisualizer = new Visualizer(mMediaPlayer.getAudioSessionId());
        mEqualizer = new Equalizer(0, mMediaPlayer.getAudioSessionId());
        mEqualizer.setEnabled(true);

        try {
            bassBoost = new BassBoost(0, mMediaPlayer.getAudioSessionId());
            bassBoost.setEnabled(false);
            BassBoost.Settings bassBoostSettingTemp = bassBoost.getProperties();
            BassBoost.Settings bassBoostSetting = new BassBoost.Settings(bassBoostSettingTemp.toString());
            bassBoostSetting.strength = (1000 / 19);
            bassBoost.setProperties(bassBoostSetting);
            mMediaPlayer.setAuxEffectSendLevel(1.0f);

            presetReverb = new PresetReverb(0, mMediaPlayer.getAudioSessionId());
            presetReverb.setPreset(PresetReverb.PRESET_NONE);
            presetReverb.setEnabled(false);
            mMediaPlayer.setAuxEffectSendLevel(1.0f);
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    if (homeActivity.isEqualizerEnabled) {
        try {
            bassBoost.setEnabled(true);
            BassBoost.Settings bassBoostSettingTemp = bassBoost.getProperties();
            BassBoost.Settings bassBoostSetting = new BassBoost.Settings(bassBoostSettingTemp.toString());
            if (homeActivity.bassStrength == -1) {
                bassBoostSetting.strength = (1000 / 19);
            } else {
                bassBoostSetting.strength = homeActivity.bassStrength;
            }
            bassBoost.setProperties(bassBoostSetting);
            mMediaPlayer.setAuxEffectSendLevel(1.0f);


            if (homeActivity.reverbPreset == -1) {
                presetReverb.setPreset(PresetReverb.PRESET_NONE);
            } else {
                presetReverb.setPreset(homeActivity.reverbPreset);
            }
            presetReverb.setEnabled(true);
            mMediaPlayer.setAuxEffectSendLevel(1.0f);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (homeActivity.isEqualizerEnabled && homeActivity.isEqualizerReloaded) {
        try {
            homeActivity.isEqualizerEnabled = true;
            int pos = homeActivity.presetPos;
            if (pos != 0) {
                mEqualizer.usePreset((short) (pos - 1));
            } else {
                for (short i = 0; i < 5; i++) {
                    mEqualizer.setBandLevel(i, (short) homeActivity.seekbarpos[i]);
                }
            }
            if (homeActivity.bassStrength != -1 && homeActivity.reverbPreset != -1) {
                bassBoost.setEnabled(true);
                bassBoost.setStrength(homeActivity.bassStrength);
                presetReverb.setEnabled(true);
                presetReverb.setPreset(homeActivity.reverbPreset);
            }
            mMediaPlayer.setAuxEffectSendLevel(1.0f);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

where mMediaPlayer is ffmpeg...Other than that the library is working fine in regards to streaming. The only problem is that it doesn't get any effect put in. I thought this might be a coding problem so I just switched ffmpeg with Android standard media player like I mentioned above and it works. FFmpeg - bass boost and equalizer only works in the emulator and not in real phone device.

Another strange thing was that the effect initially worked at first in debug run mode and stopped working after I signed the apk. From which point on it stopped working both in the debug as well as any other run modes i.e - release also....I'm not using any pro guard rules also.

Points to note : 1. Replacing FFmpegmediaplayer with Standard Media player the effects works. 2. Effects worked before signing the apk then stopped working in all run modes 3. Using the same code above for FFMpegmediaplayer effects only work in the Emulator and not in real device. 4. Other than the effects problem, FFmpegmediaplayer is functional regarding streaming and local playback - in real phone device as well as emulator.

1 个答案:

答案 0 :(得分:0)

没关系自己找到答案。对于那些有同样问题的人,我建议手动更改库并希望它能正常工作。导致它出现问题或与正在使用的库相关的错误。