I downloaded the Vlc.DotNet project from Github and have been adding more functionalities to its Sample Forms application. Everything goes fine, except on thing: I noticed that every time I start the application and play an audio, the audio sounds like its volume is 100% (or something around that) - even after I set it to a lower value.
I tried setting the volume before playing the audio, but it didn't work. If I debug the code, I see that the volume is always set to -1.
For instance, if I execute the following lines of code, after setting the volume to 40, when I debug it, the volume is still -1:
myVlcControl.Play(new FileInfo(FileName));
myVlcControl.Audio.Volume = 40;
Change the order of the lines above also doesn't work.
The funny thing is, when the audio is already playing and I change the volume,it is successfully changed to the select value on the NumericUpDown. The code below is the event where this happens:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
myVlcControl.Audio.Volume = (int)numericUpDown1.Value;
}
I've been trying to solve this problem for two days now. Unfortunately, my coding skills are not even close the people behind this project. I have already posted this problem on their Issues page on Github, but since there are questions since November without replies, I decided to try the StackOverflow. Hopefully someone here uses Vlc.DotNet and have a solution for my problem.
That being said:
Thanks!
[EDIT on Jan 8, 2016, 11:50 AM GMT-2]
The user higankanshi on Github answered me the following:
I have found the problem. You should use LibVlc 2.2.0(or later). Vlc.DotNet is using LibVlc 2.1.5
Then, I executed some tests and came to the following conclusions:
You're right. Using the LibVlc 2.2.0 I'm able to set the Volume before playing.
Unfortunately, for some reason, setting the volume before playing the audio only works on the first time the application is opened. After stopping the audio, changing the volume, and playing it again, the volume doesn't change anymore - only changes while playing.
Here are the steps with results:
I'm doing my tests on the Vlc.DotNet.Forms.Samples - CLR 4 - .Net 4.5 project. The changes I've made to the project were:
My code is below:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
myVlcControl.Audio.Volume = (int)numericUpDown1.Value;
}
private void Play()
{
myVlcControl.Audio.Volume = (int)numericUpDown1.Value;
myVlcControl.Play(new FileInfo(FileName));
}
private void OnButtonPlayClicked(object sender, EventArgs e)
{
Play();
}
private void OnButtonStopClicked(object sender, EventArgs e)
{
myVlcControl.Stop();
}
private void OnButtonPauseClicked(object sender, EventArgs e)
{
myVlcControl.Pause();
}
Any ideas?
Advanced use of VLC ) the maximum volume value is 1024, yet actually you can put any value. The 256 corresponds to 100%, 512 to 200% and so on. Try up to 4096 and it will worked. If you put up the volume to 200%, vlc will not correctly amplify the sound but apparently cap some frequencies which leads to distortions.
I have found working solution:
int volume { get; set; }
public Constructor(){
InitializeComponent();
myVlcControl.VideoOutChanged += myVlcControl_VideoOutChanged;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
this.volume = (int)numericUpDown1.Value;
myVlcControl.Audio.Volume = volume;
}
void vlcPlayer_VideoOutChanged(object sender, VlcMediaPlayerVideoOutChangedEventArgs e)
{
myVlcControl.Audio.Volume = volume;
}
This seems to work for both file and stream.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With