Adjust Dash stream volume with Android Exoplayer

放肆的年华 提交于 2019-12-12 12:27:45

问题


I'm trying to set up a seekbar to control the level of an instance of exoplayer streaming dash.

The setup I am using is a modified version of the demo project and am having trouble figuring out which element I should be trying to affect with the seekbars output ie how to use MSG_SET_VOLUME properly etc etc Any input would be massively appreciated.

The end result I am looking for is an application with two instances of exoplayer both streaming dash content with a fader(seekbar) controlling the mix of the two players (which once this is figured out i presume should be easy enough if the maths is correct) Again any help would be massively appreciated I have had a bit of a time with Exoplayer so far being such a novice! thanks guys!


回答1:


If I read the ExoPlayer source code correctly you have to keep references to the audioRenderers you use when preparing the ExoPlayer instance.

exoPlayer.prepare(audioRenderer);

To change volume you have to send the following message:

exoPlayer.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME, 0.1f);

First you pass the audioRenderer for which you want to change the volume. Secondly you define the message which you want to send to the renderer which is MSG_SET_VOLUME, since you want to affect audio. Finally you pass the value you want to set the volume to. In this example I chose 0.1f but of course you can use any value which fits your needs.

You can effect two different playback volumes if you send messages to both MediaCodecAudioTrackRenderers which you used to prepare playback. So you could send two messages with for example value 0.4f for audioRenderer1 and 0.6f for audioRenderer2 to blend the playbacks into one another.

I did not try this myself, but I think it should work.

This is the snippet of the original ExoPlayer code which is responsible for handling the MSG_SET_VOLUME message:

public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
    if (messageType == MSG_SET_VOLUME) {
        audioTrack.setVolume((Float) message);
    } else {
        super.handleMessage(messageType, message);
    }
}


来源:https://stackoverflow.com/questions/31517573/adjust-dash-stream-volume-with-android-exoplayer

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