ZeBobo5 / Vlc.DotNet

.NET control that hosts the audio/video capabilities of the VLC libraries
MIT License
947 stars 416 forks source link

Media.Duration returns zero duration #665

Open Yuri-Belkasoft opened 4 years ago

Yuri-Belkasoft commented 4 years ago

I have an issue about Vlc.DotNet.

Generic information

Summary

My code

    VlcControl.SourceProvider.CreatePlayer(new DirectoryInfo(my directory here);
    FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    VlcControl.SourceProvider.MediaPlayer.SetMedia(stream);
    VlcMedia media = VlcControl.SourceProvider.MediaPlayer.GetMedia();
    media.Parse();
    string duration = $"{media.Duration.Hours}:{media.Duration.Minutes}:{media.Duration.Seconds}";

fills 0:0:0 in duration.

Yuri-Belkasoft commented 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.

Yuri-Belkasoft commented 4 years ago

I was able to get correct duration using ParseAsync + ParsedChanged event. However, I think that sync event must also work or be removed.

707763911 commented 3 years ago

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 :)

jeremyVignelles commented 3 years ago

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.

707763911 commented 3 years ago

Yes, But i also want FileStream can, Because of others' limited !
Hard to change...