Im making a small app. I want to put a pieve of music (one is .mp3 and one is .wma) in the resource to make just one executable. Trouble is, i dont know how to play them as a resource. I recently learnt the useful MCIWndCreate with SendMessage to play tracks. Trouble is, that requires a string (directory) to the file, and i dont know how to play it when its in my resource. Anyone got an example or want to enlighten me with where i should be looking?
Thanks :U
A crude solution would be to dump the resource music files out to temporary files.
IF it's possible (which I don't know) to use an URL instead of a filename, you can try something like this:
res://C:/path/your_program.exe/resource_id
Where "resource_id" is the resource name (if you used a string) or a decimal number, preceded by a numeral symbol (#) if I recall correctly, if you used an integer.
Thanks QvasiModo - Cant get it to play using MCIWndCreate. Anyone got an example or know how to do this
ta :U?
Quote from: RedXVII on November 23, 2005, 09:28:08 AM
Anyone got an example or know how to do this?
The viable route is to go with the extract to temp file. And play it.
If you use 'Search', you will find several examples.
Regards, P1 :8)
You could take a look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_mciwndcreate.asp and maybe do something with it... :U
I have had this problem myself and had to stick to using a temp file. It will be interesting to here if anyone can accompish this.
dougiem
P1: i presume you mean search the forums, ill do that now [Edit: couldnt find anything - not even on the web either] :(
Left Of Right: Yes, ive seen that - thats what i use to play music, i cant get it to play music in part of the resource
RedXVII,
There are several examples in 'Search'. But I know picking the right keyword to search on is half the battle.
Modify the Destination for the TempFolder and Play from there.
A snippet I uploaded to MadWizard's website a while ago.
http://www.madwizard.org/view.php?page=snippets
; #########################################################################
;USAGE
szResMarker db "BINFILE",0
szResourceName db "My_File",0
szDestination db "MyReadMe.txt",0
invoke ResExtractFile,hInstance,addr szResourceName,addr szResMarker,addr szDestination
;Line in Resource File
;My_File BINFILE Readme.txt
; #########################################################################
ResExtractFile proc hInst:DWORD, Resource:DWORD, ResMarker:DWORD, Destination:DWORD
LOCAL hRsrc:DWORD
LOCAL hResource:DWORD
LOCAL dwResSize:DWORD
LOCAL hFile:DWORD
LOCAL dwWritten:DWORD
LOCAL lpfResource:DWORD
invoke FindResource,hInst,Resource,ResMarker
.if eax == NULL
not eax
.else
mov hRsrc,eax
invoke LoadResource,hInst,hRsrc
.if eax == NULL
not eax
.else
mov hResource,eax
invoke SizeofResource,hInst,hRsrc
mov dwResSize,eax
invoke LockResource,hResource
mov lpfResource,eax
;Currently setup to overwrite, if present.
invoke CreateFile,Destination,GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
.if eax == INVALID_HANDLE_VALUE
;User can use GetLastError
.else ;File is present.
mov hFile, eax
invoke WriteFile,hFile,lpfResource,dwResSize,ADDR dwWritten,NULL
mov eax,dwResSize
.if eax == dwWritten
invoke CloseHandle,hFile
mov eax,ERROR_SUCCESS
.else
invoke DeleteFile,Destination
mov eax,-2
.endif
.endif
.endif
.endif
ret
ResExtractFile endp
; #########################################################################
Regards, P1 :8)
isnt there a way to do it without making a temporary file?
Thanks though, ill give it a shot :U
RedXVII,
Try the following attachment from William F. Cravener 12/07/2003. It displays a picture of a motorcycle and plays an MP3 at the same time.
EDIT: I think I misred your first post. Sorry :'(
Anyway, it is a cool example and it works.
hth,
Paul
[attachment deleted by admin]
Generally everywhere a filename is accepted in the Windows API a resource identifier string (eg. "#101") will be accepted. There may also be better DLLs which can be used to play music these days, have a look at the Windows Media SDK documentation.
Look here:
http://www.fmod.org/
I hope this will help.
Regards, P1 :8)
I know this is an old thread but here goes...
You could add a wav file as a resource then play it using PlaySound:
// Resource file
#include "\masm32\include\resource.h"
WAVE_SOUND WAVE "C:\WINDOWS\Media\chimes.wav"
; Assembly file
.486
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\winmm.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\winmm.lib
.data
pWave db "WAVE_SOUND", 0
.code
start:
invoke GetModuleHandle, NULL
invoke PlaySound, addr pWave, eax, SND_RESOURCE or SND_SYNC
invoke ExitProcess, NULL
end start