Crossfade & Volume normalization
Hi,
i have two questions about how the volume level can be controlled and how the playback volume could be normalized.
I tried to code a very basic crossfade function that should fadeout one player, while fading in the other. Furthermore i added options that should enable the normvol audio filter. This is my code:
var mp, mp2, libVLC, libVLC2;
public Main()
{
List<string> options = new List<string>();
options.Add("--verbose=2");
options.Add("--audio-filter=normvol");
options.Add("--norm-buff-size=20");
options.Add("--norm-max-level=0,1");
libVLC = new LibVLC(enableDebugLogs: true, options.ToArray());
libVLC2 = new LibVLC(enableDebugLogs: true, options.ToArray());
mp = new MediaPlayer(libVLC);
mp2 = new MediaPlayer(libVLC2);
mp.Media = GetMedia(GetNextFile());
mp.Play();
NextCrossFade();
}
public Task CrossfadeAsync(MediaPlayer mpin, MediaPlayer mpout)
{
return Task.Run(() =>
{
int volout = mpout.Volume;
int volin = 0;
mpin.Volume = 0;
while (volout > -1 || volin < 51)
{
Thread.Sleep(1000);
if (volout > -1)
{
mpout.Volume = volout;
volout--;
}
if (volin < 51 && mpin.IsPlaying)
{
mpin.Volume = volin;
volin++;
}
}
});
}
private async void NextCrossFade()
{
if (mp != null && mp.IsPlaying && mp2 != null && !mp2.IsPlaying)
{
mp2.Media = GetMedia(GetNextFile());
mp2.Play();
await CrossfadeAsync(mp2, mp);
mp.Stop();
}
else if (mp2 != null && mp2.IsPlaying && mp != null && !mp.IsPlaying)
{
mp.Media = GetMedia(GetNextFile());
mp.Play();
await CrossfadeAsync(mp, mp2);
mp2.Stop();
}
}
private string GetCurrentFile()
{
return (path of next file);
}
private Media GetMedia(string path)
{
return new Media(libVLC, new Uri(path));
}
During the crossfade i get weird volume stuttering. Checking the volume from the volumechanged event revealed, that changing the volume of one MediaPlayer also affect the volume of every other MediaPlayer. Is there an option to prevent this behavior? So far i only tried to create the MediaPlayer from different instances of LibVLC.
Furthermore the "audio-filter=normvol" option doesn't work. I also tried it to set this to the media directly with .AddOption(":audio-filter=normvol"); but this didn't work.
My question now is if both issues are solvable with the VLC Lib?
Thank you for your time :)