Results 1 to 4 of 4

Thread: Play Video In a Control

  1. #1

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Thumbs up Play Video In a Control

    Have you ever wanted to play videos in a control on a form without using Windows Media Player? Here's how:

    Code:
        Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
        Const WS_CHILD As Integer = &H40000000
    
        Private Sub PlayMedia(ByRef FileName As String, ByVal Window As Control)
            FileName = Chr(34) & FileName & Chr(34)
            mciSendString("Open " & FileName & " alias MediaFile parent " & CStr(Window.Handle.ToInt32) & " style " & CStr(WS_CHILD), Nothing, 0, 0)
            mciSendString("put MediaFile window at 0 0 " & CStr(PixelToTwip(Window.ClientRectangle.Width) / 15) & " " & CStr(PixelToTwip(Window.ClientRectangle.Height) / 15), Nothing, 0, 0)
            mciSendString("Play MediaFile", Nothing, 0, 0)
        End Sub
    
        Private Function PixelToTwip(ByVal Pixel As Integer) As Double
            Return Pixel * 15
        End Function
    USAGE:

    Code:
    PlayMedia("FileName", PictureBox1)
    Last edited by .NetNinja; Nov 10th, 2008 at 02:24 PM.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  2. #2
    Lively Member
    Join Date
    Aug 2008
    Posts
    75

    Re: Play Video In a Control

    thank you very much for the submission... works great right off the bat... all i did was add a picturebox and a button... also runs in its own thread... with audio.... but question how would i say pause... and stop.... basically how would i control the video


    thank you
    How To Make A Youtube Downloader
    I use Visual Studio 2008 Pro...

  3. #3

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: Play Video In a Control

    Everything can be found under mciSendString Multimedia Command Strings.

    But, for example, to pause the video you would simple do this:

    Code:
    mciSendString("pause MediaFile", Nothing, 0, 0)
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  4. #4
    Lively Member
    Join Date
    Aug 2005
    Posts
    88

    Re: Play Video In a Control

    Does anyone know how to play another video after the first one has played? It does seem to do anything if I call the PlayMedia function with a different path.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width