Hi evry body........How can i play mp3 file in masm32
Posted on 2008-05-30 12:08:20 by sudeer
Posted on 2008-05-30 14:39:42 by ti_mo_n
I thought Playsound was able to do it, but when researching I came along a snippet from someone giving mciSendCommand as the answer to that. Here's his quote:

However, if you call mciSendCommand with the MCI_ALL_DEVICE_ID device type - it will play.


op.dwCallback = NULL;
op.lpstrDeviceType = (char*)MCI_ALL_DEVICE_ID;
op.lpstrElementName = "you_file_name.mp3";
op.lpstrAlias = NULL;

// Open command
mciSendCommand( NULL, MCI_OPEN,

// Play command
pp.dwCallback = NULL;
pp.dwFrom = 0;
mciSendCommand(pDevice, MCI_PLAY, MCI_NOTIFY | MCI_FROM, (DWORD)&pp);

Posted on 2008-05-30 18:20:55 by JimmyClif
And there are ways to decode it via ACM, I had posted a snippet here to do that (but this is the hardest way to go, if you just want to play an mp3).
The MCI way is the easiest way, plus you can adjust volume and seek.
PlaySound can play any .wav, but not mp3. This is a tricky thing... you can actually embed mp3 audio inside .wav (WAV is just a wrapper-format, with options for many compression types).
Posted on 2008-05-31 00:21:23 by Ultrano
He asked about mp3 file, so I assumed he means the file format, not the compression format. If the compression format is mp3 and the file format is wav (a wave file with mp3-compressed data), then -yeah- it's quite easy to play it ^^

Oh, and I didn't know that the mci* functions can play mp3 files..? Have you tested it or is it a guess?
Posted on 2008-05-31 10:31:41 by ti_mo_n
Yup, it's been the case ever since win98:
Posted on 2008-05-31 10:59:06 by Ultrano
If I knew this sooner I wouldn't have to write ~300 lines of DirectShow code ^^'
Posted on 2008-05-31 22:34:11 by ti_mo_n
I still could not be able to figure it out, i have 10 different mp3 files in the resorce.
how can i laod and play these files
an example would be appriciated................thanks

Posted on 2008-06-01 03:24:49 by sudeer

use bass.dll for play mp3 from resource

the dll and api doku can you download http://www.un4seen.com/bass.html

.model    flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include bass.inc

include \masm32\macros\macros.asm

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

dialogproc proto :DWORD,:DWORD,:DWORD,:DWORD


bleh db "mod",0; change this to whatever prefix you want
syntax db "%d",0
rsrctype db "DLL",0
err db "can't read/write bass.dll",0
pathbuf db MAX_PATH dup(?)
buf db MAX_PATH dup(?)

; BASSMOD function names, add any others you'll need here
func1 db "BASS_Init",0
func2 db "BASS_Start",0

func3 db "BASS_MusicLoad",0
func4 db "BASS_StreamCreateFile",0

func5 db "BASS_ChannelPlay",0
func6 db "BASS_ChannelPause",0
func7 db "BASS_ChannelStop",0

func8 db "BASS_MusicFree",0
func9 db "BASS_StreamFree",0
func10 db "BASS_Free",0


hInstance dd ?
h dd ?; module handle
fh dd ?; file handle
w dd ?; receives the number of written bytes
s dd ?; size of resource (bass.dll)
buffer dd ?
resh dd ?
module dd ?
PlayOn dd ?

; BASS function addresses, add any others you'll need here
BASS_Init_addr dd ?
BASS_Start_addr dd ?

BASS_MusicLoad_addr dd ?
BASS_StreamCreateFile_addr dd ?

BASS_ChannelPlay_addr dd ?
BASS_ChannelPause_addr dd ?
BASS_ChannelStop_addr dd ?

BASS_MusicFree_addr dd ?
BASS_StreamFree_addr dd ?
BASS_Free_addr dd ?



    invoke GetModuleHandle,0
    mov hInstance, eax
    invoke DialogBoxParam,hInstance,1000,0,addr dialogproc,0
    invoke ExitProcess,0

InitBASSMOD proc
    invoke FindResource,hInstance,1101,addr rsrctype
    test eax,eax
    jz bail_out
    mov resh,eax
    invoke LoadResource,hInstance,resh
    invoke LockResource,eax
    test eax,eax
    jz bail_out
    mov buffer,eax
    invoke SizeofResource,hInstance,resh
    mov s,eax
    invoke GetTempPath,sizeof buf,addr buf
    test eax,eax
    jz bail_out
    invoke GetTempFileName,addr buf,addr bleh,0,addr buf
    test eax,eax
    jz bail_out
    cmp eax,-1
    je bail_out
    mov fh,eax
    invoke WriteFile,fh,buffer,s,addr w,0
    invoke CloseHandle,fh
    invoke LoadLibrary,addr buf
    test eax,eax
    jz bail_out
    mov h,eax

; start retrieving addresses, add any other calls for addresses you want to retrieve here
    invoke GetProcAddress,h,addr func1
    mov BASS_Init_addr,eax
    invoke GetProcAddress,h,addr func2
    mov BASS_Start_addr,eax
    invoke GetProcAddress,h,addr func3
    mov BASS_MusicLoad_addr,eax
    invoke GetProcAddress,h,addr func4
    mov BASS_StreamCreateFile_addr,eax
    invoke GetProcAddress,h,addr func5
    mov BASS_ChannelPlay_addr,eax
    invoke GetProcAddress,h,addr func6
    mov BASS_ChannelPause_addr,eax
    invoke GetProcAddress,h,addr func7
    mov BASS_ChannelStop_addr,eax
    invoke GetProcAddress,h,addr func8
    mov BASS_MusicFree_addr,eax
    invoke GetProcAddress,h,addr func9
    mov BASS_StreamFree_addr,eax
    invoke GetProcAddress,h,addr func10
    mov BASS_Free_addr,eax
    mov eax,1
    xor eax,eax
InitBASSMOD endp

dialogproc proc hwnd:DWORD,m:DWORD,wp:DWORD,l:DWORD
    LOCAL msg[5]:BYTE
    LOCAL hResInfo:DWORD
    LOCAL nMusicSize:DWORD
    LOCAL pMusic:DWORD

    .if m==WM_INITDIALOG
        invoke InitBASSMOD
        .if !eax
            invoke MessageBox,hwnd,addr err,addr err,MB_OK
            invoke ExitProcess,0
        push 0
        push hwnd
        push 0
        push 44100
        push -1
        call BASS_Init_addr
        call BASS_Start_addr
        .if eax!=NULL
            invoke FindResource,hInstance,1100,addr rsrctype
            mov hResInfo,eax
            invoke LoadResource,hInstance,hResInfo
            invoke LockResource,eax
            mov pMusic,eax
            invoke SizeofResource, hInstance, hResInfo
            mov nMusicSize, eax
            .if eax!=NULL
                push 0
                push nMusicSize
                push 0
                push pMusic
                push 1
                call BASS_MusicLoad_addr
                .if !eax
                push nMusicSize
                push 0
                push pMusic
                push 1
                call BASS_StreamCreateFile_addr
                mov module, eax
            invoke wsprintf,addr msg,addr syntax,FUNC(GetLastError)
            invoke MessageBox,hwnd,addr msg,addr msg,MB_OK
        mov PlayOn, FALSE
        mov eax,1

        .elseif m==WM_COMMAND
        mov eax,wp
        .if ax==30
        invoke DestroyWindow,hwnd
        .elseif ax==10
                    .if PlayOn == FALSE
            push 0
            push module
            call BASS_ChannelPlay_addr
            mov PlayOn, TRUE
            push module
            call BASS_ChannelPause_addr
            mov PlayOn, FALSE
    .elseif m==WM_LBUTTONDOWN
        invoke ReleaseCapture
        invoke SendMessage,hwnd,WM_SYSCOMMAND,0F012h,0 

    .elseif m==WM_DESTROY
        call BASS_Free_addr
        invoke FreeLibrary,h
        invoke DeleteFile,addr buf
    xor eax,eax
dialogproc endp

end start
Posted on 2008-06-01 04:41:56 by ragdog