1 Attachment(s)
MediaControl: Play audio and video files, easy!
I have made a nice module to simplify the playback of audio and video files in VB.NET.
It uses the mciSendString method for playback, which is the same method Windows Media Player uses, so you will be able to play all the files that Media Player does.
The zip-file contains a sample project which shows the functions of the module. The module is commented and also contains help information.
If you find a problem, please tell me so in a reply to this post or by email.
Have fun!
UPDATE: Changed a few things. Now the module works for VB .NET 2005 as well.
Re: MediaControl: Play audio and video files, easy!
hello, i really like your program as i'm having a few problems installing visual studeo full edition, i installed a partial edition for my vb class, then decided to buy a full one since i couldn't use directx on the partial version, i unistalled it, installed the new one and couldn't enter a new serial key, know i have a hybrid i don't know what, but that's not the point this is just kind of ticking me off right know. So your little program was a life saver, but i do ahve one problem, would it be possible to play .mpg format movies it plays .avi fine but when i try an .mpg movie i get this error message
An unhandled exception of type 'System.NullReferenceException' occurred in MediaControl.exe
Additional information: Object reference not set to an instance of an object.
and it occurs on line 157, normally i'd try to fix it on my own, but i've never really been into movie/music playing and more an amiture at vb, so i'd probibly only screw this program up if i tried. i'm guessing it is because mpg/mpeg files require the codec, but i have the codec, is there a way to make the player use the codec for thes files and otehr files like them (ps, sjut a wild stab)? thanks for the help, john
Re: MediaControl: Play audio and video files, easy!
This problem should not occur. And playing mpeg files works fine for me.
It's especially strange that it'll work for avi files, but not for mpeg files.
I have four questions for you:
- Are you using the sample program, without having changed it? (If not, use the original program and try again)
- Is the mpg file playing in Windows Media Player? (If not, then the file is corrupted or you can't play mpg files)
- Is the file on a normal local drive, not on a network or online drive? (If not, then place your file on a local drive and try again, networking and streaming is not supported)
- Are you using Visual Basic .NET 2003? (If not, then the module may be incompatible with 2002 or 2005 [EDIT: It is now compatible with VB .NET 2005], I don't know)
If all the answers to the questions are yes and it still doesn't work, then I don't really know what the problem is. It may be to do with the window handle, so you could try this: change the code in frmSample.vb for the open button, from pic.Handle.ToString() to Me.Handle.ToString() and see if it'll play then. It should then play on the form, not in the picture box.
Please tell me your findings.
By the way, the player uses the default codecs installed for each filetype, so that shouldn't be the problem.
Re: MediaControl: Play audio and video files, easy!
well, it plays .wma, .mps, .avi, and to answer al your questions i'm a go, i'm thinking it's probibly somthing on my comptuer, but i'm going to ahve one of my friends with the same visual studio .net 2003 edition that we got from our vb class run it, see if it works there, if it does not then i know it's this stupid partial edition that came with the books, but i don't think it is. although they run fine in windows media player, i'm thinking that the codec may be corrupt, but i'll wait until my friend trys it before jumping to conclusions, I'll get back to you shortly, well probibly not for about 2 days witht eh results and a solution if i ahve one, still even if i can't use .mpg files a great program, i love how it works, thanks again john
Re: MediaControl: Play audio and video files, easy!
Nice program.. but it dous not play wma here..
I'm getting an error: error 277 - er is een probleem bij het initialiseren van MCI
Re: MediaControl: Play audio and video files, easy!
Thank you for code ,Sir :thumb:
How i can play the URL like Winamp? :ehh:
Re: MediaControl: Play audio and video files, easy!
Hi, do you have any version for Pocket PC ? I am interested, thank you.
Re: MediaControl: Play audio and video files, easy!
Quote:
Originally Posted by the_rpd
Nice program.. but it dous not play wma here..
I'm getting an error: error 277 - er is een probleem bij het initialiseren van MCI
Firstly, sorry for the late reply.
Now, in order to be able to help you, I would like to know a few things:
- Do(es) the file(s) play in MediaPlayer?
- What version of Windows do you use?
- What is the full path of the file(s)?
- Do you have a Dutch version of Windows, or did my Dutch version somehow make all errors display in Dutch?
P.S. From now on I will reply to posts faster, I am now subscribed to this thread.
Re: MediaControl: Play audio and video files, easy!
Quote:
Originally Posted by antitrusty
Thank you for code ,Sir :thumb:
How i can play the URL like Winamp? :ehh:
The module does not support playing online files. Sorry.
Re: MediaControl: Play audio and video files, easy!
Quote:
Originally Posted by Winder
Hi, do you have any version for Pocket PC ? I am interested, thank you.
I know nothing about Pocket PCs, so I won't be able to help you a lot. But I found on MSDN that Pocket PCs send the filename to the MCI-device in a different way.
Replacing the code from the mediaOpen-function with the code below should work:
VB Code:
If NoAlias() Then Exit Sub
If Not IO.File.Exists(Filename) = "" Then
mediaErrorCode = 1003
mediaErrorInfo = "File does not exist."
Exit Sub
End If
Dim iReturn As Integer
If ObjectHandle = Nothing Then
iReturn = mciSendString("open """ & Filename & _
""" type mpegvideo alias " & sAlias, "", 0, 0)
Else
iReturn = mciSendString("open """ & Filename & _
""" type mpegvideo alias " & sAlias & " parent " & _
ObjectHandle & " style child", "", 0, ObjectHandle)
End If
If iReturn Then GetError(iReturn) : Exit Sub
iReturn = mciSendString("set " & sAlias & " time format milliseconds", "", 0, 0)
If iReturn Then GetError(iReturn) : Exit Sub
mediaErrorCode = 0
mediaErrorInfo = Nothing
If it doesn't work, first try to solve the problem yourself, then try searching MSDN on "Pocket PC" and "mciSendString" for a solution as I really can't help you a lot.
Re: MediaControl: Play audio and video files, easy!
This line of codes has an error.
mediaOpen(txtFile.Text, pic.Handle.ToString())
handles is not a member... blar blar blar..
Re: MediaControl: Play audio and video files, easy!
You can use the handle to play a video in almost any control.
Is there a control with a handle-property for Pocket PC?
If not, try removing the ", pic.Handle.ToString()"-part of the command. It should then play in a new window.
Re: MediaControl: Play audio and video files, easy!
It works quite nicely for me. I have found 2 small issues:
1) Play a WMV file until the end. Then click play again. The movie doesn't play again. There's no way to rewind and start playing again.
2) You need a finished event - something to allow the programmer to know that the movie is done playing.
Re: MediaControl: Play audio and video files, easy!