The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: RedXVII on November 22, 2005, 12:18:45 AM

Title: Music - tricky
Post by: RedXVII on November 22, 2005, 12:18:45 AM
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
Title: Re: Music - tricky
Post by: Eóin on November 22, 2005, 01:33:03 PM
A crude solution would be to dump the resource music files out to temporary files.
Title: Re: Music - tricky
Post by: QvasiModo on November 22, 2005, 04:12:42 PM
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.
Title: Re: Music - tricky
Post by: RedXVII on November 23, 2005, 09:28:08 AM
Thanks QvasiModo - Cant get it to play using MCIWndCreate. Anyone got an example or know how to do this

ta  :U?
Title: Re: Music - tricky
Post by: P1 on November 23, 2005, 05:09:47 PM
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)
Title: Re: Music - tricky
Post by: subhadeep_ghosh on November 23, 2005, 05:46:57 PM
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
Title: Re: Music - tricky
Post by: dougiem on November 24, 2005, 06:11:50 PM
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
Title: Re: Music - tricky
Post by: RedXVII on November 24, 2005, 11:51:06 PM
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

Title: Re: Music - tricky
Post by: P1 on November 25, 2005, 09:01:41 PM
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)
Title: Re: Music - tricky
Post by: RedXVII on November 28, 2005, 09:56:44 PM
isnt there a way to do it without making a temporary file?

Thanks though, ill give it a shot  :U
Title: Re: Music - tricky
Post by: PBrennick on November 29, 2005, 12:46:41 AM
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]
Title: Re: Music - tricky
Post by: zooba on December 02, 2005, 08:01:47 AM
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.
Title: Re: Music - tricky
Post by: P1 on December 02, 2005, 01:48:30 PM
Look here:
http://www.fmod.org/

I hope this will help.

Regards,  P1  :8)
Title: Re: Music - tricky
Post by: Emperor on March 23, 2006, 11:58:37 AM
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