Page 1 of 1

Does libvlc_audio_output_device_set work?

Posted: 01 Mar 2012 22:43
by kevintcore
I am trying to use the libvlc api in Windows7 to specify the audio device to output to.

This command works from the command line
C:\Temp>"C:\Program Files (x86)\VideoLAn\vlc\vlc" --waveout-audio-device="Speakers (High Definition Audio ($1,$ffff)" poker_music.mp3

I can get it to work in the UI too. But I can not get libvlc_audio_output_device_set() to work. It always plays to the default sound device regardless of what I do.

I am using the library from the ftp site, version 2.0.0 (http://download.videolan.org/pub/videol ... 0.0/win32/) checked out yesterday and dated 2/17/2012.

Using the libvlc api to iterate through the audio output devices, this is what I see
Number of audio devices = 3
id, longname
1. wavemapper, Microsoft Soundmapper
2. Speakers (USB Audio Device) ($ffff,$ffff), Speakers (USB Audio Device) ($ffff,$ffff)
3. Speakers (High Definition Audio ($1,$ffff),Speakers (High Definition Audio ($1,$ffff)


This is the code that I am using where libvlc_audio_output_device_set() does not work. Can someone tell me what I am doing wrong?
Notice in the commented out code that I have tried switching the output in the vlc instance constructor and with libvlc_media_add_option. Nothing works.

int _tmain(int argc, _TCHAR* argv[])
{
libvlc_instance_t *vlcInstance;
libvlc_media_player_t *vlcMediaPlayer;
libvlc_media_t *vlcMedia;

vlcInstance = libvlc_new (0, NULL);

//const char * const vlc_args[] = {"--waveout-audio-device=\"Speakers (High Definition Audio ($1,$ffff)\""};
//const char * const vlc_args[] = {"--aout=waveout --waveout-audio-device=\"Speakers (High Definition Audio ($1,$ffff)\""};
//vlcInstance = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);

vlcMediaPlayer = libvlc_media_player_new(vlcInstance);

int numAudioDevices = libvlc_audio_output_device_count(vlcInstance, "waveout");
printf ("Number of audio devices = %d\n", numAudioDevices);
for(int i = 0; i < numAudioDevices; i++)
{
printf ("%s\n", libvlc_audio_output_device_id(vlcInstance, "waveout", i));
printf ("%s\n", libvlc_audio_output_device_longname(vlcInstance, "waveout", i));
printf ("\n");
}

libvlc_audio_output_set(vlcMediaPlayer, "waveout");
libvlc_audio_output_device_set(vlcMediaPlayer, "Speakers (High Definition Audio ($1,$ffff)", "Speakers (High Definition Audio ($1,$ffff)");

vlcMedia = libvlc_media_new_path(vlcInstance, "C:\\Temp\\poker_music.mp3");
// libvlc_media_add_option(vlcMedia, "--waveout-audio-device=\"Speakers (High Definition Audio ($1,$ffff)\"");
// libvlc_media_add_option(vlcMedia, "--aout=waveout --waveout-audio-device=\"Speakers (High Definition Audio ($1,$ffff)\"");
libvlc_media_player_set_media (vlcMediaPlayer, vlcMedia);
libvlc_media_release(vlcMedia);

libvlc_media_player_play(vlcMediaPlayer);

libvlc_state_t vlcMediaPlayerState;
do
{
vlcMediaPlayerState = libvlc_media_player_get_state(vlcMediaPlayer);
} while (vlcMediaPlayerState != libvlc_Ended);


libvlc_media_player_stop(vlcMediaPlayer);

libvlc_media_player_release(vlcMediaPlayer);
libvlc_release(vlcInstance);

return 0;
}

What am I missing?
Or is libvlc_audio_output_device_set() broken? If so, is there a work around?

Re: Does libvlc_audio_output_device_set work?

Posted: 01 Mar 2012 22:59
by kevintcore
Since I have more than one version of vlc on my machine, I tried the following.
const char * const vlc_args[] = {"--ignore-config",
"--plugin-path=C:\\MyPath\\VideoLAN\\VLC\\2.0.0\\vlc\\plugins",};
vlcInstance = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);

and made sure the 2.0.0 dlls are the ones in my path.

It still plays to the default device.

Re: Does libvlc_audio_output_device_set work?

Posted: 02 Mar 2012 09:35
by Rémi Denis-Courmont
I have not looked at it much but I suspect the audio output device API never really worked.

Re: Does libvlc_audio_output_device_set work?

Posted: 02 Mar 2012 14:38
by kevintcore
Are there any work arounds?

I need the ability to play audio in a service in a non-interactive (logged out) session and switch the audio output device on the fly.

Re: Does libvlc_audio_output_device_set work?

Posted: 02 Mar 2012 17:22
by Rémi Denis-Courmont
Well, fix the code, sure.

Re: Does libvlc_audio_output_device_set work?

Posted: 02 Mar 2012 21:39
by kevintcore
Got it! Since there are other posts about this and none of them were really resolved, here is what I did to get things to work.

1) I set the second parameter to libvlc_audio_output_device_set() should be "waveout" and not the audio device name. I think I saw others make that mistake. VLC code appends this with "-audio-device" to create a config var name.
2) Set the output device after the media has been set in the media player. If you set it before, you will get the windows default audio device. Setting the media in the media player seems to set the output device back to the default.
3) Use the vlc methods to discover the names of the audio devices. Don't use the windows native waveOutGetDevCaps(); it can return a truncated name that will not work as a parameter to libvlc_audio_output_device_set() (even though VLC code makes use of waveOutGetDevCaps() in places).
4) I believe this is working in 2.0.0 not 1.x. Even though I had changed my path to pick up the new dlls, I was running in debug and had not closed and reopened Visual Studio so I was using the old path. I got this working shortly after closing and reopening Studio (but the previous fixes were still necessary).

