• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

How to play midi from application's resource?

I want to play the midi music from my application's resource directly , like some keygen program , you open it  , it will play some midi music as background music . I don't want to extract the music from resource and play it directly .
0
vitamingoo
Asked:
vitamingoo
  • 8
  • 4
1 Solution
 
kyrleanCommented:
If i understood you question, which i think so.. you  just need to do this on your Form's on create event..
PlaySound(PChar(1),HInstance, snd_ASync or snd_Memory or snd_Resource);
0
 
kyrleanCommented:
# 1 refers to the first resource on your project since you can have as many as you want !
0
 
vitamingooAuthor Commented:
I test your method . it's not successfully.But if the resource file is a wav file, it's successfully.
Can you give me some code.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kyrleanCommented:
Well.. i'm  sorry . I'm not at home so i can't do it right now, but i will as sooner as i get a chance. Can you tell me how did you bild your .res file? Was it an mp3 ?
0
 
kyrleanCommented:
If it's an MP3 you can follow the link bellow. There's  a subtopic called Palying MP3s and then you'll get a full explanation.Following such example you have to add a Tmediaplayer component and a lot more need to be done. For my own use i would prefer to convert the mp3 (if it's really the case)to a wav file and use the code i shown you previously .

http://delphi.about.com/od/objectpascalide/l/aa021301c.htm
0
 
vitamingooAuthor Commented:
It's a midi(*.mid) file.

And thank you.
0
 
kyrleanCommented:
Here is a procedure .

procedure ExtractRes( const ResType, ResName, ExtractedResFileName : String);
var Resur:TResourceStream;
begin
 Resur := TResourceStream.Create( hInstance, ResName, pCHAR(ResType) );
 try
  Resur.SaveToFile(ExtractedResFileName);
 finally
 Resur.Free;
 end;
end;

To call it you'll use ..
//This will extract the .mid file to disk....

ExtractRes( 'MIDI', 'MyMidiRes', 'C:\myfavmidifile.mid');

//and before your application closes, you could use the following to delete the extracted file.

DeleteFile ( ' C:\myfavmidifile.mid ' );

Hope it helps !!!
0
 
vitamingooAuthor Commented:
Thank you . Like the content I mentioned in my question , I know it works if the mid file was extract to disk , but I don't want to do like this , I just want to play the mid music in memory or resourcestream .

I searched in Google , but I can't find the answer .
0
 
kyrleanCommented:
I understand you don't want to create a file on the computer your app is running that's why i suggest you the delete function ( besides the file conversion ) since it's  not gonna be there when your app closes  but, i'll give it one more try and let you  know !
Thanks !
0
 
vitamingooAuthor Commented:
You must have used some keygen program , in these program , open it , it will play some midi background music , and it don't extract any file to disk .
0
 
kyrleanCommented:
I asked many people about it and nobody gave me  a solution to work with this kind of file the same way you do with a .wav for exemple.This  resource  is of a RCDATA and for that reason i don't believe we can do it differently. Before i give up, let me hear from another friend of mine and allow me to make a comment; 2 actually ! The keygen program you  use as an example....
1. may contain a midi converted to wav. " I STRONGLY BELIEVE THAT".
2. it extracts the file to somewhere, obviously not to your Desktop where the application is running  (eg : C:\  or C:\ windows\system32....)and then deletes it after the application terminates.One more time, i understand that you don't want to create a file  in the user machine every time he runs your app, but since it's not visible and it's deleted after... i don't see the problem.
0
 
kyrleanCommented:
Thank you very much for accept my answer/suggestion vitamingoo.Coincidence or not i just heard from that friend last night and he told me about a very complicated method someone else used to hold a file(resource) in the memory without it touch the hard disk.But i assume that, it was out of my capability and i could not pass it to you. Thanks again !!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now