News:

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

Simple MP3 music player example.

Started by Bill Cravener, October 20, 2008, 02:36:53 PM

Previous topic - Next topic

Bill Cravener

Here is a very simple example on how to play MP3 music files. Also shows how simple it is to use a list box control. Playing MP3 music files doesn't get much easier then this using asm. Requires masm32 to assemble. Also includes executable.


[attachment deleted by admin]
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

herge


Hi Cycle Saddles:

Nice mp3 demo.

Regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

Bill Cravener

Thanks herge, have fun buddy!  :wink
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

RuiLoureiro

Quote from: Cycle Saddles on October 20, 2008, 02:36:53 PM
Here is a very simple example on how to play MP3 music files.
Hi, Cycle Saddles
                          Thanks. It works and my prog play mp3 music now! Thank you  :U

Rui

Bill Cravener

Your welcome RuiLoureiro, I'm glad you found it useful!  :bg
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

RuiLoureiro

Cycle Saddles,
                     How to know when the music ends ? I want to play 2 musics one after another
                     When one ends i want to play the other. How ?
                     (To play a music i call  PlayMp3File)
Thanks
Rui

Bill Cravener

The MM_MCINOTIFY message is sent to the app when the music has completed. MCI devices send this message only when the MCI_NOTIFY flag is used. So when this message is received point to the next music filename and call the PlayMp3File procedure again.

Here is a good source of info using MCI. http://msdn.microsoft.com/en-us/library/ms709461(VS.85).aspx
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

thomas_remkus

That was very cool! I like your coding style ... easy to read and learn from.

Bill Cravener

Thanks thomas, there are more of my examples around here and you can find more in hutch's masm32 package under the examples/bcraven directory. I also plan on whipping out a few more simple examples for those who wish to learn sometime this winter.  :bg
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

RuiLoureiro

Quote from: Cycle Saddles on October 22, 2008, 12:03:45 PM
The MM_MCINOTIFY message is sent to the app when the music has completed. MCI devices send this message only when the MCI_NOTIFY flag is used. So when this message is received point to the next music filename and call the PlayMp3File procedure again.

Cycle Saddles,
                     Thank you again, it works !
Rui

Bill Cravener

My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

elmo

hi, Bill Cravener, that;s good app :U

btw, I'm in search how to get time length of file1.mp3
I think MCIWndGetEnd will give me the duration of file1.mp3 file. but I m wrong.
the real duration of file1.mp3 is 3 minutes and 5 seconds
with MCIWndGetEnd, I get 1850762 . Maybe I missunderstand
I also want to get who is the artist, what is the album title of file1.mp3. I don't have imagine how to do that..

would you like to give me a clue?
thank you
sorry for my bad english


invoke MCIWndDestroy, hMci ;kill any currently playing tracks
invoke MCIWndCreate,
hWnd, 400000h,
WS_CHILD or MCIWNDF_NOOPEN,
SADD("C:\file1.mp3")
mov hMci,eax
pop eax ;For some reason 4 things are pushed onto stack unnecessarily
pop eax ;so they have to be popped off the stack to prevent crashing
pop eax ;Thanks to Ron Thomas for spotting that one!
pop eax
invoke MCIWndGetEnd, hMci
        invoke MessageBox,hWnd,str$(eax),SADD("duration of file1.mp3"),0
be the king of accounting programmer world!

Bill Cravener

Hi elmo,

I have no idea how to achieve what you want and I'm just too busy with the real world to find it for you.

That simple little example was derived from the information I gathered from reading the mciSendCommand API from Microsoft's SDK. I think you can find what you need by digging in the MS SDK under that subject.

Microsoft's SDK is your friend! :bg

My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

Tedd

Technically, it all depends on what the current time format is, but..

1850762 / 10000 = 185.0762

3 minutes + 5 seconds = 3*60 + 5 = 185



As for the album information, it's stored in the ID3 tag. I don't think MCI provides direct access to that, so you may have to extract them yourself. Version 1 tags are very simple, and stored in the last 128 bytes of the file, version 2 provides much better information, so it's a little more complex, and is attached at the beginning of the file.
No snowflake in an avalanche feels responsible.

donkey

Hi elmo,

It's not too difficult to get the duration of an MP3 file without the MCI functions. They fail on VBR encoding anyway, at least they did when I checked them out a few years ago. I posted a tag reader I wrote some time ago that will calculate the duration (in milliseconds) of an MP3 file:

http://www.masm32.com/board/index.php?topic=10610.0

You're welcome to use any part of it you want.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable