Skip to main content

Microsoft Silverlight

Playing MIDI through SilverlightRSS Feed

(0)

generalgoodtimes
generalg...

Member

Member

6 points

5 Posts

Playing MIDI through Silverlight

More specifically, would it be possible to create a MIDI file in memory and then load it into some media playing object that silverlight might have? I'm not looking to communicate with MIDI devices, just play MIDI files... 

chad.campbell
chad.cam...

Participant

Participant

1918 points

332 Posts

Silverlight MVP

Re: Playing MIDI through Silverlight

Hello generalgoodtimes,

Silverlight does not support the MIDI format.  However, you could create a MIDI file in memory and then encode it into the .mp3 file format using a workflow that uses a command line application.  You could then play the MP3 file within a MediaElement.

If this answers your question, please select "mark as answer", otherwise, please post a follow up question.

Thank you,

Chad Campbell

If this answers your question, please select "mark as answer", otherwise, please post a follow up question. Thanks!
Chad Campbell

Author of Silverlight 2.0 in Action Blog: http://cornucopia30.blogspot.com

generalgoodtimes
generalg...

Member

Member

6 points

5 Posts

Re: Playing MIDI through Silverlight

Hi Chad,

Thank you for your reply. While that is good news, its only slightly what I'm looking for. Let me ask you this - do you suppose it would be possible to both create the MIDI file in memory and then encode it into an MP3 file within the same Silverlight application? I see no reason why that would not be possible - but then here's the big question - can MediaElement play a file that was created in memory? I spent a good deal of time investigating this on MSDN last night, and I don't think it can - but maybe I'm missing something... Any help or other ideas would be greatly appreciated.

Thank you,

Rob

 

chad.campbell
chad.cam...

Participant

Participant

1918 points

332 Posts

Silverlight MVP

Re: Playing MIDI through Silverlight

You could encode the .midi file as an MP3 file, then use the SetSource method and an downloader object. 

If this answers your question, please select "mark as answer", otherwise, please post a follow up question. Thanks!
Chad Campbell

Author of Silverlight 2.0 in Action Blog: http://cornucopia30.blogspot.com

generalgoodtimes
generalg...

Member

Member

6 points

5 Posts

Re: Playing MIDI through Silverlight

Hi Chad,

That is what I was thinking, but I'm trying to do this without saving the MP3 file to disk, whether locally or remotely. I want to do this all in memory - and my understanding is I can't give a byte buffer to Downloader.SetSource - did I just miss something in the documentation that would allow this, or is there another way to go about that?

Thanks,

Rob

electroguerrero
electrog...

Member

Member

15 points

20 Posts

Re: Playing MIDI through Silverlight

Hi, 

I find it very interesting, but ...

" using a workflow that uses a command line application. "

could u explain, these phrase, with a little more of detail?, thank you very much

djprod
djprod

Member

Member

334 points

65 Posts

Re: Playing MIDI through Silverlight

Why not just add the Windows Media Player to your html page it plays midi files:-

<object id="Player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="position:absolute;top:10px;width:64px;height:54px;" >
<param name="autoStart" value="false"/>
<param name="UImode" value="none"/>
<param name="stretchtofit" value="true"/>
<param name="volume" value="100"/>
<param name="Url" value="12popcorn.mid"/>
<param name="windowlessVideo" value="true"/>
</object>

 Accessing it is easy:-

HtmlPage.Window.Eval("parent.document.getElementById('Player').controls.play()");

Regards

Marc.

loarabia
loarabia

Member

Member

80 points

25 Posts

Re: Playing MIDI through Silverlight

It seems to me like you should be able to create the MIDI content, encode it in memory into an Mp3 (or WMA) where the contents are written to a MemoryStream and then use MediaElement.SetSource to set the source to the MemoryStream containing the freshly encoded Mp3 content. The only place I can think of here where you might run into trouble is if you continued adding to the MemoryStream after you had already passed it to the MediaElement for playback.

Larry Olson
Silverlight PM
Microsoft

odahan
odahan

Participant

Participant

1625 points

291 Posts

Re: Re: Playing MIDI through Silverlight

I just looked at this thread and I'm feeling a bit like a martian discovering strange human behavior :-) It seems obvious for everyone here "to encode a Midi file into a MP3".

Well.. I'm not bad at C#, I'm also a composer using a lot of midi devices and digital things...So I know a little bit about all this stuff, and I can say one thing : it is not obvious to "encode" a Midi into a MP3 !

Midi file does not carry any sound, just some data about what notes are played, when and how long (plus some other info).

The only way to "encode a midi file into a MP3" is to create a synthesizer that will play the score, get the resulting Wav and then, ok, encode the latter into MP3. Two things that are far to be obvious !

But it seems to be simple for everyone in this thread so, I'll just add : Good luck guys ! :-)

(and do not forget to publish your source code, just the little tricky part that can "encore a midi into a mp3", I'd love to get it :-) )

Olivier Dahan (MVP C#)
wwww.e-naxos.com
Blog: www.e-naxos.com/blog
English is not my native language so be indulgent and do not hesitate to ask for clarification! Thanks.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities