But for something a little closer to your level of programming you should just drag and drop the MediaPlayer component (Ctrl+T) into VB and start from there....
Afetr you get more experienced then you can move on to declarations....
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
The best solution. :thumb: Paste this code into a class file and declare it as
Private MyPlayer as New ClassNAme
then you can access it with,
MyPlayer.Stop
The post that I got it from had smilies enabled, so it did something similar to about 3 lines in the code, so if you get an error, it should be either ":)" or ";)" (without quotes).
Enjoy. :)
VB Code:
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
That code needs serious fixing. First of all, where is Option Explicit? There are tons of undeclared variables... and when I started to go through fixing it, I ended up getting confused what the *censored* it is doing. TimeRemaining for example, it does something weird in there. And why all the return values are string? And why there are functions even if those don't return anything? Should be a sub then.
Thank you....you just proved my prior statement...
And @ PC_Madness.... what are you trying to do the kid with all those codes?
The kid just found out what boolean is and you're gonna lay this sort of coding on him?
(Not to mention the codes are incorrect...)
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
Well, the code does work (I guess, I didn't check it before I started to fix it). The problem is how it works and what it returns. It is far from optimal. And boy do people like optimal...
Edit Here we go again!
VB Code:
If sec < 60 Then Position = "0:" & Format(sec, "00")
If sec > 59 Then
mins = Int(sec / 60)
sec = sec - (mins * 60)
Position = Format(mins, "00") & ":" & Format(sec, "00")
End If
Dear lord...
More edit I don't mean to be insultive, it just bugs me so much to see such a code. Or maybe I'm just evil?
I'm now working with a "better" class, which is fully commented and should be easy to use as well. I guess I make a sample program too. Atleast I can say I made it, since it is all different from the one posted above
And yeah, it is made hard, but this is because there are so many things one might want to know (such as playback position, playback length and so on).
Wonder if I go as far as getting tags... or, even, saving tags. That'd be cool to implement
Originally posted by SandmanSamR see, this is the type of overwhelming things I'm talking about. Why the hell is there so many things just to play a simple mp3?!
Oh and thanks protocol. I know someone gots mah back
To play an MP3 is a bit complicated. You only see the Play and Stop buttons in Winamp, the code for Winamp is actually quite LARGE.
I was working on an MP3 class in C++. I haven't worked on it for a while, but the declarations of everything alone is a good 100-200 lines of code. Not to mention the ID3 v1, v1.1, and v2 Tag reading code. I haven't finished the whole playing part, lol.
Anyway, there isn't going to be a very easy solution like
Code:
PlayMP3("Slayer.mp3")
You first need to decide how you want to play it. Win API? Direct Sound? ect.... there are many ways. When you determine that, you will then need to learn how an MP3 file is made and works so you can write the code to play it.
Seeing that you are new, I would suggest a different project. Perhaps a text editor or something? That way you'll learn the language much better before tackling such a project.
Originally posted by kasracer
I was working on an MP3 class
I just started seeing class used in explinations, I am unfamiliar with the term. how, what, and why is it used? Normally I would first go look it up but its kind of hard looking up the word class without thousands of irrelevent results
Seeing that you are new, I would suggest a different project. Perhaps a text editor or something? That way you'll learn the language much better before tackling such a project.
Common now, Text editing? well yeah I guess so, seeing as how thats what we recently learned. Recently being couple weeks ago but still. I dont like the pace the class because 1/2 the class is learning slower then others, by a lot!
And here we have the MP3 class I've been working on. The class module and a simple project demonstrating how to use it.
I included a proper error handler. It records all errors for programmer's convenience.
And as a btw, I found atleast one mp3 which it didn't play. It seemed to work ok, but I didn't hear anything. I don't know if this is a bug in MCI or in my sound drivers. All other mp3s I tested played just fine.
You're welcome to report any errors you find
Edit Fixed GetStatus problem, it now returns the correct status.
More edit This versiom has no ID3v1 support, scroll below for newer code.
I downloaded it, and I'm going to check it right after I reinstall VB6.. I've been meaning to make some autoplay's for MP3 CDs that I've made in the past, but I didn't like the Media Player Control and it's options that much.. so, I'll get back to you.
@Merri....Just goes to show you that postcount does not make the Guru...
I have yet to find an MP3 tag class that supports MusicMatch feature for album imaging....when that is done, to the codebank it goes.....
@ kasracer: 100-200 lines of declarations?!!
What are you creating an OS?
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
And a new version out. Now you can edit and save ID3v1 tags. Ain't that fun? Also, fixed an error in the genres list (values were one too big) and did some other minor enhancements somewhere. I can't find a bug, so its ready enough for another upload
And, well, guru... I'm good only with some things. Maybe a guru of generic coding or something like that. And well, I haven't been all that much in here, so that's why my post count is so small. I'm no MadBoy who posts about anything and everything he gets his mind into before even thinking about trying doing it himself Ok, that was a bit over, but it is a half-truth, since he HAVE posted somewhat twice as much in two months as I have in the entire time I've been here (registered the first time in early 2001, add about 200 to my post count).
Uhhuh, this is going too much off-topic, so please don't answer to this. Otherwise we gotta go to Chit Chat.
Maybe I'm able to work on ID3v2 tags too. That requires a lot more work though, since I have no proper code ready for it atm and v2 tags are far more complicated to read (and especially write) than v1 tags.
Also, I happened to find www.fmod.org - maybe I can make a similar class module for that DLL to ease the life of a VB programmer, since the DLL is free. I tested it and it worked like a charm. Ideal for playing audio. It supports OGGs and modules too
I've been reading the ID3v2 specification and I'm pretty sure I understand it completely by now. Complex format compared to ID3v1, but I managed to get it after some ten hours of reading and pondering. Of course I did some other things in the while. I'm pretty sure I'm now able to write the code (I wrote some types while going through the document and fixed them as I understood more... atm I need only to write the code that does the dirty work and reads the tag into memory).
I expect to have a new version of the class module to be out by tomorrow, with full ID3v2 support. Full means you can get any information from the tag, be it pictures or whatever it can have. I think the next bigger problem I have is CRC-32 since there can be CRC-32 data... as for encryptions and compressions, I'm leaving those for the programs to handle. There are just so many different ways to do it.
Originally posted by Protocol lol
@ kasracer: 100-200 lines of declarations?!!
What are you creating an OS?
First of all, That is a phat ass program! Thank you!!!!
a couple questions though, when I first opened it, it said something was wrong with this line:
VB Code:
Dim MyMP3 As New MP3_CLASS
I just unloaded everything, opened project as new and just added the form and the class into the already opened project and it seems to have fixed that error message.
Also, everytime I open a new song it says error "263|The specified device..." why does that keep opening?
Do you think with my "know-how" I can add a playlist to that? and if so, what about a randomize order and/or play?
I would rather try it before you go off and do it unless you think its to much of a task for me to handle
Last edited by SandmanSamR; Dec 29th, 2003 at 01:12 PM.
Yeah, I just noticed I forgot .FRX files from the zip file. And nobody told me I had done so. I don't update the zip before I get ID3v2 support done. Which is going on nicely, I just managed to read some of my files properly with it Still, it needs some expanding to be fully functional...
First of all, does the song play? If it does, you can ignore the error. The error detection is maybe reacts too easily to things... but atleast it is quite good
Then some small coding tutorials
To go on with a simple playlist:
- add a listbox
- instead of placing a filename into txtFile textbox, add it to the listbox
- modify code in butOpen to use List1.List(List1.ListIndex) instead of txtFile.Text to open files
To have a random song playing when a song ends:
- find the following line in StatusUpdate_Timer:
VB Code:
If Val(Status) = 4 And Length = Position Then MyMP3.SeekTo 0: MyMP3.PlayMP3
Now, remove everything after Then and add butClose_Click, List1.ListIndex = Int(Rnd * List1.ListCount) and butOpen_Click
You might get same song twice, as you don't keep any track on what have been played. You might encounter some errors too, since there is no error checking (such as if there are listitems at all in the listbox).
Voilá! I have now coded a simple ID3v2 tag support. It isn't perfect... yet. Wonder if this will be ready this year? Two days to go...
What I added:
- flexible read and storage routines for ID3v2 tags
- UTF-16 decoder (and the other character codings should work too)
- tons of comments
Maybe not that much done, but it was a hard job to get this far. ID3v2 isn't of the easiest formats... I guess its only popular because WinAmp uses it. Oh well, the hardest part is done. Now it needs only some fixing so that it is 100% standard compliant... it reads most tags just fine.
If you find a problematic song, please let me know.
He also needs to edit the code so that it would work (the code has set all functions to Private! not accessible outside the class!), remove the parts that don't work (Pitch and SetVolume for the least), remove the unused API commands (GetShortPathName, SendMessage, ReleaseCapture, SetWindowPos), remove the unused constants, edit the file opening so that instead of using shortpathname API (because it doesn't work) it uses Chr(34) & Filename & Chr(34)...
Umm... Am I going too far with listing what is wrong with the code...? I just hate code that doesn't work. There is too much of it in this world. Back to fixing mine.
Merri, you are my hero. I've been trying to figure out V2 tags for 2 months now.
Few comments:
The button with the ellipsis on it should probably say something like "Browse for MP3".
Once a file is selected there, why not open it immediately on return from the common dialog? By "Open" I mean, read & display the tag info.
Why an "Open" button? This seems to start playing (I don't have speakers on this PC). Shouldn't the "Play" button do that?
Why a "Close" button?
Wouldn't hurt to use the ToolTipText to add some help.
Will you be adding V2 tag editing?
Thanks and Happy New Year to all. Looking forward to the next release. DaveBo
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
Sorry, I'm not concentrating to the actual program. I wanted to make it more clear how many different commands there are to play files. Like, play-button could be also the pause/resume button... but since these are three different commands, I wanted to point it out visually. It is a sample program and I'm concentrating on the Class Module itself.
V2 editing is coming once I've fixed some things. I've already fixed an error in ID3v1 loading plus I've fixed some other things... atm I'm working CRC-32 support, since it is possible there is a file with CRC-32 checking. Now if I happened to have a CRC-32 enabled file, I'd be super-happy. I just have to make the support in theory... in the other hand, I gotta do a lot of things to be working in theory.
Here I come again with an another update. I made the ID3v2 reading support more complete, now it reads almost any ID3v2 enabled file (the only thing missing is reading of synchronized frame data, which I probably leave unimplemented - it would be a pain to reformat the code now).
- added CRC-32 support
- made error detection more complete: you now know where the error comes from
- possible to get header information
- fixed two-three stupid bugs (not sure if all of them were in the last version)
- even more comments!
- did I have UTF-16 support in the last version? Anyways, it is there now
Once again, enjoy! I think I'm now ready to go on with ID3v2 writing
I am learning a thing or two if it means anything to you. I got a question though, whats the purpose of adding the common dialog box?
This topic is fine. If it wasn' t for more people posting I would say yeah, make a new one. As it is, people are aware of the updates so you dont really have to. Ultimatly it is up to you though, if you wish to show everyone on this board what you have done I have no problem with that
I use Common Dialog Box to show the file opening dialog. It was the easiest way to do it. It can open only one file at a time though. I have a module that lets open multiple files at a time, showing the exactly same Dialog, but I didn't want to use it in this example. Wanted to keep it as simple as possible.
Yet, I'm planning on making a more complex sample program, since ID3v2 is complex... and there is no way going around it. Maybe I make multiple sample programs on different possibilities of the Class Module (one as a simple MP3 player with ID3v1 view and a ID3v2 file browser or something like that).
what about scrolling text inside a textbox? would I just do
VB Code:
Private Sub Timer1_Timer()
Filename.Left = Filename.Left - 50
If Filename.Left <= -2160 Then Filename.Left = Filename.Left + 50
If Filename.Left >= 1920 Then Filename.Left = Filename.Left - 50
End Sub
I just made it so that instead of the text moving inside the box, the whole textbox moves. I just made a frame to put it in so it doesn't overlap the other things and it looks cool
Last edited by SandmanSamR; Dec 30th, 2003 at 08:03 PM.