Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Media.Duration returns zero duration #665

Open
Yuri-Belkasoft opened this issue Aug 27, 2020 · 5 comments
Open

Media.Duration returns zero duration #665

Yuri-Belkasoft opened this issue Aug 27, 2020 · 5 comments

Comments

@Yuri-Belkasoft
Copy link

I have an issue about Vlc.DotNet.

Generic information

  • Vlc.DotNet version : 3.1.0 (latest from NuGet)
  • Vlc.DotNet project used : WPF
  • libvlc version : 3.0.11 from NuGet, VideoLan.LibVLC.Windows package
  • .net version : 4.7.2
  • Project language : C#
  • Project build architecture : AnyCPU
  • Operating system : Windows 7 x64

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.

  • I can't confirm that my issue doesn't happen in VLC itself, I am not sure how to test that.
@Yuri-Belkasoft
Copy link
Author

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
Copy link
Author

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

@707763911
Copy link

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
Copy link
Collaborator

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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants