Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
I am trying to get sound file length, I got the length for wav file using mciSendString
but my goal is for file.wma or other. I am trying using Microsoft.WindowsAPICodePack.Shell
unfortntley i could not added a reference to Microsoft.WindowsAPICodePack.Shell
help me to find the file length in any way you know ,I am looking for several answers
thanks

What I have tried:

C#
//try1
using Microsoft.WindowsAPICodePack.Shell;
        private void FindLengthClick(object sender, EventArgs e)
        {
            double nanoseconds;
            string file = "mac1.wma";
            ShellFile so = ShellFile.FromFilePath(file);
            double.TryParse(so.Properties.System.Media.Duration.Value.ToString(),
                                out nanoseconds);
            MessageBox.Show("File length in MilliSeconds=", (nanoseconds/10000).ToString());
        }
//try 2
using System.Runtime.InteropServices;
    public partial class Form1 : Form
    {
        [DllImport("winmm.dll")]
        private static extern uint mciSendString(
            string command,
            StringBuilder returnValue,
            int returnLength,
            IntPtr winHandle);

        private void button1_Click(object sender, EventArgs e)
        {
            string fileName = "mac1.wma";//"myfile.wav";

            StringBuilder lengthBuf = new StringBuilder(32);
            mciSendString(string.Format("open \"{0}\" type waveaudio alias wave", fileName), null, 0, IntPtr.Zero);
            mciSendString("status wave length", lengthBuf, lengthBuf.Capacity, IntPtr.Zero);
            mciSendString("close wave", null, 0, IntPtr.Zero);
            int length = 0;
            int.TryParse(lengthBuf.ToString(), out length);
            MessageBox.Show("length=" + length.ToString());
        }
Posted
Updated 28-Aug-21 4:55am
v5
Comments
Engineer khalid 27-Aug-21 13:46pm    
microsoft.windowsAPiCodePack.Shell
can be doawnload from this site
https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-Shell/
i still waitting for the other part of the question(mciSendString)

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900