Volume Channels

折月煮酒 提交于 2019-12-24 03:03:42

问题


Such Problem: I have video file recorded with two sound channels. I tried to switch off left sound channel by this code:

MediaPlayer mp; 

....

mp.setVolume(0.f, 1f);

... and on Tablet this work good (right volume channel sounds well). But then I tried it on googleTv which I connect to Samsung UE46ES6307U and this code did not work, sound swichs off. Maybe it is bounds to Dolby Digital Plus / Dolby Pulse audio? Can I somehow programmatically discover how sound channels device has, and what volume in each chanels setuped?

Update: On this forum http://www.googletvforum.org/forum/logitech-revue/375-audio-problems-logitech-revue.html in one of replies such message: "Logitech has not yet figured out how to pipe multichannel audio thru hdmi.you have to use the optical output. Which is ok."

"How are you constructing the MediaPlayer?"

Videoview vv;
...............

        vv.setOnPreparedListener(new OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setVolume(0.f, 1f);
            }
        });

Update:

public class MainActivity extends Activity {
    MediaPlayer mp = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (mp != null) {
            mp.reset();
            mp.release();
        }

        mp = MediaPlayer.create(this, R.raw.test);
        mp.start();

    }

    public void onTurnOffLeft(View v){
        mp.setVolume(0.f, 1.f);
    }

    public void onTurnOffRight(View v){
        mp.setVolume(1.f, 0.f);
    }
}

Method onTurnOffLeft switchs off all sound, and onTurnOffRight method has no effect.

Update2

I tried to play .ogg audio file codded with Vorbis codec - channels turns off well. But I tried to play video files codded with mp3, ac3, pcm, aac - and problem with turning off channels is still there... I need to turn off audio channels in video, but how to solve that problem, I do not know yet.


回答1:


The MediaPlayer object is backed by different libraries across the devices (not the same between a tablet and a Google TV). How are you constructing the MediaPlayer?

One thing you may want to try is calling #reset() on the MediaPlayer right after it is constructed. By default when you use a "new" operator to construct a MediaPlayer instance it is in an IDLE state (at least on Google TV). By calling reset you allow your own OnErrorListener.onError() handler to be invoked. This will let you see if there is some underlying error that is not visible otherwise.

You may also want to look at AudioManager#setStreamVolume(int, int, int) which sets the volume of ALL streams of a particular type.

Edit 1: Since you are just grabbing the VideoView from layout (I'm guessing since that code was omitted) after you setup the listener you should call reset on the video view.



来源:https://stackoverflow.com/questions/13684352/volume-channels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!