Important alert: (current site time 7/15/2013 9:09:09 AM EDT)
 

winzip icon

ApiVideo

Email
Submitted on: 10/6/2005 5:51:50 PM
By: SpaceMonkey 
Level: Advanced
User Rating: By 27 Users
Compatibility: VB.NET
Views: 22707
 
     At one point or another, we all come in contact with a project where we need (or want) to play media files. There are 2 main ways you can go about this, you can either use the MS MediaPlayer control and deal with interop and alot of issues. Or you can implement mci using the API. This project is an implementation of the mciSendString API, so you can just include the class into your project and use it on your form, no need to reference Media Player. This plays all know formats (mp3, mpeg, avi, wmv, divx,...) except midi files and cda (audio cd's). (the play statement, and maybe other statements as well, use arguments not supported by the midi and cda devices) The code is well documented and very clear, even a beginner will find it's way in it. Please leave a comment, and do vote if you like it. Thanks !!

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
10/6/2005 6:22:20 PMThorben Linneweber

or you can use directX
(If this comment was disrespectful, please report it.)

 
10/6/2005 7:04:17 PMSpaceMonkey

I never worked with directX (yet) but I imagen it being more work (and harder) to implement than this.
(If this comment was disrespectful, please report it.)

 
10/7/2005 8:11:00 AMVBHelp

Nice running example, works fine. I havent been using .net long enough to know if there's a better way of doing this or not but wanted stay it does work great.
(If this comment was disrespectful, please report it.)

 
10/7/2005 10:26:42 AMK-Code

i gonna give you five for this it's really great so i can use my own UI instead MMP UI,and do you know how to get the frames from a movie so i can put it as wallpaper for example?please if you know email me at ncstrike@hotmail.com
(If this comment was disrespectful, please report it.)

 
10/8/2005 1:45:53 PManthony

Very nice i give it a 5.
Would like to take this and make it show two videos that play along the same timeline, for instance. a regular video with a small video (no sound) of a person translating 1st video in sign language.
(If this comment was disrespectful, please report it.)

 
11/15/2005 4:52:27 AMOlivier

Hello, nice code but... some movie plays too fast... do you know why ?
(If this comment was disrespectful, please report it.)

 
11/15/2005 1:47:35 PMSpaceMonkey

Olivier, are you sure you didn't change the speed trackbar ? Also try playing them with MS Mediaplayer to check if it isn't a problem with the file itself.
(If this comment was disrespectful, please report it.)

 
11/18/2005 4:21:02 AMOlivier

Hello Spacemonkey,
the speed trackbar... lol :)
No in fact my script launch the open command with mpeg in place of avi...
(If this comment was disrespectful, please report it.)

 
11/25/2005 9:52:11 AMPertuman

Excellent class, but I need to play one list of video. Want i do this?
Thank.
(If this comment was disrespectful, please report it.)

 
11/25/2005 1:18:53 PMSpaceMonkey

Pertuman, use the OnEnd event to know when playing ends, then close the current file, open the next one in the list, and start playing that one. Make sure you don't have Repeat on. (To repeat start playing the first file in the list in the OnEnd event of the last file)
(If this comment was disrespectful, please report it.)

 
11/25/2005 5:27:30 PMPertuman

Thank SpaceMonkey, the class is great.


(If this comment was disrespectful, please report it.)

 
11/28/2005 1:34:03 PMAndicioz

This is really an excellent code man. Keep up the good work!
(If this comment was disrespectful, please report it.)

 
12/30/2005 1:35:04 AMSantosh

Very Good
(If this comment was disrespectful, please report it.)

 
3/4/2006 1:20:49 AMHermit

can u please explain me the coding of your project i am using it for my project work . so can u please explain me in details . mail me on my ID hermit85a@gmail.com
(If this comment was disrespectful, please report it.)

 
3/4/2006 7:14:46 AMSpaceMonkey

Hermit, explain you what ?

Just look at the source code...
It is very well structured and has sufficient comments...

If there are any functions in the code that you don't know look them up on www.msdn.com or just google for them.


(If this comment was disrespectful, please report it.)

 
3/18/2006 1:22:29 PMJoni

Excellent job I would rate. I refered some of the codes into my current project. But i'm having some problems with Karaoke MPEG1 file. I couldn't switch the channel (vocal or music). I wonder if I can do it like the default Microsoft MPEG1 Properties which can change the channel to FIRST, SECOND, or BOTH. I've tried "setaudio movie1 source to left", but it only works with certain hardware. In my case, My AC97 works but not my Intel SOUNDMAX. I hope I could get some enlightement here. Thanks.
(If this comment was disrespectful, please report it.)

 
3/22/2006 11:43:31 AMJoni

Hi,


