How-to Playback Movies and Videos with VB and Visual Basic .NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (25 votes, average: 4.12 out of 5)
 

As you will see, playing videos is easy using the Windows MCI Command interface for the playback which is supported in Windows XP, Windows Vista, Windows 7, Windows 8, and Windows 10. Specifically the MCISendString function will be used in this tutorial.

MCI should by default already support the common formats like avi, mpg, mpeg, wmv, etc. with a basic Windows installation. But you can actually get MCI to playback nearly all formats if the correct Codec/Driver is installed. For Example, you can playback Apple QuickTime .Mov, MPEG 4 DivX, or H.264 .MP4 by simply installing the codec for each format. After that just program the device like you normally would.

This article is only to show how to do basic playback of videos and not features like duration/length, position, or resizing the video. You can check out my MCI MultiMedia Tutorial to learn how to program MCI and add your own features.

If your using VB 6.0 select the correct MCISendString declare below, change any IntPtr.Zero code to 0, and use ‘.hWnd’ instead of ‘.Handle’.

Edit: 2014, December 17th: I decided to make a download available that uses all of the codes in this article with a couple extras to help resizing and such. I also changed some of the code in the program for Option Explicit.

Download Example: Click Here

View Screenshot: Click Here


Visual Basic 6.0 and Older

    'The Main API call that will be used for the playback.
    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

 

Visual Basic.NET and Newer

    'The Main API call that will be used for the playback.
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal _
        lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As _
            Integer, ByVal hwndCallback As IntPtr) As Integer

 

OR You Can Use…

    'The main API call.
    <DllImport("winmm.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Public Shared Function mciSendString(commandString As String, returnString As String, _
        returnStringLength As Integer, _mciCallback As IntPtr) As Int32
    End Function

Now make a couple variables.

    'Will hold the path to the movie file.
    Dim filename As String

    'Holds the return value of mciSendstring. Not used for anything in this article though.
    Dim retVal As Integer

 

Then set a path to the file you want to play. If you’ve seen my other MCI articles you should remember about adding “Quotes” around the path and filename, or at least supply the file’s short pathname.

        'The path to the movie or video to play.
        filename = "c:\movies\MyMovieFile.mp4"

        'Now add the quotes around the path.
        filename = Chr(34) & filename & Chr(34)

Next thing to do is open and setup a playback device. I usually use the MPEGVideo device since it works with audio and video. The MPEGVideo device is DirectShow down under.

There are a couple ways you can open the video. You can have it display in its own popup window or have it displayed in a control like a Panel or Frame. Basically any control with a .hWnd or .Handle property.

This command will display open a new device and have the video display in a control window.

'This code below will open a new mpegvideo device and play the movie in the “movieWindow” control which is
'nothing more than a GroupBox/Frame control I used in an example app. Basically any control with a
'handle can be used. For VB 6 you would use the controls .hWnd property instead of the
'Handle.ToInt32 property.
'If you want MCI to select which device to use just take out "type mpegvideo" from the code.

retVal = mciSendString("open " & filename & " type mpegvideo alias myMovie parent " _
& movieWindow.Handle.ToInt32 & " style child", vbNullString, 0, IntPtr.Zero)

 

If you want the video to open in a separate window use this code instead.

'Specify the mpegvideo driver to play the movies which should play most movie formats without any problems.
'This code will have the video open in its Own window and the alias name will be “myMovie”.
If you want MCI to select which device to use just take out "type mpegvideo" from the code.

retVal = mciSendString("open " & filename & " type mpegvideo alias myMovie", vbNullString, 0, IntPtr.Zero)

OK, now that you’ve opened a device, all you have to do is call the Play command to begin playback. The codes below will Play, Stop, Pause, and Resume.

Play

 '
 'Start Playing the movie once you’ve setup the device with your file.
 retVal = mciSendString("play myMovie", vbNullString, 0, IntPtr.Zero)

 

Stop


'Will Stop the playback if its currently playing.
 retVal = mciSendString("stop myMovie", vbNullString, 0, IntPtr.Zero)

 

Pause