Here's a look at the code,

int _tmain(int argc, _TCHAR* argv[])
{
libvlc_instance_t *vlcInstance;
libvlc_media_player_t *vlcMediaPlayer;
libvlc_media_t *vlcMedia;

//vlcInstance = libvlc_new (0, NULL);

const char * const vlc_args[] = {"--ignore-config"
,"--plugin-path=C:\\MyPath\\VideoLAN\\VLC\\2.0.0\\vlc\\plugins"
,"-vvv" // verbose log messages
};
vlcInstance = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);

vlcMediaPlayer = libvlc_media_player_new(vlcInstance);

// Use this block of code to discover the names of your audio devices
int numAudioDevices = libvlc_audio_output_device_count(vlcInstance, "waveout");
printf ("Number of audio devices = %d\n", numAudioDevices);
for(int i = 0; i < numAudioDevices; i++)
{
printf ("%s\n", libvlc_audio_output_device_id(vlcInstance, "waveout", i));
printf ("%s\n", libvlc_audio_output_device_longname(vlcInstance, "waveout", i));
printf ("\n");
}

vlcMedia = libvlc_media_new_path(vlcInstance, "C:\\Temp\\poker_music.mp3");
libvlc_media_player_set_media (vlcMediaPlayer, vlcMedia);
libvlc_media_release(vlcMedia);

libvlc_audio_output_set(vlcMediaPlayer, "waveout");

libvlc_audio_output_device_set(vlcMediaPlayer, "waveout", "Speakers (High Definition Audio ($1,$ffff)");
// libvlc_audio_output_device_set(vlcMediaPlayer, "waveout", "Speakers (USB Audio Device)");

libvlc_media_player_play(vlcMediaPlayer);

libvlc_state_t vlcMediaPlayerState;
do
{
vlcMediaPlayerState = libvlc_media_player_get_state(vlcMediaPlayer);
} while (vlcMediaPlayerState != libvlc_Ended);

libvlc_media_player_stop(vlcMediaPlayer);

libvlc_media_player_release(vlcMediaPlayer);
libvlc_release(vlcInstance);

return 0;
}

Re: Does libvlc_audio_output_device_set work?

Posted: 03 Mar 2012 07:13
by Rémi Denis-Courmont
The fact that you cannot set the device before playback is probably a bug in the WaveOut plugin or in VLC.

Re: Does libvlc_audio_output_device_set work?

Posted: 04 Oct 2016 21:35
by mc007
awesome, you saved my ass! was wasting so much time on trying til I found this post.

Will integrate this in my libvlc wrapper for nodejs.

thanks a lot!

Re: Does libvlc_audio_output_device_set work?

Posted: 07 Oct 2016 23:15
by Jean-Baptiste Kempf
awesome, you saved my ass! was wasting so much time on trying til I found this post.

Will integrate this in my libvlc wrapper for nodejs.
Which wrapper is it?