Getting length of video

后端 未结 7 2003
忘掉有多难
忘掉有多难 2020-12-01 12:36

I am having trouble finding a simple example of how to get the video length of a file programmatically. Many people say, oh use this library/wrapper or whatever, but do not

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 13:25

    I have tried to get the video length in a bit different way :
    Actually using Windows Media Player Component also, we can get the duration of the video.
    Following code snippet may help you guys :

    using WMPLib;
    // ...
    var player = new WindowsMediaPlayer();
    var clip = player.newMedia(filePath);
    Console.WriteLine(TimeSpan.FromSeconds(clip.duration));
    

    and don't forget to add the reference of wmp.dll which will be present in System32 folder.

提交回复
热议问题