The p/invoke has one error that I can see. The return value should be of type int
or uint
since MCIERROR
is a 32 bit integer. In C# long
is 64 bits wide.
Beyond that, the way you are calling mciSendString
is fine. In fact, your code plays an mp3 file just fine when I run it, even with the erroneous return type declaration.
So, why does it fail for you? The most obvious reason is that the multimedia functions rely on the presence of a message loop. Perhaps the thread which calls this code does not service a message queue. Are you making the call from a console application for instance?
If the thread does have a message queue, and pumps it properly, then I'm not sure what else to suggest. The next step would be to perform some error checking which you do not do at the moment. Take note of the values returned by mciSendString
and see if they indicate errors.
You've now discovered that mciSendString
is returning error code MCIERR_INTERNAL
. To me that sounds like your problem is environmental. Your code works perfectly well for me so it seems that there is a problem with your audio setup/drivers or a problem with the .mp3 file. But there's nothing more that we can do to help you with your code since the problem is not in your code.