Hey everyone,
I'm working on a simple application and I want to use a midi file as background music. I want to be able to embed the file as a resource as to make it "portable", meaning, only having a single executable.
I did a lengthy search on Google and on here but nothing really answers my question, so I thought I'd post.
I've tried embedding the resource and using the SoundPlayer (which some sites claim will play midi files) but it just makes a "ding" sound and won't play the file.
I've used the WindowsMediaPlayer COM interface by referencing WMP.dll, but it seems you have to provide a URL to an actual location, you can't seem to specify a stream?
People had posted workaround like saving the midi file to a local location and then deleting it after, but that seems really clunky and undesirable (in the event of a crash, it would leave my midi file on their computer in some random spot).
Does anyone know if there's a good way to do this? It seems really strange not to be able to feed a file stream into WMP via an embedded resource?
(BTW - WMP DOES play midis, I was able to run it just fine from a local file URL, just not from a stream)
If I missed a post that addresses this, I apologize... I know there are a couple out there but none that sufficiently answer the question.
Thanks!
Play Midi as an embedded resource?
Page 1 of 16 Replies - 989 Views - Last Post: 08 April 2011 - 03:09 PM
Replies To: Play Midi as an embedded resource?
#2
Re: Play Midi as an embedded resource?
Posted 08 April 2011 - 09:38 AM
Why not save it as a byte array in the project's resource? Make a 'string' resource. Give it a name.. then convert your midi to a byte array. Save that byte array in your string resource. When you need it convert the byte array to a memory stream, and then plug it into this "SoundPlayer Constructor", then just <SoundPlayer object>.play();!
http://msdn.microsof...y/ms143770.aspx
http://msdn.microsof...y/ms143770.aspx
#3
Re: Play Midi as an embedded resource?
Posted 08 April 2011 - 09:48 AM
modi123_1, on 08 April 2011 - 10:38 AM, said:
Why not save it as a byte array in the project's resource? Make a 'string' resource. Give it a name.. then convert your midi to a byte array. Save that byte array in your string resource. When you need it convert the byte array to a memory stream, and then plug it into this "SoundPlayer Constructor", then just <SoundPlayer object>.play();!
http://msdn.microsof...y/ms143770.aspx
http://msdn.microsof...y/ms143770.aspx
That's an interesting idea... I actually had an example of using the file as as a Stream from an embedded resource, but SoundPlayer wouldn't play it... it just made a "ding" sound and acted like it wasn't able to play it?
Do you know if SoundPlayer can actually play Midi files? Some people online had said they thought so but noone seemed to actually have done it hehe
#4
Re: Play Midi as an embedded resource?
Posted 08 April 2011 - 09:55 AM
Ah crap.. no.
http://msdn.microsof...oundplayer.aspx
So.. why not convert the mdi to a wav?
Quote
The SoundPlayer class provides a simple interface for loading and playing a .wav file
http://msdn.microsof...oundplayer.aspx
So.. why not convert the mdi to a wav?
#5
Re: Play Midi as an embedded resource?
Posted 08 April 2011 - 12:01 PM
modi123_1, on 08 April 2011 - 10:55 AM, said:
Ah crap.. no.
http://msdn.microsof...oundplayer.aspx
So.. why not convert the mdi to a wav?
Quote
The SoundPlayer class provides a simple interface for loading and playing a .wav file
http://msdn.microsof...oundplayer.aspx
So.. why not convert the mdi to a wav?
Also a good idea... I suppose I could do that, but I wonder what the difference in file size would be?
It just irks me that there's no apparent way to embed a file that's relatively simple (and whose format has been around forever) and play it from an embedded resource. If I could use the Windows Media Player interface, that would be fantastic, as it has everything I need and more.
It's just weird to me to see programs like application patchers that have midi files embedded and play just fine, but in a .NET app, we don't have that ability? I just keep getting a feeling there's some way I'm overlooking...
(Short of writing my own midi reader from scratch of course lol)
This post has been edited by beju0506: 08 April 2011 - 12:03 PM
#6
Re: Play Midi as an embedded resource?
Posted 08 April 2011 - 12:07 PM
Eh it's the breaks of the libraries.. Have you looked into the SDL (Simple DirectMedia Layer) as an option?
http://cs-sdl.sourceforge.net/
http://cs-sdl.sourceforge.net/
#7
Re: Play Midi as an embedded resource?
Posted 08 April 2011 - 03:09 PM
modi123_1, on 08 April 2011 - 01:07 PM, said:
Eh it's the breaks of the libraries.. Have you looked into the SDL (Simple DirectMedia Layer) as an option?
http://cs-sdl.sourceforge.net/
http://cs-sdl.sourceforge.net/
I suppose so hehe
Actually, that's a really good idea too! I ended up breaking down and writing the file to a temporary location, playing it with Windows Media Player control and then removing it after... however, your solution might be better in the long run. I'm going to check that out.
Thanks!
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|