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:
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());
}
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";
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());
}