'Will Pause the playback if its playing.
 retVal = mciSendString("pause myMovie", vbNullString, 0, IntPtr.Zero)

 

Resume


'Will Resume the playback if it has been paused.
retVal = mciSendString("resume myMovie", vbNullString, 0, IntPtr.Zero)

 

You want to use this code when your done with your device and/or closing your program so the mci resources will be cleaned up. You could change ‘close myMovie’ and put ‘close all’ to free everything MCI has used.

        'Will make sure the previous alias is destroyed. If the alias “myMovie” hasn’t been created yet,
        'this code will NOT cause any errors or anything. So there is no need to worry about that.
        retVal = mciSendString("close myMmovie", vbNullString, 0, IntPtr.Zero)

Well, that’s all there is to it. Hope you found something useful from this article. Have Fun!

Jason

Revised: 2015

94 thoughts on “How-to Playback Movies and Videos with VB and Visual Basic .NET

  1. Jorg

    thanks for your information. playing musicfiles works fine, playback videos (.mpg, .mwv) doesn’t work. the mci-driver installed on my pc is mciqtz32.dll. all entries in the two registries (…\MCI32 and …\MCIExtensions) are set correct to MPEGVideo. Does anyone have an idea, what’s going wrong?

    Reply
  2. etix

    PERFECT TUTORIAL!!

    I use this for my old pc which does not have many system capacities. This is a simple, nice and fast movieplayer!!

    THANKSSS!!!

    Reply
  3. Jared

    does anyone know how to maximize the video? I’ve been trying for a while and can’t seem to get it to maximize.

    (basically fullscree (without borders would be nice)

    Reply
  4. Bergstad

    I have made this code in VB 6.0:

    Option Explicit

    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
    Dim filename As String, retVal As Long

    Private Sub Spillknapp_Click()
    filename = “D:\skole\infag\INF2\program\tull.mov”
    filename = Chr(34) & filename & Chr(34)
    retVal = mciSendString(“open ” & filename & ” type mpegvideo alias movie”, 0, 0, 0)
    retVal = mciSendString(“play movie”, 0, 0, 0)
    Refresh
    End Sub

    The trouble is that the video is only played the first time you click on the button! Afterwards a static picture is shown. How to deal with it Jason?

    EDITED BY JASON:

    Hi, it sounds like you need to restart the movie back to the beginning. Check out the code below on how to do that….

    retVal = mciSendString(“seek movie to start”, 0, 0, 0)

    Just remember to set ‘movie’ to whatever alias you are using.

    Take care, Jason

    Reply
  5. Hdd

    How can I fit the video into a picture box. Currently, it’s played at 100% size, meaning if my form is not big enough, part of the video is cropped.

    Reply
  6. Jason Post author

    Hi, I will go ahead and give you some sizing info.

    If using VB 6.0, then check out this download link: http://www.vbcodesource.info/downloads/moviemodule126.zip ; and look for the location/resize function.

    If using .net check under the .net controls section of the same vbcodesource.com website for csMovieLibrary.

    Either ways, below is some quick code to locate and size the movie in whatever child window you are using.

    —————–

    retVal = mciSendString(“put movie window at ” & leftPos & ” ” & top & ” ” & Width & ” ” & _
    Height, 0, 0, 0)

    —————–

    That code above should work. Just change ‘movie’ to whatever device alias you are using. Be sure to create the leftPos, top, width, and height as integer based variables (Long if using VB 5 or 6).

    Also, if you only want to change the position of the movie but not resize it, then just set height and width to “0”.

    Check out my vbcodesource.com site for more info and the libraries/modules for many more codes on mciSendString. 🙂

    Jason

    Reply
  7. sebastian

    how can i select the video card ouput on a case have 2 video cards?
    card #1 .. onboard .. for preview videos ( 30 segs, no more)
    card #2 … Nvidia card for play videos

    thanks

    Reply
  8. Jason Post author

    Hi Jeff, you can use the Play From and/or Seek To command to move forwards or backwards.

    The value to play from/seek to is based on a milli-second value.

    What you want to do is get the current position the media is at in a milli-seconds value. If you want to move forward by 5 seconds then simply add 5000ms to the current position.

    Example: If the media is currently at 20 seconds and you want to advance by 5 seconds then the new value would be:

    currentPosition = 20000

    newPosition = currentPosition + 5000

    Then pass that position value to the play from/seek to command.

    If the audio is playing then use the: play From command.

    —————

    retVal = mciSendString(“set movie time format ms”, 0, 0, 0)

    retVal = mciSendString(“play movie from ” & newPosition, 0, 0, 0)

    ————–

    If the audio is not playing then use the same code above but instead of Play From you want to use the: Seek To command.

    Hope this helps 🙂

    Jason

    Reply
  9. Jeff

    ok thanck but how will i be able to set the currentposition to the position i am currently at- intead of 20 seconds in?

    Reply
  10. Jason Post author

    It would probably help you if you check out the mci tutorial at this link: http://www.vbcodesource.info/?p=155

    That way you can program and add the mci features you want for yourself.

    Anyways, you will want to use the “status” command while passing the ‘position’ flag.

    ————-

    Dim retData as string = Space(128)

    retVal = mciSendString(“set movie time format ms”, 0, 0, 0)

    retVal = mciSendString(“status movie position wait”, retData, 128, 0)

    Dim position as integer = val(retdata)

    ————-

    That code should get you going.

    Jason

    Reply
  11. Jeff

    Jason- Thanks for all of that help- it worked 😀 but i was wondering (i couldn’t find it on the pages) If you knew how to make the cursor when play a movie different. I noticed that while playing a movie and if you bring your mouse over it, it will change to the XP default 🙁 Can i change it?

    Reply
  12. Jason Post author

    Hi, I am not completely sure what your wanting. You want the cursor to be changed when the mouse is over the movie window? Let me know more detailed info. Thanks

    Jason

    Reply
  13. Jeff

    o and also if you know how to make a track bar that will change its value to the total number of milliseconds in the video so I can scroll through the video with it.

    Reply
  14. Jason Post author

    I don’t have any info on the cursor since its never something i’ve needed to do. If I get time I may look into it.

    Also you need to check out the links below which will show you how to implement most moveie player features.

    This is the Movie Player example: http://www.vbcodesource.info/downloads/csMovieLibraryProExampleApp.zip

    This is the class library you make a reference to from the movie example above: http://www.vbcodesource.info/downloads/csMovieLibraryProProject.zip

    That example project shows how to make a full movie player with many features.

    Jason

    Reply
  15. Jeff

    o and a got another question 😀 -do you have any ideas on how to convert a string of images into and AVI File? maybe useing MciSendString~

    Reply
  16. Jason Post author

    Hi, Jeff I do not have anything on doing what you want with your AVI files. I have never tried to do anything like that. If I come up with anything I will make a comment here on it.

    Jason

    Reply
  17. Garry

    I have a working media player written in VB6 using MCISend String.
    What I cannot figure out is how to make the video window (A Frame on a Form) respond to mousemovements and mouse clicks.Does anyone have any idea’s.
    I have tried the GetCursorPos API but it does not detect any mouse movement on the X or Y Cords.

    Reply
  18. Jason Post author

    Hi John, you will want to use the MSWEBDVD control as it provides a web-like interface. Just remember that the target computer will have to have some kind of software or hardware dvd decoder. For example most ATI video cards has hardware assisted dvd decoding and powerdvd would be a software decoder.

    KLite may have one in it. I do know that Classic Media Player can playback dvd’s and is included in some of the KLite codec packs.

    Hopefully this will give you a starting point. 🙂

    Jason

    Reply
  19. Jeff

    Jason-
    I just noticed that this media player will distort the aspect ratio if not sized perfectly-Is there a way I can get the original size of the media file?

    Reply
  20. Jason Post author

    Hi, you can check the original size of the movie. Go to this post: http://www.vbcodesource.info/?p=155 and go to the link that lists the available mci command strings located at microsofts msdn site. You will see a list of commands and just check some of those commands to see which will give you what you want. That post i’m linking too is a tutorial on how to program the mci device by yourself by using the mci string system.

    Jason

    Reply
  21. Roger

    Jason,
    Thanks. I’ve been able to use your information to write a program to scout opponents in football. The only problem that I have is that when I have the program play a series of clips, it acts like it loses the video for a little while. It says program not responding at the top of the form and the screen goes white. Generally after a little while the program comes back and executes. The bad thing is that the error is not consistent. Any suggestions? Thanks again for the article.

    Reply
  22. akula

    I just noticed, the function t_Tick() causes the video playback to be jumpy (e.g. it refreshes once every 1 second as it update the label texts inside t_Tick() which cause it to be jittery..)

    Anyone else have this problem? How can I update the label text without causing the playback to be jumpy?

    Reply
  23. Jason Post author

    Hi, try removing or comment out the line of code in the timer that gets: “positionInFrames”

    I’m not sure if your having the same problem I ran into a few years ago. For some reason changing the time format back and forth to frames the mci device skips.

    Anyways, see if that helps or not.

    Jason

    Reply
  24. Jason Post author

    Roger, sorry it took so long for me to respond. I’ve been VERY busy.

    I’m not sure how fast your computer is as that could have some impact on video performance. Also try turning off all code except for the playback code and see if it still does it. If it stops having that problem then enable the code features one by one until it start having that problem again. If you can’t figure it out give me a link to download your prjoect with the video file that freezes on you. If any video freezes then just let me know.

    Jason

    Reply
  25. Roger

    Jason, thanks for the response. I don’t have a way to post it so you can download it. I can copy the Section of code that is giving me trouble into the comment box, but I’m afraid that its format will be distorted and will be a headache for you to read. I did eliminate a lot of the code but the problem seems to persist although it is intermittent. When it is working, transition from one clip (the clips average about 6 seconds in length) is very smooth, and I’ve been able to play as many as 50 clips in a row without error, but other times it loses the video and I get all kinds of strange things happening inside the program’s frame. It kind of reminds me of how Pascal programs used to act when arrays got out of dimension. I don’t know if it is related, but inside the loop, there are a couple of lines that should update textboxes, and these don’t execute at all until the program is done with the loop and then they show the correct final values. The text box that should be showing frame number isn’t updating at all, although it will if a play a single clip. I would be glad to email the code as an attachment if that would work out for you. Thanks again for your help – this has become a major frustration.
    Roger

    Reply
  26. Jason Post author

    Hi, Roger, if you don’t have a link to the download send it to:

    Obviously replace att with @. I will remove this email info once I have your files.

    Also make sure the video files are not corruprted and play fine in another program like windows media player. Also just make sure your computer has enough power to handle the decoding stress.

    What type of encoding is used for the videos? It could be a codec problem. Installing the latest codecs could help fix the problem as well. K-Lite is a very nice codec pack you can install if you want to.

    Anyways, let me know some more info and feel free to send the files to the email address above. Thanks 🙂

    Jason

    Reply
  27. Jeff

    Hey Jason-

    I asked you earlier about the original size of the movie and I can not find it in the list of the available mci command strings. Can you please help?

    Reply
  28. Jason Post author

    Hi Jeff. I must have looked over your question or was to busy at the time.

    You will want to use the ‘where’ command string and the ‘source’ flag.

    This code should work.

    retVal = mciSendString(“where movie source”, retData, 128, 0)

    Change ‘movie’ to the alias you used when opening the file. The ‘reVal’ string would contain the data you want. It should contain a data format similar to this: 0 0 1024 768

    The first 0 would be the left position, the second 0 would be the top position, 1024 would be the default width and 768 would be the movies default height.

    Depending on what info you want specificially just extract the values from the retval string.

    Hope this helps. 🙂

    Jason

    Reply
  29. ali

    i cannot play mp3 music using mcisendstring where there is have a ALBUM ART or PICTURE FOR LOGO

    there are anyone have this solutions?

    Reply
  30. Jason Post author

    ali, If you mean that it try’s to play a logo file as a mp3 song then you need to add code to only play media ending with the .mp3 extension. Basically make it ignore any file that is Not an .mp3 based file.

    Reply
  31. Libometric

    Jason,

    Thanks for this tutorial. I’ve been looking for something that works for over a week now and, thanks to you, I made it.

    WELL DONE!!!

    Libometric

    Reply
  32. Libometric

    Jason,

    I thought my problems were over but I was mistaken… So, I would be grateful if you could assist on this question:
    How can I either save a specific frame of an avi to a picture file (say bmp or jpg) or, even better, place it as actual image of the picture box used as a display. If I understand correctly, the picture box is empty, right?

    Thanks in advance.

    Libometric

    Reply
  33. Jason Post author

    Hi Libometric, its not a easy job to do. The mci documentation provide commands for capture but they don’t really work anymore probably since everything is hardware accelerated these days and play movie’s as a overlay instead of a real window.

    I was successful before by using the BitBlt api but I can not find that code anywhere. I know I have it but I can’t find it. If I come up with it I will uploa a example and put a link in a comment here.

    Jason

    Reply
  34. Libometric

    Hi Jason,

    Thanks; BitBlt api is good enough provided that no other windows are in front as it captures portions of the screen. I found a working code in this address:
    http://www.codeproject.com/KB/GDI-plus/BitBlt.aspx.

    I was thinking something like returning the handle using the SendMessage function but this would only work with parent containers and picture box is a child one.

    Anyway, thanks again, you have really helped (again!!)

    Libometric

    Reply
  35. João Carlos

    estou procurando um código fonte em VB6 que joga todos os arquivos de onda na placa de audio selecionada (device)

    Reply
  36. JamesJSH

    Hello Jason, Im a grade 12 student in a computers class, Im trying to figure out how to make a CD player program kind of like Windows Media Player, I have all of the song codes and player outlook, One thing im missing in the program is the Visualization we see in our own media players, I dont need those files, just need to be cleared up on how to be able to put the visualization in

    Reply
  37. Jason Post author

    Hi James, I’m not completely sure what you need. Do you mean something like fft visualizations?

    If its fft visualizations its not possible to do using the mcisendstring interface.

    Bass.dll library has a specific .dll for cd player programs. That library gives you direct access to the audio buffer that you can use to plot visuals that dances to the music or whatever.

    If I am wrong about what your wanting let me know. Thanks 🙂

    PS: My site: vbcodesource.com has full featured libraries and example programs on making a full-featured CD Player application if your interested.

    Jason

    Reply
  38. Abelius

    Oh, this is so great! I thought it was impossible to play videos in VB because I didn’t saw any “video control” or something, but now the possibilities are endless! Thank you! I’ll be back without any doubt for more of your wisdom, he he…

    Reply
  39. Jason Post author

    Hi Hendra, the closest thing to pitch control using MCI is speed control setting like below…

    value = 1500

    mciSendString(“set movie speed ” & Value, “”, 0, 0)

    “Value” is a integer value between 1 and 2000. 1000 is normal speed. Higher than 1000 is faster and lesser than 1000 is slower.

    Reply
  40. Hendra

    Hi Jason, thanks for answering my question about the pitch control, that’s really work !!
    but i still have some problem with MCIsendstring command. How can i play my mpegvideo file with full screen at the second monitor? i hope you have reference about this, thanks before !

    Reply
  41. Jason Post author

    Hi, I actually have no idea if its possible to use mci to specify the window on a second monitor. If I come up with something I will make a comment here in the future. Thanks 🙂

    Jason

    Reply
  42. Andy

    Hi I finished most of my media player now Im stuck on the fullscreen issue I knw bout the windowstate but I want the video to maximize whn I dblclick and minimize whn I dblclick again, the handle window seems to be blockin the control whch I assigned the mousedblclick event to, I tryd usn a panel but i hav to dblclick twice in order to see the video. Is ther a way to assign events to the msci video window or a way arwnd this issue thanx in advance

    Reply
  43. Andy

    Ok I was jst bein a lil impatient I tryd a panel again and it worked lyk a charm jst had to make sure the dock style is fill and its the same color as my frm so all thats left nw is the album art

    Reply
  44. Jason Post author

    Rnight, do you mean change the cursor when its over the movie window only? LMK alittle more info and I can try to help.

    Jason

    Reply
  45. mimi

    ei.. i try your code but the ‘movieWindow’ has an error… it is not declared ?? what will i gonna do ?? please heelp thank you….

    Reply
  46. Jason Post author

    Mimi, the movieWindow is the handle to the control you want the movie to play on.

    For instamce…

    movieWindow = Panel1.handle.toInt32

    Now the movie will play in that panel window. If your using vb 6.0 then something like…

    movieWindow = me.hwnd

    That will play the movie on the form.

    Anyways, hope this helps. 🙂

    Reply
  47. Dave

    Hi Jason your code is brilliant – I have one question though
    before you click the play button ,the moviewindow in my case a groupbox is blank – is there a way of displaying a frame of the movie before you play it ?
    like media players library thumbnails
    Thanks in advance

    Reply
  48. Jason Post author

    Hi Dave, you can try forwarding the video by a couple frames or so. So instead of playing just fast forward by how ever many frames you want.

    Jason

    Reply
  49. mihai

    Hi Jason, first of all I want to thank you (like many others) for this tutorial. After more than 2 years the dialog is still alive, and that shows us how good it is. From a few guideing ideea growed up. I like this.
    So, now see my question (I read before that, all dialogs from here and many other articles) but I have an understanding issue.
    I need the code for automatic close mci when the movie is finished.
    I know, I need to put some code in a Timer control, but I don’t know what code must put in it.

    Reply
  50. Jason Post author

    Hi Mihai, I have a library I made that has code in it that you can use to determine if the song or movie has finished playing. Its at vbcodesource.com.

    Either way, the way that code works is by getting the total play length of the media, and then monitor in a timer control the current playing position of the media. Once the current position is the length of the media’s play length, then it has reached the end of the media.

    Hope this helps. 🙂

    Jason

    Reply
  51. mihai

    Thanks Jason.
    My mistake it was then I try to find the lenght media properties before playng.
    Wrong steps:
    1. open media
    2. lenght media
    3. play media

    I change 2 with 3 and is ok.

    Mihai

    Reply
  52. mihai

    Hi Jason again

    Now, this is my question…
    What error message is generated by mci if windows system don’t have instaled the proper driver ? (user don’t see anything, the screen is black)
    I ask that because I want to create some function witch help user to download K-Lite (because is free), from my ftp address and install it.
    Or if mci don’t send any error, what is the solution in this case?
    Thanks a lot for any sugestion.

    Mihai

    Reply
  53. Noob

    Is there any way to let MCI device choose the best driver available for a particular video and play it ? If this is possible can you provide codes for the same ?

    Thank You

    Reply
  54. Jason Post author

    Hi, just leave out the type mpegvideo string. Like below…

    retVal = mciSendString(“open ” & filename & ” alias movie”, 0, 0, 0)

    It doesn’t always pick the best driver to use. You will just need to test it out. The mpegvideo type does play nearly all formats out there once you have the proper codecs installed.

    Just try it out and see which method works for you. 🙂

    Reply
  55. Mas Boy

    i have karaoke software, was perfect playing avi and another format. with dual view output, VGA and SVideo.
    The problem is can’t play to HDMI output on my VGA card.

    if i play on another player, DVI, VGA and HDMI is working.

    i think, video codec in karaoke software not support for HDMI support.

    i hope you have reference about this, thanks before !

    Reply
  56. Kris

    Jason, you are a genius. But tell me, if I want to embed a video on Form1 (for example) and my project is in the “My Project” folder in Documents, how can I correct the code so that if my friend copies the entire folder to her Desktop on her PC, the path for the video will still work. I have the video in the Resources folder. Thanks.

    Reply
  57. Mihai

    Hi Jason,
    how is possible to know if user have an proper codec in him pc ?
    Depend on result, to tell user … instal KLite for example, or other codecs package.

    Reply
  58. Jason Post author

    Hi, that’s a good question. One thing that could help you is the MCI status info when you send it a command. For instance, when you tell MCISendstring to send an Open command to a file you want to play, if everything appeared to have went ok it will say something like: “The specified command was carried out”. If it can’t playback the file, like if it doesn’t have the proper compressors/decompressors (codecs) installed, I think it will usually say something like “an unrecognizable format being opened”, or something along the lines of a codec error or something like that.

    That is probably the easiest way I can think of although it may not the a 100% accurate. Maybe give that a try and see what you can come up with. 🙂

    Jason

    Reply
  59. Mihai

    Hi Jason, thank again for your quick reply.
    I will explore MCI errors, to find a way to filter and make some decisions about that.
    Another small advice, if you have one(like allways you must have one :))))….)
    In one of my project I use a small .avi file, created by me and is pure .avi format (uncompressed, without sound).
    In this case, I think, maybe it’s a good way to install directly the needed .dll’s when I install my application.
    But ??? … which are this dll’s ? And must by registered in registry ? or it’s enough to put in my app folder.

    Thanks a lot for any sugestion.

    Reply
  60. Jason Post author

    Hi, If I was you I will have them install the codecs separately from your program. Maybe popup a window that tells them what has happened and what they may need to do to fix it. You could then provide a link to download a codec pack.

    I personally would rather have them install a third party program on there own.

    Jason

    Reply
  61. Mihai

    Hi Jason, I rewind again with another issue.
    I want to play to play 2 movie, in 2 PictureBox’s
    One it’s a ‘Logo’ movie witch must play all the time.
    Second movie it’s like ‘Wait’ and must play just when the one of many recordings, is done.
    So, for the second movie I ‘Play’ and ‘Close’ MCI many time.
    The issue appear when I use for the first time the ‘Close’ command, witch close all movies.
    I use (and I thank you) your movie class.

    I try to declare 2 separate variable:
    Public logoMOV As New MovieModule
    Public waitMOV As New MovieModule

    Each one have separate FileName for the files path:
    logoPath = app.path & “\logo.avi”
    waitPath = app.path & “\wait.avi”

    Also I try to put in your CloseMovie function this code:
    Filename = Chr$(34) & Replace(Filename, Chr$(34), “”) & Chr$(34)
    retVALL = mciSendString(“close movie” & Filename, 0, 0, 0)

    How you see I use ‘close movie’ and not ‘close all’, but without any succes.
    All movie is closed.
    How is possible to manage this situation

    Thanks in advance for any sugestion 🙂

    Reply
  62. Jason Post author

    Hi, if I understand you correctly you will want to open each movie with a different alias name. The alias name can be pretty much whatever you want. The examples below is using an alias named movie1 and another named movie2.

    Like…

    ‘This will open your first movie file with an alias named movie1.
    retVal = mciSendString(“open ” & movieFilename1 & ” alias movie1″, 0, 0, 0)

    ‘This will open your second movie file with an alias named movie2.
    retVal = mciSendString(“open ” & movieFilename2 & ” alias movie2″, 0, 0, 0)

    Now, you can control each of your movies individually. For instance, you can start playing the first movie and pause the second movie.

    ‘This will start playing movie1 only and have no effect on your 2nd movie.
    retVal = mciSendString(“play movie1”, 0, 0, 0)

    ‘This will pause your second movie and have no effect on your first movie..
    retVal = mciSendString(“pause movie2”, 0, 0, 0)

    Now if your done with one of the movies you just close the movie using the alias name you used when you opened it. For instance below will close your first movie file but continue allowing your second movie file.

    retVal = mciSendString (“close movie1”, 0, 0, 0)

    So now your 1st movie is completely closed but your 2nd movie is still opened.
    Hope this helps. 🙂

    Jason

    Reply
  63. Mihai

    Ji Jason, it seems that I have not read enough, because I see in some articles “alias movie”, but I did not understand what it is.
    Thanks again for your support. 🙂

    Reply
  64. Ryder

    Hi Jason,

    I have a question about this video player. Its cool player, but i want to modify it, but i dont know how to do it.
    Ok here is what i want to do.
    1) I want that video is loaded automatically on form load and without OpenFileDialog option.
    How do i do this?
    2) How do i play video from url (e.g http://wwwblabla.com/blabla.mp4) not from local library?? 🙂

    Thank you!
    Regards

    Reply
  65. Jason Post author

    You just need to provide the path and filename you want played on startup for your player. It may delay your apps loading a little while it buffers, but should not be to bad.

    If you want to stream a video, you will want to use a different media system. MCI is not able to stream music or video. You should be able to use the Windows Media Player library or try the Bass library from un4seen.com.

    If you need anything more make a comment.

              Jason
    
    Reply
  66. Shahram

    Hi Jason, First of all thanks a lot for your codes and comments. It was fantastic.
    I could write a media player (of course not like GOM player) but almost with all required features using your tips and guide lines.
    Mouse wheel hook, Volume, full screen, speed 2x 4x 8x up to 64x etc., original size, window size, all types of media, everything works perfect, due to your brilliant and simple codes.
    There is only one problem in VB6 on windows XP. not on Windows 7.
    Everything works fine until I close the window, VB6 crashes. Those kind of errors you never know what is all about. However in windows 7 it works perfect. Any idea?

    Reply
  67. Jason Post author

    Hi Shahram, I need a little more info. When it crashes, what error message do you get? Does it crash every time you unload? You could try sending an MCI call to close all opened devices to release resources when your program begins unloading. Just send a MCI command with: “close all”. That may help. But let me know some more info if you could.

            Jason
    
    Reply
    1. Shahram

      Hi Jason,

      First of all thanks a lot for such quick response. yes it does every time.
      I checked everything.
      close all, close mymovie, close mymovie wait.
      remove the close all from the unload of media form, and put it let say in another command click event of a parent form, since I think there is problem with time issue.
      I can send you a project example source file, that you can open it in vb6, and check it, if you give me an email.
      As I mentioned, there is not any specific error message. Just those kind of VB6 errors, that closes the IDE too, and if you debug, it just says something about writing to an address 0000000×0 or something.

      By the way, Thanks a lot again.
      and please tell me how can I remunerate.

      Reply
      1. Shahram

        Hi Jason,

        It seems something is wrong with my system. I checked in another computer running Windows XP, and it worked perfectly. I also checked in a Windows XP mode of Windows 7 and it worked without any problem too.

        Again thanks a lot.

        Reply
  68. Shahram

    Hi Jason,
    This is what I need, if it is there a solution. I have some training courses mp4 video, that I could play it in my media player, programmed and written with your guild lines. Thanks again.
    But I don’t want to be copied. Thus I encrypted it, and whenever I want to replay it, I decrypt it and load it in mci open command.
    But anyone can find the decrypted file by comparing files of his or her system, before playing and while playing.
    Is there a way to create such stream in memory for let say mp4 files not bigger than 80MB, and push that stream to the MCI open, instead of writing to a file.

    Thanks in advance,
    All the best

    Reply
  69. Jason Post author

    Hi, for VB.NET I think it is possible within the .NET Framework to do something like that. But for VB6.0, I don’t know. That is, if I’m understanding what you want correctly.

    Reply
  70. Shahram

    Hi Jason, Thanks for your reply.
    You got exactly what I meant. I could find a DELPHI code to do that. But it uses a syntax I am not familiar with. TObject, Tlabla….
    I am trying to see if it is possible in VB6. For now I used ReadFile API to read an mp4 in a byte array.
    I am wandering now internet to see an example of using MCISendCommand example in VB6.
    I hope if I can pass this byte array directly or with VarPtr function to MCISendCommand it works.
    I’ll let you know, if I found anything special.

    All the best
    Shahram

    Reply
  71. hany

    hi.. i want to ask. how to change pitch without change the speed,iam use
    mciSendString(“set movie speed ” & value, “”, 0, 0)
    its for change pitch and tempo. i just want change the pich without change the tempo to make vocal control. is it possible? thank you

    Reply

Leave a Reply