How can I mute the video in MFC vc++ ?

This forum is about all development around libVLC.
chamanlata
Blank Cone
Blank Cone
Posts: 17
Joined: 19 Feb 2019 06:16

How can I mute the video in MFC vc++ ?

Postby chamanlata » 14 Mar 2019 11:12

Hello,
I am working on vlclib library in MFC VC++.I want to mute the audio of video.I triedc many function but it is not working.Please help!!
I have tried all the option:
1. By Zero the volume Level
2. By mute the video
3. By disable the track

This is my code:

my_instance = libvlc_new(0, NULL);
my_media_file = libvlc_media_new_location(my_instance, "rtsp://test.mov");
my_player = libvlc_media_player_new_from_media(my_media_file);
my_event_manager = libvlc_media_player_event_manager(my_player);
libvlc_media_player_play(my_player);

libvlc_audio_set_volume(my_player ,0);
libvlc_audio_set_mute(my_player ,true);
libvlc_audio_set_track(my_player ,0);

chubinou
Developer
Developer
Posts: 521
Joined: 23 Jul 2015 15:19

Re: How can I mute the video in MFC vc++ ?

Postby chubinou » 14 Mar 2019 13:39

Hi,
mute or set should work unless you use pass through audio

from the documentation of libvlc_audio_set_mute
This function does not always work. If there are no active audio playback stream, the mute status might not be available. If digital pass-through (S/PDIF, HDMI...) is in use, muting may be unapplicable. Also some audio output plugins do not support muting at all.

chubinou
Developer
Developer
Posts: 521
Joined: 23 Jul 2015 15:19

Re: How can I mute the video in MFC vc++ ?

Postby chubinou » 14 Mar 2019 13:44

you should also be able to call libvlc_audio_set_track with the track "-1" to disable it.

chamanlata
Blank Cone
Blank Cone
Posts: 17
Joined: 19 Feb 2019 06:16

Re: How can I mute the video in MFC vc++ ?

Postby chamanlata » 15 Mar 2019 04:41

Hello,
I already tried try this but it also does not work for me.

This is my code:

my_instance = libvlc_new(0, NULL);
my_media_file = libvlc_media_new_location(my_instance, "rtsp://test.mov");
my_player = libvlc_media_player_new_from_media(my_media_file);
my_event_manager = libvlc_media_player_event_manager(my_player);
libvlc_media_player_play(my_player);
libvlc_audio_set_track(my_player ,-1);

chubinou
Developer
Developer
Posts: 521
Joined: 23 Jul 2015 15:19

Re: How can I mute the video in MFC vc++ ?

Postby chubinou » 15 Mar 2019 09:25

hum, as this is an RTSP stream, the audio tracks might available asynchronously after you made the play, can you try to issue your command after a libvlc_MediaPlayerESAdded event (you register a callback on you my_event_manager, see [1])

[1] https://www.videolan.org/developers/vlc ... 2392f62fc6

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: How can I mute the video in MFC vc++ ?

Postby mangokm40 » 15 Mar 2019 17:31

When I updated my crap to use libvlc 3.0, I couldn't find the correct event for this. In my case, I was trying to 'get_mute', instead of 'set_mute'. I tried "libvlc_MediaPlayerESAdded", without success. The call to "libvlc_audio_get_mute()" would fail when responding to that event. I couldn't find an event that assured me the player was ready to get/set mute. I'm using "libvlc_MediaPlayerVout", which (of course) doesn't work if you're playing audio files. :)

I should be more specific....
When I tried "libvlc_MediaPlayerESAdded", it worked for the first file (audio or video) that I played. Any other file that played after that, had the failure at "libvlc_audio_get_mute()" (I think it returns -1).

chubinou
Developer
Developer
Posts: 521
Joined: 23 Jul 2015 15:19

Re: How can I mute the video in MFC vc++ ?

Postby chubinou » 15 Mar 2019 17:44

@mangokm40, could you send your code?

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: How can I mute the video in MFC vc++ ?

Postby mangokm40 » 15 Mar 2019 19:18

"@mangokm40, could you send your code?"

Are you looking for code fragments, or a working sample? If the latter, I will have to work on one.

chubinou
Developer
Developer
Posts: 521
Joined: 23 Jul 2015 15:19

Re: How can I mute the video in MFC vc++ ?

Postby chubinou » 18 Mar 2019 11:22