I've found the answer for switching the channel. It's exactly "setaudio @alias source to {left, right, average, stereo}" The problem which I got last time was caused by Sonic MyDvd Ligos Mpeg Splitter and Ligos Mpeg Audio. I found Ligos Mpeg Audio is the culprit when I use DirectX utils => GraphEdit to view the filters. The Ligos Mpeg Audio cannot switch the channel as what default microsoft Mpeg filter do. After I unregister the filter: regsvr32 -u the filter name, everything is back to normal and my player is completed.
(If this comment was disrespectful, please report it.)

 
4/7/2006 2:24:01 PMSpaceMonkey

If you have questions, post them as comment here, don't use the feeback link, I don't reply on mail, but I do monitor comments...

Bati, in case you come back here...

Does the project, as posted here, play unexpected, in full screen, on your second monitor as well ? If not, then it must be some of your modifications...

I can't reproduce your problem on my dual monitor system.


(If this comment was disrespectful, please report it.)

 
4/17/2006 3:13:31 AMRavi Ranjan Sharma

Fentastic coding

(If this comment was disrespectful, please report it.)

 
7/23/2006 1:55:47 PMAbhinavChadda

hey...excellent piece of code... one issue though... when i used it in my project it is not showing in the panel it is supposed to show but on the windows explorer window (which is open in the background) on the same location... ne idea as to y is this happeneing...

P.S: it works if i try to use it on a blank form but doesnt on the current project...
(If this comment was disrespectful, please report it.)

 
8/10/2006 2:06:29 PMYµR0kewL

Great work - HOWDY !
(If this comment was disrespectful, please report it.)

 
10/14/2006 1:03:04 PMmehrtash

i want to load a mpeg file in ram
(binary array) and then play it
what should i do ?
who can help me?
(If this comment was disrespectful, please report it.)

 
11/20/2006 5:10:45 AMSriram Prasad

Very nice code.

working perfectly..

I would like to is it possible to create playlist from this code...

Please post here...
(If this comment was disrespectful, please report it.)

 
11/20/2006 5:21:39 AMSpaceMonkey

Yes you can add a playlist feature, look at my comment from "11/25/2005 1:18:53 PM" it explains how to use the OnEnd event for this...
(If this comment was disrespectful, please report it.)

 
12/19/2006 6:50:02 AMSriram Prasad

Very nice piece of work. great. but when i tried this sample application in windows 2000, it not working and reporting a error MCIERR_INTERNAL. What could be reason for this. can be explain me the way sort out this problem
(If this comment was disrespectful, please report it.)

 
12/19/2006 4:52:47 PMSpaceMonkey

Sriram Prasad, this code was originally written on a W2K system... dunno what the reason for your problem might be... can be any number of things related to hardware, drivers, software or the operating system...

(If this comment was disrespectful, please report it.)

 
4/18/2007 12:46:27 PMWasim Bashir

Thanks for your great work, the program is excellant. If I wanted to have the play button so that when the user clicks the button an embedded video will play automatically, what is the coding for that?. This is so that I can take out the Open button just to restrict the user to one video.

I thought it would be something like MyApiVideo.Play = ("wave.wav").

Thanks in advanced.

Regards
Wasim Bashir
(If this comment was disrespectful, please report it.)

 
4/18/2007 5:49:16 PMSpaceMonkey

Wasim,

I think you would need to embed the file as a resource, and then maybe extract it to the users temp folder just before playing...

Don't think you can play it from a resource directly...

.NET has classes to work with resources, I'm sure you can find tons of examples on how to embed a file at design time and then extract it at runtime...

If you only want to play a wav file, check out the PlaySound api, that might be better in your case... less overhead and might even play the file from the resource directly, never tried that with .NET...

If you get the PlaySound api working to play from the resource directly, make it a pscode article if it isn't already one :o) (feel free to post a link to that in this thread, might be useful to others as well)
(If this comment was disrespectful, please report it.)

 
4/19/2007 4:40:44 PMWasim Bashir

R4egarding the embedded video, under the play button add
MyApiVideo.Open = ("wave.wav").
MyApiVideo.play

And make sure the video file is located in the "bin" folder.
(If this comment was disrespectful, please report it.)

 
6/1/2007 6:51:36 PMaddythemaddy

hey buddy..thats great work...just keep up the good work
(If this comment was disrespectful, please report it.)

 
10/2/2007 7:54:16 AMLuke Vear

Hello SpaceMonkey,

I was taking a look at your 'ApiVideo' application and was wondering if I could modify it around abit (like add a more interesting look to it as well as adding support for Windows Aero). If I am permitted too could you please reply to me. If not please email me saying so anyway.

Thanks in advance!
(If this comment was disrespectful, please report it.)

 
10/3/2007 1:19:00 PMSpaceMonkey

