MCI

I am attempting to use MCISendString in order to aquire information about a media file.  More specifically I want to get the file length(in time) of a wma file.  I found elsewhere some information that is supposed to accomplish this, but I cannot get it to work.  Below is my code.

Using the code below, the return values of the calls to mciSendString were 0, meaning no errors, but no matter what my command string is, I mssg is ALWAYS blank.  Does anyone see anything that would be keeping mssg from returning a value????????

Thanks,
Kendal
private void FindLength(string file)
		{
			string cmd = "open " + file + " alias voice1";
			StringBuilder mssg = new StringBuilder(255);
			int h = mciSendString(cmd,null,0,0);
			int i = mciSendString("set voice1 time format ms", null, 0, 0);
			int j = mciSendString("status voice1 length", mssg, mssg.Length, 0);
			MessageBox.Show(mssg.ToString());
 
		}
 
		[DllImport("winmm.dll")]
		public static extern int mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);
 
		[DllImport ("winmm.dll")] 
		private static extern int mciGetErrorString(int l1, StringBuilder s1, int l2);

Open in new window

gvector1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PlatoConsultantCommented:
i have tried ur code,  if u replace the mssg.length with 255 code start to work ...

i have changed ur code a liitle and its working now....

private void FindLength(string file)
        {
            string cmd = "open " + file + " alias voice1";
            StringBuilder mssg = new StringBuilder(255);
            int h = mciSendString(cmd, null, 0, 0);
            int i = mciSendString("set voice1 time format ms", null, 0, 0);
            int j = mciSendString("status voice1 length", mssg, 255, 0);
 
            int seconds;
            seconds = int.Parse(mssg.ToString());
            seconds = seconds / 1000;
            MessageBox.Show( "Seconds = " + seconds.ToString());
 
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gvector1Author Commented:
Excellent.....Thanks a million.  I would have sworn that I even tried using 255, but I guess something was not right.  Also instead of 255, mssg.Capacity could be used.

Thanks again,
Kendal
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.