News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Music - tricky

Started by RedXVII, November 22, 2005, 12:18:45 AM

Previous topic - Next topic

RedXVII

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

Eóin

A crude solution would be to dump the resource music files out to temporary files.

QvasiModo

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.

RedXVII

Thanks QvasiModo - Cant get it to play using MCIWndCreate. Anyone got an example or know how to do this

ta  :U?

P1

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)


dougiem

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

RedXVII

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


P1

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)

RedXVII

isnt there a way to do it without making a temporary file?

Thanks though, ill give it a shot  :U

PBrennick

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]
The GeneSys Project is available from:
The Repository or My crappy website

zooba

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.

P1

Look here:
http://www.fmod.org/

I hope this will help.

Regards,  P1  :8)

Emperor

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