Luke,

Feel free to use this code in any way you feel fit... I posted it here to help others save some time.

Good luck with your project.
(If this comment was disrespectful, please report it.)

 
2/19/2008 2:32:36 PMRicky

Hi, I feel I should comment.

This has taught me a lot and it's very well coded, so thank you very much :)

There is only one slight glitch I have found. Some songs, the total time reads wrong. For instance, I have a song, 3:21 seconds, the total time displays 7:34 or something similiar. The trackbar value is wrong because of this, though the song does cut off at the right place? Only on a few songs, and it's nothing to do with the speed and I have checked in other players to make sure the files are fine (which the are). Still, I've been changing/adding bits for a while now, thankyou for posting. :)
(If this comment was disrespectful, please report it.)

 
2/19/2008 4:24:52 PMSpaceMonkey

Thanks Ricky for your feedback, I appreciate it.

I been using a player based on this code (it's a dual monitor thing where the movie is played on my TV and I control the thing using an old serial [RS232] mouse :o) for a while now, and it does indeed not play all media as flawlessly as Microsoft Media Player, but it serves my needs. Feel free to build on it and where needed improve it and maybe even post your version here on pscode...
(If this comment was disrespectful, please report it.)

 
2/23/2008 2:10:25 PMguideX

Well done!
(If this comment was disrespectful, please report it.)

 
2/24/2008 10:54:23 AMRicky

Hi again,

I have it nearly working flawlessly now. It displays the total time correctly and will always play the song right to the end without any problems with the scroll bar. However, when playing a song then using the scroll bar to jump through the song the format is changed, so the bar finishes yet the song continues (if you understand me). So, I see there is a "TimeFormat" that I'll be needing to play with :)

I may post the version up once I'm done, I have added a few things, such as a 'random' feature, allowing it to sit in the taskbar, saving tracklists and loading tracklists etc. :)
(If this comment was disrespectful, please report it.)

 
5/28/2008 7:15:49 PMTimo Böhme

Hi SpaceMonkey. You will get 5* from me. I have a big question about the result image. I will save some frames of the video as Bitmap and play the video in a second Picturebox. How to get access to the single frame?
wg__@hotmail.com
(If this comment was disrespectful, please report it.)

 
6/16/2008 5:51:19 PMAndre

This is fantastic! Excellent work.
(If this comment was disrespectful, please report it.)

 
9/1/2008 10:47:51 AMClay

Will this play MP3 audio files with no UI displayed?

Is this code dependent on any other components/libraries being installed?
If not, does it use an MP3 decoder? If so, would I need to install that MP3 decoder?
(If this comment was disrespectful, please report it.)

 
10/30/2008 6:06:31 AMrio711phil

This coding is really cool but it plays fast on my other .avi files and no sound at all, maybe theres a conflict on a codec or something! what do you think...? if I figured this out I'll let you know guys...
(If this comment was disrespectful, please report it.)

 
6/16/2009 10:57:08 AMNader Naderi

Hello,

Your code is nice. Thank you for sharing this with us, How about 2 instance in a form? I tested this, but it didn't work. At the same time, only one player works. What is the problem? in my code i need two players.

Regards,

Nader
(If this comment was disrespectful, please report it.)

 
6/18/2009 10:34:49 AMSpaceMonkey

Hi Nader,

I tried it on my system and it works... both using a different parent on the same form or playing two clips on the same parent. Playing them directly on the form seems no problem either.

Have you set the size and location correctly. And are they in a different location?

Is the code controlling the players correct?


(If this comment was disrespectful, please report it.)

 
10/6/2009 10:52:14 AMali noroozi

ir your program is not here please connect with my emile address and and I need your corporation Now ,Thanks
(If this comment was disrespectful, please report it.)

 
10/8/2009 9:19:32 AMSpaceMonkey

Hi Ali,

Thanks for your interest in this project. I'm happy it still draws people in after all this time.

I have tried the zip and the dowload works, just click "download code".

Don't click on the buttons in the screenshot, this is not a webapplication :o)

Regards
(If this comment was disrespectful, please report it.)

 
6/3/2010 12:53:54 PMMark Kintigh

Excellent code -- 5 * from me.

Got a question though, can you control the size of the buffer for the video? I'm having buffer issues running an AVI from a DVD -- it goes along playing OK then, after accessing the DVD again, jumps up in the video however long it took to read the file.
(If this comment was disrespectful, please report it.)

 
4/24/2011 11:45:27 AMjefferson

this is cool. i did somethine like this in VB6
(If this comment was disrespectful, please report it.)

 
6/12/2011 7:28:44 AMNavdeep Singh

excellent code, How can i play hd avi videos? can u help.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.