Belisario93

Alright, I'm back, just like I said I would be. This time, it isn't about the to-do list for my browser. This time around, it is about something more complicated, a media player. If possible I want it to play as many file types as possible, but if I have to I will stick with just .WMA or MP3. There was a tutorial about this in the "how do I" section in visual basic, but at the "creating the user interface" section of the tutorial message boxes come up saying that the "WithEvents keyword isn't valid". If anyone could help me past this point in the tutorial or give me a new way to do this then that would be helpful.
The link to the tutorial is here: http://msdn2.microsoft.com/en-us/library/ms345151.aspx



Re: Visual Basic Express Edition Need help making a media player

Dave299

That is a very long article. It would help if you could be more specific about where you get the error message.





Re: Visual Basic Express Edition Need help making a media player

Belisario93

i got it in the "creating the user interface" section where it says to make a module level variable with the keyword WithEvents. heres a quote from that point in the tutorial:
"While the Visual Basic Express toolbox is rich with wonderful components and controls, old and new, there doesn't appear to be one that plays MP3 files. The new SoundPlayer component only supports WAV files. If possible, I wanted to avoid P/Invoke. A little research and I found what I wanted: the managed DirectX libraries provide an Audio class that lives in the Microsoft.DirectX.AudioVideoPlayback.dll assembly. This class supports MP3, WMA, and other audio file types. The Audio class has two overloaded constructors. One takes a file name to an audio file; the other adds a Boolean value to specify that the file should begin playing once opened. In addition, there are two shared members for opening a file. The FromFile() method duplicates the behavior of the instance constructor that doesn't auto-play the file. The FromURL()

method supports running the file from an HTTP stream.

For the application, create a module level variable using the WithEvents keyword. The Audio class exposes Stopping and Pausing events (as well as a few others) that the application will use to keep the UI in sync. The Play File button uses the Open File dialog component to enable the user to browse for an MP3 file. Once the file has been selected, the MP3 metadata is parsed, and the song begins to play. Below are the core routines to define the audio instance, pick a file, and then play the file:"


When it said that the keyword wasn't valid (or something like that, it didn't like the keyword name) i just ignored it and kept going til i got to the part called "Working with the database", where i couldnt find out where to put the code. If you could help it would be very useful. Heck, if you could tell me how to use the SoundPlayer component so that it could let the user use their own media files i would be happy enough and be able to move to the next on my list of features to add on the browser (don't worry i won't have to ask how to do all the rest of the stuff on there, just about most of em).






Re: Visual Basic Express Edition Need help making a media player

js06

If you do a search in the forum here for - MP3 you will find many examples on using directx

directx will allow you to play most media types as you know so you won't be limited to wav files as with soundplayer

You can also use directx to play video as well

anyway search and you will find plenty here






Re: Visual Basic Express Edition Need help making a media player

Belisario93

I couldn't find anything useful so i guess I'll just cut the media player idea . I'm pretty new to all this programming so i don't know where to put half the code that the answerers are giving. Well, I guess I'm off to do the other features.





Re: Visual Basic Express Edition Need help making a media player

js06

This will get you started on the directx

Make sure you add the .net references with the following imports names

project menu - add reference - .net tab

Imports Microsoft.DirectX

Imports Microsoft.DirectX.AudioVideoPlayback

Public Class Form1

Dim song As Audio

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

song.Play()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim openDLG As OpenFileDialog = New OpenFileDialog

openDLG.Filter = _

"Audio Media (*.mid, *.mp3, *.wav, *.wma|*.mid;*.mp3;*.wav;*.wma"

If openDLG.ShowDialog = Windows.Forms.DialogResult.OK Then

song = New Audio(openDLG.FileName, False)

End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

song.Stop()

End Sub

End Class

Play around with it

to see the other methods type - song. and then you will see intellisense pop up






Re: Visual Basic Express Edition Need help making a media player

Belisario93

There's just one problem, there isn't a microsoft.directx or a microsoft.directx.audiovideoplayback in the .net tab...





Re: Visual Basic Express Edition Need help making a media player

js06

Ok, you need to download the directx sdk from microsoft

http://msdn2.microsoft.com/en-us/xna/aa937788.aspx




Re: Visual Basic Express Edition Need help making a media player

Dave299

I think trying to make a DirectX media player may be a little ambitious at this stage.

If you just want a simple application that will play media files why not make one with Windows Media Player embedded in your application.

If it is not in your toolbox already right click on the toolbox and choose Select Items. In the next window click on Com Components and when the list eventually loads scroll down and tick Windows Media Player then click OK

This will put the Windows Media Player into your toolbox.

Drag it to your form and call it WMP. Also add a button to the form.

Add the following code, or something similar:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

WMP.URL = "d:\temp\test1.mp3"

WMP.Ctlcontrols.play()

End Sub

and you have a media player.





Re: Visual Basic Express Edition Need help making a media player

Belisario93

Dave, i think I'll go in your direction. The only problem is how do I make it so that the user can select their own music files





Re: Visual Basic Express Edition Need help making a media player

Dave299

Music files are no different to any other files so you could select them with an OpenFileDialog box.

How would you like the user to be able to select them





Re: Visual Basic Express Edition Need help making a media player

Belisario93

Well, I was thinking of making it so that after the user selects it from the file that it would be able to be selected from a listbox that saves when the user closes the control (i think i can get the saving part down, depending on the method of saving it). I also want it so that the songs that are listed in the list box can be played if they are selected.





Re: Visual Basic Express Edition Need help making a media player

js06

This is why i stay away from media player component

http://www.microsoft.com/windows/windowsmedia/licensing/licensing.aspx

In order for you to legally distribute your finished program with the component you have to enter into an agreement with microsoft with an advance payment of $10,000 which is a downpayment on your royalty fees

Why spend all that time learning and using WMP just to get into a legal problem with microsoft

And don't think that just because you are a nobody in terms of software that they won't come after you.

They have to becasue if they let one do it, then another will, then another will. They can't afford that.

And i know what you are thinking, how will they know

Well they already know who you are and they see what you do here in the forum.

Save yourself the worry and use something without the hassles.

Unless you plan on signing an agreement, then have at it.

Anyway just a fair warning to you.

Take it for what it's worth






Re: Visual Basic Express Edition Need help making a media player

Dave299

How are the files stored and named, e.g. is there a directory for each artist or each album. Does the file name include artist name, album name, track name etc.





Re: Visual Basic Express Edition Need help making a media player

Belisario93

*igonores js' post for just a second* dave, I think it depends on the user, but most of the time the track name is the file's name and there is a directory for the artist, then the album. heres a tree diagram if u need it:
C:
Documents and settings
user
my documents
My music
artist name
album name
Trackname.wma
Ok, and now for Js' post, ummmmm, your method is too complicated for me so i'll just have the program for only my family and friend's use until i can find a way to use the very complex method you gave me (i'm pretty sure that wouldn't get me in trouble), and actually, doesn't that only apply to those selling the application cuz if i can i'm gonna have this program be a freeware on the web pretty much.