Page 1 of 1

Volume handling in 2.1.0 onwards

Posted: 19 Sep 2012 19:39
by sherington
Hello,

With vlc 2.0.x, when you invoke libvlc_audio_get_volume it will seemingly return a valid value whether an audio output is playing or not.

With vlc 2.1.x, when you invoke libvlc_audio_get_volume it will return -1 (error) until after the audio output has started, which will be some short time after the asynchronous libvlc_media_player_play function is invoked.

So I am wondering what is the right way to handle querying the volume via libvlc_audio_get_volume now? I can't invoke it immediately after invoking play (it's too soon), and I shouldn't do a short sleep() before invoking it, so I think I should wait until I receive a (new) event telling me the audio output has been created (much like the existing event for video output created).

The same applies to setting the volume - so even if instead I manage my own volume setting rather than querying libvlc, I still need to know the right moment (after the audio output is created) to invoke libvlc_audio_set_volume.

Such an event does not exist yet, if this is the right thing to do I am happy to try and contribute a patch for it.

Is this correct or am I missing something?

Re: Volume handling in 2.1.0 onwards

Posted: 19 Sep 2012 22:48
by Rémi Denis-Courmont
Internally, there is an event to report the volume status, but there is indeed no code to pass it to the application.

There should already be an "aout" event though.

Re: Volume handling in 2.1.0 onwards

Posted: 20 Sep 2012 08:32
by sherington
Internally, there is an event to report the volume status, but there is indeed no code to pass it to the application.
I have seen aout_VolumeReport(), which sets the "volume" variable on the aout - is this what you are referring to here? First I was thinking to add a variable callback to listen for changes to this variable, but of course the aout does not exist yet so I need to do something else.
There should already be an "aout" event though.
Are you referring to input-events? I was thinking to translate INPUT_EVENT_AOUT to a new Libvlc_MediaPlayerAout event, in the same way as is currently done for INPUT_EVENT_VOUT. Existing code from lib/media_player.c:

Code: Select all

else if( newval.i_int == INPUT_EVENT_VOUT ) { [Some code was removed from here to keep it short] event.type = libvlc_MediaPlayerVout; event.u.media_player_vout.new_count = i_vout; libvlc_event_send( p_mi->p_event_manager, &event ); }
This part of it would be quite simple to implement in a patch, but...

I suppose it would be more useful (especially if external processes can change the volume?) if there was also a Libvlc_VolumeChanged event? And it would fire *any* time the volume changed, not just when the aout was created?

Re: Volume handling in 2.1.0 onwards

Posted: 26 Sep 2013 15:32
by bunjee
Greetings guys :-D.

I've just updated to the 2.1.0 Sdk. The new volume rocks, congrats to the team.

I too have issue setting the volume before playback.

libvlc_audio_set_volume returns -1 until some point after playback started.

I haven't found the event to get notified when volume is ready to be set.

Sherington, have you found a workaround for this ?

Thanks.

Re: Volume handling in 2.1.0 onwards

Posted: 26 Sep 2013 16:31
by sherington
Sherington, have you found a workaround for this ?
No.

Re: Volume handling in 2.1.0 onwards

Posted: 27 Sep 2013 01:22
by Jean-Baptiste Kempf
Depends on the aout.

Re: Volume handling in 2.1.0 onwards

Posted: 27 Sep 2013 08:13
by sherington
Depends on the aout.
From what I have seen, there is simply no way through libvlc to successfully set/get the volume for a media player before an aout has been created (which is some indterminant time after you play the media). It will always return an error (this is clear from the libvlc media player code actually).

So a reasonable approach would be to wait for a notification that an aout has been created, then get/set the volume - similar to the existing "vout has been created" event. The problem with that is there is no such event exposed at the moment.

I wrote a small libvlc patch to expose that event and it seems to work. Whether it's generally useful or not, or whether this is a "wrong" approach for this issue or not, I don't know.

Related to that is that there is no way at the moment to be notified that the volume has changed (by some other means). As was stated earlier in this thread internally a volume change notification *is* made, but exposing that through libvlc seems trickier to me and I have made no progress in that particular regard.

Re: Volume handling in 2.1.0 onwards

Posted: 27 Sep 2013 12:23
by bunjee
On my side I previously reimplemented my video renderer.

The workaround I found is to initialize the volume right after the first frame unlock callback. Yes that's dirty :-).

I understand libVLC now supports multiple audio devices and that's great !

From my perspective there should be a way to set a "master volume" at any moment.

I'm curious how VLC player actually handles that for its volume slider.

Re: Volume handling in 2.1.0 onwards

Posted: 27 Sep 2013 14:24
by mangokm40
Thanks Sherington. This thread saved me a lot of time when I was trying to upgrade my code yesterday. :)

Thanks for the idea Bunjee. The frame unlock callback is better than a Win32 timer (what I did yesterday). :)

Re: Volume handling in 2.1.0 onwards

Posted: 27 Sep 2013 17:03
by Rémi Denis-Courmont
VLC uses basically the same underlying code path as LibVLC.

Re: Volume handling in 2.1.0 onwards

Posted: 25 Nov 2013 20:59
by bunjee
From what I have seen, there is simply no way through libvlc to successfully set/get the volume for a media player before an aout has been created (which is some indterminant time after you play the media). It will always return an error (this is clear from the libvlc media player code actually).
This is still true on 2.1.1.

Anyone made progress on this ?

Re: Volume handling in 2.1.0 onwards

Posted: 25 Nov 2013 22:17
by Rémi Denis-Courmont
The media player needs to create the audio output earlier, just like the playlist does. It should not be very hard to fix.

Re: Volume handling in 2.1.0 onwards

Posted: 26 Nov 2013 09:48
by bunjee
You're talking about changes to be made on libVLC side ?

If that's the case we should open a ticket on Trac ♥.

Re: Volume handling in 2.1.0 onwards

Posted: 12 Feb 2014 03:32
by itzalive
Has anyone got a good solution to this yet?

I'm trying to start videos muted but not being able to set audio properties before the video is playing is causing problems.

Re: Volume handling in 2.1.0 onwards

Posted: 12 Feb 2014 17:57
by Rémi Denis-Courmont
No patch to be seen so far.

Re: Volume handling in 2.1.0 onwards

Posted: 24 Jan 2015 16:12
by sherington
I've been looking at this again with 2.2.0-git.

What I observe happening now (Linux, using Pulse Audio, I can't speak for other platforms) is that it *is* now possible to get/set the volume on a media player *before* playback begins.

But if you invoke libvlc_media_player_stop, then from that point onwards libvlc_audio_get_volume will return -1 and libvlc_audio_set_volume will no effect until you invoke libvlc_media_player_play - at which point the volume will be whatever was set before you stopped.

So in short you can't stop the media, change the volume, play the media and have the desired volume be applied, it will be whatever it was prior to stop.

I don't know if it's a problem, or if it's by design, but that's what it does at the moment.

Re: Volume handling in 2.1.0 onwards

Posted: 25 Jan 2015 00:56
by Rémi Denis-Courmont
I think it affects all platforms but I have not tested, but this misfeature is really specific to stop. Maybe only the video should be terminated at stop, not the audio [output].

Re: Volume handling in 2.1.0 onwards

Posted: 15 Jun 2015 09:58
by Der_Knob
I found a solution in the nVLC comments:

http://www.codeproject.com/Articles/109 ... x4967240xx

Option b is working for me.
You may need to adapt it to your programming language...