Does libvlc_audio_output_device_set work?

This forum is about all development around libVLC.
kevintcore
Blank Cone
Blank Cone
Posts: 16
Joined: 28 Jul 2011 21:28

Does libvlc_audio_output_device_set work?

Postby kevintcore » 01 Mar 2012 22:43

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?

kevintcore
Blank Cone
Blank Cone
Posts: 16
Joined: 28 Jul 2011 21:28

Re: Does libvlc_audio_output_device_set work?

Postby kevintcore » 01 Mar 2012 22:59

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.

Rémi Denis-Courmont
Developer
Developer
Posts: 15268
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Does libvlc_audio_output_device_set work?

Postby Rémi Denis-Courmont » 02 Mar 2012 09:35

I have not looked at it much but I suspect the audio output device API never really worked.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

kevintcore
Blank Cone
Blank Cone
Posts: 16
Joined: 28 Jul 2011 21:28

Re: Does libvlc_audio_output_device_set work?

Postby kevintcore » 02 Mar 2012 14:38

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.

Rémi Denis-Courmont
Developer
Developer
Posts: 15268
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Does libvlc_audio_output_device_set work?

Postby Rémi Denis-Courmont » 02 Mar 2012 17:22

Well, fix the code, sure.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

kevintcore
Blank Cone
Blank Cone
Posts: 16
Joined: 28 Jul 2011 21:28

Re: Does libvlc_audio_output_device_set work?

Postby kevintcore » 02 Mar 2012 21:39

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;
}

Rémi Denis-Courmont
Developer
Developer
Posts: 15268
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Does libvlc_audio_output_device_set work?

Postby Rémi Denis-Courmont » 03 Mar 2012 07:13

The fact that you cannot set the device before playback is probably a bug in the WaveOut plugin or in VLC.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

mc007
New Cone
New Cone
Posts: 3
Joined: 13 Sep 2016 09:27

Re: Does libvlc_audio_output_device_set work?

Postby mc007 » 04 Oct 2016 21:35

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!

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Does libvlc_audio_output_device_set work?

Postby Jean-Baptiste Kempf » 07 Oct 2016 23:15

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?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 8 guests