Open Yuri-Belkasoft opened 4 years ago
Interesting enough, if after VlcControl.SourceProvider.MediaPlayer.Play() I call the same:
VlcMedia media = VlcControl.SourceProvider.MediaPlayer.GetMedia(); string duration = $"{media.Duration.Hours}:{media.Duration.Minutes}:{media.Duration.Seconds}";
without Media.Parse() method, it returns me correct duration.
I was able to get correct duration using ParseAsync + ParsedChanged event. However, I think that sync event must also work or be removed.
Hello,I do a lot of time to get a duraton with:
public MainWindow()
{
InitializeComponent();
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
if (currentDirectory == null)
return;
var url = @"c:\test.ts";
myControl.SourceProvider.CreatePlayer(new DirectoryInfo(System.IO.Path.Combine(currentDirectory, "libvlc", "win-x64")));
FileStream stream = new FileStream(url, FileMode.Open, FileAccess.Read);
myControl.SourceProvider.MediaPlayer.SetMedia(stream);
VlcMedia media = myControl.SourceProvider.MediaPlayer.GetMedia();
media.ParsedChanged += Media_ParsedChanged;
}
private void BtnPlay_Click(object sender, RoutedEventArgs e)
{
myControl.SourceProvider.MediaPlayer.Play();
}
private void BtnDuration_Click(object sender, RoutedEventArgs e)
{
VlcMedia media = myControl.SourceProvider.MediaPlayer.GetMedia();
media.ParseAsync();
}
private void Media_ParsedChanged(object sender, VlcMediaParsedChangedEventArgs e)
{
VlcMedia media = myControl.SourceProvider.MediaPlayer.GetMedia();
string duration = $"{media.Duration.Hours}:{media.Duration.Minutes}:{media.Duration.Seconds}";
MessageBox.Show(duration);
}
But i still get 0:0:0 ! Hope you can reply me, Thank you :)
Why are you using a file stream instead of passing the file name directly to vlc ?
If libvlc returns wrong values, I don't think I can do something about it.
Yes, But i also want FileStream can, Because of others' limited !
Hard to change...
I have an issue about Vlc.DotNet.
Generic information
Summary
My code
fills 0:0:0 in duration.