Page 1 of 1

toggle or switch audio tracks

Posted: 09 Sep 2010 23:35
by anhlunnhaque
Hello,

I am a newbie in VLC and C#. But I would like to create a custom media player using C# and libVLC.net. I got this great project from here: viewtopic.php?f=32&t=58438 and after testing, debugging and trying to understands some of the code. I have a question and hope that somebody could help me.

I want to create a button click event that when I click it..I toggle or switch the audio from audio 1 to audio 2. Or from audio 2 to audio 1. Does anybody has the snippet code that I can use to play with? Ultimately, I want to set the player to play the audio stream that I specify. But at this moment. I'll just work a little at a time.

Thank you and greatly appreciated for your help...

Re: toggle or switch audio tracks

Posted: 16 Sep 2010 18:12
by XilasZ
I don't know about the wrapper libVLC.net because i use another one, but on the vlc side, you need to play with libvlc_audio_set_track, libvlc_audio_get_track and libvlc_audio_get_track_description.

You can check the source code of my program here if you want (a mediaplayer dedicated to tv from my internet provider, but it can also play any media file, and it can switch audio/video/subtitle tracks on the fly) : http://sourceforge.net/projects/fritivi/
it still use libvlc 1.0.5, i did not take the time to update to 1.1.x.

More specifically, you'll find how i deal with audio tracks here : http://fritivi.git.sourceforge.net/git/ ... d5;hb=HEAD

Re: toggle or switch audio tracks

Posted: 16 Sep 2010 21:40
by anhlunnhaque
XilasZ...thank you for the info..I'll definitely look at the source code to learn more about vlc..thanks again..

Edit: How do i get the source code for your project? I downloaded it..and it's an .exe.

Re: toggle or switch audio tracks

Posted: 17 Sep 2010 16:28
by XilasZ
you can browse the whole source code here : http://fritivi.git.sourceforge.net/git/ ... ivi;a=tree
There is also a snapshot link in the left of the header of the page, if you want a tarball.

Re: toggle or switch audio tracks

Posted: 17 Sep 2010 20:43
by mangokm40
Here's a basic function that will scroll through the audio tracks:

Code: Select all

libvlc_media_player_t* vlcPlayer; bool SetNextAudioTrack(bool previous) { int total = libvlc_audio_get_track_count(vlcPlayer); if (total == 0) return false; int current = libvlc_audio_get_track(vlcPlayer); current = previous ? current - 1 : current + 1; if (current < 0) current = total - 1; else if (current == total) current = 0; return libvlc_audio_set_track(vlcPlayer, current) == 0; }
It's in C, but I hope it helps you.