April 23, 2024, 01:28:20 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Compiling an mp3 file as a resource and 'playing' it in program?

Started by AdrianFox, December 04, 2012, 07:32:08 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

I posted this question under Creative Basic questions but I think it would be better posted here for a wider audience of those who know how to do such things as the query is equally relevant to IWB!

I frequently embed wav files as a resource and have no problem using 'LOADRESOURCE'  
with 'playwave mymem, @sndasync' and so on to play them in the program.  

I was intrigued by Graham's use of midi (or mp3) files in one his Creative Basic programs  using the API call:

:

declare "WINMM",mciSendStringA(command:STRING,temp:STRING,length:INT,callBack:INT),INT


He then loads a music file from disk which can be in a variety of formats...

musicfile = getstartpath + "Music.mp3"


and plays it with

mciSendStringA("Play " + musicfile,"",0,0)

With my limited understanding of the whole process involved,  I am wondering if the same API call can be used and similar code to load the file from a resource?

I have saved my mp3 file as a custom resource having declared memory, def mymem as memory, and using the following:


loadresource("RES_SND", "MP3",mymem)


To my simple mind that means I have loaded my customised resource into memory,  but I am then at a loss to know how I would go on to 'PLAY' it from memory.  The only code I can find in the Resources section of the manual is how to 'playwave' .wav files.

I hope I've explained that clearly and that maybe someone can tell me if I am attempting something that is not possible, or even has some idea how I might achieve this!

Thanks...  :)

Adrian Fox

LarryMc

I couldn't figure out a way to play a resource mp3 after it was loaded into memory.(althought there may be an easy way)

However I did find a way that it can be done.

I used Fletchie's CTL.lib and Sapero's include file (which I always use)

The attached zip contains a console project.
The Joy to the World mp3 is added to the project as a resource.

The subroutines interacting with the resource file require that the id and the type of the resource be numbers.
(i.e, the strings used in the loadresource command are not allowed.

A routine is called that creates a unique tmp file in the system temp folder.
then we save the unique name, strip tmp and add mp3 to the file name.
we then extract the resource to that file name
next the mci commands are given to play the mp3.
when we are through with the temp mp3 we close out the player and delete the file

the project can be adapted to work with a window just a well.
you can also, using mci commands , add code to play multiple files
the important thing to remember is to delete the temp mp3 files when they are no longer needed.

@Adrian - This should allow you to do what you want to do until someone comes up with a better method.

After unzipping run the exe to hear the mp3 before the actual mp3 file is present(needed to compile)

Good Luck
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

Thanks very much Larry, I'll see how that works.  It's always so much 'neater' to produce a program  with all the necessary files in the single exe! 

Of course my other option would be just to convert my mp3 files into wav,  but I am assuming that they would take up much more space in the compiled program being much larger files?

:)

Adrian Fox

aurelCB

Hi..
I don't have try but might be work...
Instead to put mp3 in resource try to load mp3 into memory buffer. ->mbuffer2
Put also already compiled mp3 player(your program) into memory buffer -> mbuffer1
Then connect two buffers (bind)
output=mbuffer1+mbuffer2
and save as binary file to disk.(with extension .exe)
Of course your program must know how much bytes is long
then load mp3 file from where begins...

LarryMc

Aurel
The problem is not adding the mp3 to the exe file.  Resources works fine for that.
The problem is how do you play a mp3 file that is stored in memory when the api that plays the file requires a file name.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

I'm still experiencing problems with this I am afraid.  What has gone wrong here?

1. I downloaded Larry's program in the zip file af3a.zip above.

2.  I ran the exe to see and of course it works perfectly.

3. I then loaded the af3a project file and looked at the code.

4.  I tried to compile it.  I got error messages about the missing ctl.inc and windowssdk.inc files.

5. I found a copy of ctl.inc and put it in the IWBdev inc folder.

6.  Looking for the windowssdk.inc file,  I found Larry's 'Headers' file for IWB and Ebasic.  (An 11Mb zip file)

7. I downloaded this and ran it, selecting the IWBDev folder and the IWB options.

8. Now trying to compile the AF3A program it fails to compile but says it can't find the ctl.lib, version.lib, rpcns4.lib, or urlmon.lib

9.  The 'headers' installation file didn't complete all the installation and said it couldn't install certain library files.  I can't find any of the above in the lib folder.

What have I done wrong?  What should I do next?

Forgive me if I am being a prat but I don't know if this is my mistake or some problem with that 'headers' installation file.
Adrian Fox

LarryMc

Quote5. I found a copy of ctl.inc and put it in the IWBdev inc folder.
I don't know where you found it but did you also put the associated ctl.lib file in the libs folder?
The ctl install program is available over on my site as a download.
http://www.codingmonkeys.com/index.php?action=tpmod;dl=item108

Quote9.  The 'headers' installation file didn't complete all the installation and said it couldn't install certain library files.  I can't find any of the above in the lib folder.
During the install process for windowssdk it will attempt to create linking libraries .lib files for a lot of .dll files that come with windows and also some that don't come with windows so the warnings that certain files can't be found(during the install process) is normal. But the installer should run to completetion. The version.lib, rpcns4.lib, and urlmon.lib files should have been created by the sdk installer provided the corresponding dll files are installed on your computer by Windows.

suggest you redownload the windowssdk and reinstall.
the close and reopen IWBasic and then reopen the af3a project file

BTW, what OS and computer are you using?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

I'm running Windows XP home edition, 2002 service pack 3, with Intel Core Quad CPU, 2.33Ghz, 2.96Gb memory.

I will check for that ctl.lib file and re-run the installation as you suggest.

UPDATE:  'mille  excuses'!   I see now that I was being impatient on the installation and when the installation pauses for several seconds while installing the lib files I had closed it thinking it was finished!   Another senior moment!

Now all works absolutely fine and tickety boo!   

thanks for being so patient!  The embedding of mp3 resources will be extremely useful to me in future efforts so thanks so much for showing me how it can be done.

;)
Adrian Fox