The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Bill Cravener on October 20, 2008, 02:36:53 PM

Title: Simple MP3 music player example.
Post by: Bill Cravener on October 20, 2008, 02:36:53 PM
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]
Title: Re: Simple MP3 music player example.
Post by: herge on October 21, 2008, 01:04:39 PM

Hi Cycle Saddles:

Nice mp3 demo.

Regards herge
Title: Re: Simple MP3 music player example.
Post by: Bill Cravener on October 21, 2008, 01:48:26 PM
Thanks herge, have fun buddy!  :wink
Title: Re: Simple MP3 music player example.
Post by: RuiLoureiro on October 21, 2008, 03:43:23 PM
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
Title: Re: Simple MP3 music player example.
Post by: Bill Cravener on October 21, 2008, 04:23:00 PM
Your welcome RuiLoureiro, I'm glad you found it useful!  :bg
Title: Re: Simple MP3 music player example.
Post by: RuiLoureiro on October 22, 2008, 10:35:01 AM
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
Title: Re: Simple MP3 music player example.
Post by: Bill Cravener 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.

Here is a good source of info using MCI. http://msdn.microsoft.com/en-us/library/ms709461(VS.85).aspx
Title: Re: Simple MP3 music player example.
Post by: thomas_remkus on October 22, 2008, 03:07:51 PM
That was very cool! I like your coding style ... easy to read and learn from.
Title: Re: Simple MP3 music player example.
Post by: Bill Cravener on October 22, 2008, 03:54:31 PM
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
Title: Re: Simple MP3 music player example.
Post by: RuiLoureiro on October 22, 2008, 05:55:56 PM
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
Title: Re: Simple MP3 music player example.
Post by: Bill Cravener on October 22, 2008, 06:24:01 PM
Good!   :wink
Title: Re: Simple MP3 music player example.
Post by: elmo on April 08, 2011, 08:03:01 AM
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
Title: Re: Simple MP3 music player example.
Post by: Bill Cravener on April 08, 2011, 11:05:26 AM
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

Title: Re: Simple MP3 music player example.
Post by: Tedd on April 08, 2011, 11:18:29 AM
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.
Title: Re: Simple MP3 music player example.
Post by: donkey on April 10, 2011, 09:17:55 PM
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.