hii
is it possiable to add a mp3 file using a resource script????
thanks
yup...
i think you just make it RC_DATA and include the file into it
mymp3data RCDATA DISCARDABLE "mymp3file.mp3"
so the resource fill be called 'mymp3data'
hi
first thanks for the replyevlncrn8.
it worked.but the problem is I can't play that file using MCI functions.
is their any way I can Play this???
thanks
yeh you need to dump it to a temp file, then mci can play from it...
hi
thanks for the tip.can you tell me how can I dump the .MP3?????
is their any API for that???
thanks.
Just use a WriteFile operation from the start address of the embedded MP3 with the correct byte count for the API.
FindResource -> SizeOfResource -> LoadREsource -> LockResource -> CreateFile -> WriteFile -> FlushFileBuffers -> CloseHandle -> FreeResource
though the FreeResource isn't needed for win32 apps.. some redundancy there, but i think that shows you the steps you have to go through
Hi anuradha, this code snippet works under XP. I don't delete the HDD file as the game uses a lot of FX samples. I wrote this several years ago for my Grandson, he's now moved on to GameBoy and PS2 !
I hope this is of some help.
.data
FileNameFX db 'C:\TEMP\Music\tempFX.mp3',0
Mp3EndFX dd 0
TimerFX dd 0
mcihWndFX dd 0
MusicData db 'MUSIC',0 ; Resource description used in resource file
MusicOFF dd ?
.code
PlayFX proc param1 :DWORD ;param1 is the resource ID
LOCAL ResourceHandle :DWORD
LOCAL ResourceSize :DWORD
LOCAL ResourceAddr :DWORD
LOCAL hFile :DWORD
LOCAL FileReturn :DWORD
;----------------------------------
; cancel currently playing track
;----------------------------------
.if mcihWndFX>0
invoke MCIWndDestroy, mcihWndFX ; kill any sound effects
mov mcihWndFX,0
.if TimerFX>0
invoke KillTimer, hWnd, TimerFX
mov TimerFX,0
.endif
.endif
;--------------------------------------
; check that sounds are to be played
;--------------------------------------
.if MusicOFF==1
return 0
.endif
;--------------------------
; get resource details
;---------------------------
invoke FindResource,hInstance,param1,addr MusicData
mov ResourceHandle,eax
.if eax==0
ret
.endif
invoke SizeofResource,hInstance,ResourceHandle
mov ResourceSize,eax
.if eax==0
ret
.endif
invoke LoadResource,hInstance,ResourceHandle
mov ResourceAddr,eax
.if eax==0
ret
.endif
;-----------------------------------------------
; copy resource data to file on hdd
;--------------------------------------------
invoke CreateFile,ADDR FileNameFX,GENERIC_WRITE,FILE_SHARE_READ,
NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
.if eax==INVALID_HANDLE_VALUE
ret
.endif
mov hFile,eax
invoke SetEndOfFile,hFile
invoke WriteFile,hFile,ResourceAddr,ResourceSize,addr FileReturn,0
invoke CloseHandle,hFile
.if eax==0
ret
.endif
;--------------------------------------
; now play the track using MCI
;-------------------------------------
invoke MCIWndCreate,hWnd,hInstance,WS_CHILD or MCIWNDF_NOOPEN,\
addr FileNameFX
mov mcihWndFX,eax
pop eax ;Fix up stack
pop eax
pop eax
pop eax
invoke MCIWndGetEnd, mcihWndFX
mov Mp3EndFX, eax
invoke MCIWndPlay, mcihWndFX
invoke SetTimer, hWnd, 1, 1000, addr TimerProcFX ;start up timer
mov TimerFX, eax
ret
PlayFX endp
; ##############################################################
TimerProcFX proc
invoke MCIWndGetPosition, mcihWndFX
.if eax==Mp3EndFX ;eax=secs to 3 dec places
.if mcihWndFX>0
invoke MCIWndDestroy, mcihWndFX
mov mcihWndFX,0
.endif
invoke KillTimer, hWnd, TimerFX
mov TimerFX,0
.endif
ret
TimerProcFX endp
; ##############################################################
Per MSDN: LoadResource (http://msdn2.microsoft.com/en-us/library/ms648046.aspx):
"The return type of LoadResource is HGLOBAL for backward compatibility, not because the function returns a handle to a global memory block. Do not pass this handle to the GlobalLock or GlobalFree function. To obtain a pointer to the resource data, call the LockResource function."
I have been assuming that the LockResource call was required to get usable pointer, but now that I test with an application that creates a font file from a resource, LoadResource and LockResource are both returning the same value, so the application works correctly without the call to LockResource.
Hi anuradha,
To embed your mp3 file into your main application, you can use the File Data Assembler tool fda.exe supplied with the Masm32 package. This method does not require the usage of resources.
hi
thank you all.
:U :U :U
hi
Okay I did it using evlncrn8's procedure. But the thing is that only part of
the mp3 is dumped . first part of the file is missing. Is their any way to
over come this?
I'm give the source code . But its in C . I hope I'm not breaking the forum rules!
thanks :(
anuradha
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Here the mp31 is the resource identifier
#include <windows.h>
#include <vfw.h>
HANDLE hBag;
HMODULE hExe;
HANDLE Bcount;
HANDLE htrack;
HANDLE hfile;
LPVOID lpRes ;
char lpfname [] ="11.mp3";
int buffer ,test ,bufferw;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
htrack=FindResource(NULL,"mp31",RT_RCDATA);
Bcount=SizeofResource(NULL,htrack);
hBag=LoadResource(NULL,htrack);
lpRes=LockResource(hBag);
hfile =CreateFile(lpfname,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,NULL);
buffer=Bcount;
//bufferw=Bcount;
WriteFile(hfile,buffer,Bcount,Bcount,NULL);
FlushFileBuffers(hfile);
CloseHandle(hfile);
}
should it be
WriteFile(hfile,lpRes,Bcount,Bcount,NULL);
hi
Its working thanks.Can you explain it ?? why lpRes?
thanks.
lpRes=LockResource(hBag);
lpRes points the resource in memory, it's the address of the memory portion containing the resource.
because...
lpRes=LockResource(hBag);
that...
lpRes is the return of LockResource (which returns the 'locked' memory address).. ie: the start of the resource
hi
okay I got it . Thank you both
anuradha :U :U