473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to play a MIDI file in C# ?

I wrote following code:

using System.Runtime.InteropServices;
[DllImport("winmm.dll")]
public static extern int mciSendString(string lpstrCommand, string
lpstrReturnString,int uReturnLength,
int dwCallback);
[DllImport("winmm.dll")]
public static extern int mciGetErrorString(int errCode,string errMsg,uint
buflen);

private void btnPlay_Click(object sender, System.EventArgs e)
{
int r1,r2;
string s1,s2;
string Playingfile;
s1="";
s2="";

Playingfile=listBox1.SelectedItem.ToString();
r1=mciSendString("OPEN "+Playingfile+" TYPE Sequencer wait","",0,0);
r2=mciSendString("PLAY "+Playingfile,"",0,0);
mciGetErrorString(r1,s1,128);
mciGetErrorString(r2,s2,128);
MessageBox.Show("s1="+s1 +" s2="+s2+" r1="+r1.ToString()+"
r2="+r2.ToString());
}

The MessageBox shows s1 s2 are empty string, while r1=0 and r2=337.
I don't know what the return value 337 mean.
I just want to play a MIDI file in C#. any better way?
Waiting for reply. Thanks.
Nov 15 '05 #1
0 4463

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Elaine Jackson | last post by:
(How) can you make it so that a function invoked in the python interpreter can run another program? (Like the webbrowser module does, only not with a web browser.) If it matters the OS is Windows98...
2
by: cody | last post by:
Does anybody know how to play MIDI files? I do not want to use P/Invoke or DirectX. Maybe there is a free 3rd party Library but I do not know any supporting MIDI music. I tried the library "Bass"...
11
by: Kuba Araszkiewicz | last post by:
Hello! I have to write a program, which would convert midi files to notes, notes to midi files and which would make one MIDI file from two different. I'm totally lame in C (and any other...
2
by: david | last post by:
1.I am considering doing a midi file generator for my 4th year project in B.SC. 2.I would do it using c language, but i'm not sure abou t the level of difficulyt involved 3.Basically, the...
1
by: Lam | last post by:
how can I play sound file in a .aspx page written in C#? I try to use the code like the following. But whenI call the play function play("sound.wav", this.SND_ASYNC) my computer give out "be"...
1
by: tim | last post by:
Someone using Python Midi Package from http://www.mxm.dk/products/public/ lately? I want to do the following : write some note events in a midi file then after doing that, put some controllers...
20
by: Stephen Kellett | last post by:
Hi Folks, How can I play midi and/or audio files using JavaScript? I'm hoping there are some calls/APIs I can use that I am unaware of. My JavaScript book from O'Reilly seems rather lacking in...
13
by: anil.rita | last post by:
When the user chooses an AV file to play, based upon the type of file, I want to use the default installed media player to play it. I am wondering if this is a good way - any alternatives,...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.