@mangokm40, enough code to understand your problem and see what you're doing.

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: How can I mute the video in MFC vc++ ?

Postby mangokm40 » 18 Mar 2019 14:03

// create the VLC instance
vlcInstance = libvlc_new(argc, args);
...error chk...

// create a VLC media player object
vlcPlayer = libvlc_media_player_new(vlcInstance);
...error chk...

// Get event manager for the player
vlcEventManager = libvlc_media_player_event_manager(vlcPlayer);
// docs claim no error to check
...

libvlc_event_attach(vlcEventManager, libvlc_MediaPlayerEndReached, OnEvent, this);
vlcMediaList = libvlc_media_list_new(vlcInstance);
libvlc_event_attach(vlcEventManager, libvlc_MediaListItemAdded, OnEvent, this);
libvlc_event_attach(vlcEventManager, libvlc_MediaListItemDeleted, OnEvent, this);

....user selects file(s) to play....
....we add the selected file(s) to vlcMediaList....

commandThread = _beginthreadex(... // create/start the UI-command-handling thread
commandThread->Start();
eventThread = _beginthreadex(... // create/start the event-handling thread
eventThread->Start();
libvlc_event_attach(vlcEventManager...
...listen to more events...
libvlc_event_attach(vlcEventManager,
libvlc_MediaPlayerESAdded, // Listen for this event
eventHandlerFunction,
userData);

// get the current media...
libvlc_media_list_lock(vlcMediaList);
libvlc_media_t *currentMedia = libvlc_media_list_item_at_index(vlcMediaList, index); // index changes as we move through the items in the media list
libvlc_media_list_unlock(vlcMediaList);
...

// set the media to be played and start
libvlc_media_player_set_media(vlcPlayer, currentMedia);
libvlc_media_release(currentMedia);
libvlc_media_player_play(vlcPlayer);

/// When the event "libvlc_MediaPlayerESAdded" is fired, we communicate with the event-handler thread
/// through a synchronized-queue. Our event-handling thread then makes a call to
int rc = libvlc_audio_get_mute(vlcPlayer);
/// this call succeeds

....user hits 'stop' button....
/// We sent the request to stop to the command-handler thread through a synch-queue.
/// Our command-handler thread makes a call to
libvlc_media_player_stop( (libvlc_media_player_t*)vlcPlayer );

....user selects file(s) to play....
....we add the selected file(s) to vlcMediaList....

commandThread = _beginthreadex(... // create/start the UI-command-handling thread
commandThread->Start();
eventThread = _beginthreadex(... // create/start the event-handling thread
eventThread->Start();
// start listening to vlc events
libvlc_event_attach(vlcEventManager...
...listen to more events...
libvlc_event_attach(vlcEventManager,
libvlc_MediaPlayerESAdded, // Listen for this event
eventHandlerFunction,
userData);

// get the current media...
libvlc_media_list_lock(vlcMediaList);
libvlc_media_t *currentMedia = libvlc_media_list_item_at_index(vlcMediaList, index); // index changes as we move through the items in the media list
libvlc_media_list_unlock(vlcMediaList);
...

// set the media to be played and start
libvlc_media_player_set_media(vlcPlayer, currentMedia);
libvlc_media_release(currentMedia);
libvlc_media_player_play(vlcPlayer);

/// When the event "libvlc_MediaPlayerESAdded" is fired, we communicate with the event-handler thread
/// through a synchronized-queue. Our event-handling thread then makes a call to
int rc = libvlc_audio_get_mute(vlcPlayer);
// This time, call fails. rc == -1

chubinou
Developer
Developer
Posts: 521
Joined: 23 Jul 2015 15:19

Re: How can I mute the video in MFC vc++ ?

Postby chubinou » 19 Mar 2019 10:16

libvlc_audio_get_mute will return -1 if there is no audio output.

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: How can I mute the video in MFC vc++ ?

Postby mangokm40 » 19 Mar 2019 12:50

libvlc_audio_get_mute will return -1 if there is no audio output.
My point was merely to reply to this answer to the OP:
"... can you try to issue your command after a libvlc_MediaPlayerESAdded event"

I wanted to let him/her know that I have tried using that event.
In my case, I create the libvlc instance once. After files are chosen for play, I attach to these events. When the files finish playing, I detach from these events. Any time after that, when files are chosen to play again (and I attach to these events), the audio output is not yet ready when libvlc_MediaPlayerESAdded fires.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 27 guests