How to get volume of AudioTrack in Android? -


i can set volume of audiotrack using track.setstereovolume(a,b);

but couldn't find method to volume, either getstereovolume() or setonvolumechangedhandler(...)

how can track volume level?

you can't left , right volume levels of audio track.

so propose create class representing audiotrack.

public class audioplayer{     audiotrack track;     float leftvolume;     float rightvolume;     public audioplayer(){         //create audio track.         leftvolume = 1;         rightvolume = 1;     }     public void setstereovolume(float left, float right){         this.leftvolume = left;         this.rightvolume = right;         track.setstereovolume(left, right);     } } 

when you're creating audiotrack stereo volume @ 1.0 both channels. when volume set through audioplayer tracks new level.

this work, provided audiotrack encapsulated within audioplayer.

edit:

an audiotrack has own volume level independent of other tracks. stream audiotrackis playing on (stream_music, stream_system etc.) influence final volume level.

so, audiotrack @ .5,.5 left , right channels, , playing on stream_music. if stream @ .5 volume, final audio level

.5*.5 = .25 //for left , right channels. 

if automatic volume adjustment happens due power savings or headphones- whatever, should happen on stream level (or somewhere hidden beyond that.) still, shouldn't adjust audiotrack volume.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -