dcsimg
Results 1 to 22 of 22

Thread: MPV player into vb proyect, is possible...?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2017
    Posts
    5

    MPV player into vb proyect, is possible...?

    hi guys, I found this code mpv examples, and some time ago I saw http://www.vbforums.com/showthre..., it would be possible to integrate this player to vb projects, without external dependencies.
    The code escapes my knowledge. Thank you.

  2. #2
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,137

    Re: MPV player into vb proyect, is possible...?

    looks simple enough.

    Code:
                var windowId = pictureBox1.Handle.ToInt64();
                _mpvSetOption(_mpvHandle, GetUtf8Bytes("wid"), mpvFormatInt64, ref windowId);
                DoMpvCommand("loadfile", textBoxVideoSampleFileName.Text);
    in VB6 that would be something like
    Code:
    mpv_set_option m_mpvHandle, GetUtf8Bytes("wid"), 4&, pictureBox1.hWnd
    DoMpvCommand "loadfile", textBoxVideoSampleFileName.Text

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,367

    Re: MPV player into vb proyect, is possible...?

    Why not just use WMP for this?

    Name:  sshot.png
Views: 265
Size:  17.1 KB

    Code:
    Option Explicit
    
    Private CommonDlgsW As CommonDlgsW
    
    Private Sub Form_Load()
        Const ssfMYVIDEOS = &HE& 'Requires Windows Vista or later.
    
        Set CommonDlgsW = New CommonDlgsW
        With CommonDlgsW
            .DialogTitle = "Choose a video file"
            .Filter = "Supported video files(*.mp4;*.wmv)|*.mp4;*.wmv"
            .Flags = cdlOFNExplorer _
                  Or cdlOFNPathMustExist _
                  Or cdlOFNFileMustExist _
                  Or cdlOFNLongNames _
                  Or cdlOFNShareAware
            .InitDir = CreateObject("Shell.Application").NameSpace(ssfMYVIDEOS).Self.Path
        End With
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            WMP.Move 0, 0, ScaleWidth, ScaleHeight
        End If
    End Sub
    
    Private Sub mnuFileOpenvideo_Click()
        With CommonDlgsW
            If .ShowOpen(hWnd) Then
                WMP.Visible = True
                WMP.URL = .FileName
                mnuView.Enabled = True
            End If
        End With
    End Sub
    
    Private Sub mnuViewFullscreen_Click()
        WMP.fullScreen = True
    End Sub
    
    Private Sub WMP_KeyDown(ByVal nKeyCode As Integer, ByVal nShiftState As Integer)
        If nKeyCode = vbKeyEscape Then
            WMP.fullScreen = False
            nKeyCode = 0
        End If
    End Sub
    Attached Files Attached Files

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2017
    Posts
    5

    Re: MPV player into vb proyect, is possible...?

    Thank you, dilettante and DEXWERX, but my intention was to create an application without dependencies, and I saw that mpv player could be used, DLL procedure call. Similar
    Code:
        DllPath = app.path & "\mpv-1.dll"
        vTbl(mpv_create) = New_c.GetFuncPtr(DllPath, "mpv_create", True)
        vTbl(mpv_initialize) = New_c.GetFuncPtr(DllPath, "mpv_initialize", True)
        vTbl(mpv_terminate_destroy) = New_c.GetFuncPtr(DllPath, "mpv_terminate_destroy", True)
        vTbl(mpv_command) = New_c.GetFuncPtr(DllPath, "mpv_command", True)
        vTbl(mpv_set_option) = New_c.GetFuncPtr(DllPath, "mpv_set_option", True)
        vTbl(mpv_set_option_string) = New_c.GetFuncPtr(DllPath, "mpv_set_option_string", True)
        vTbl(mpv_get_property) = New_c.GetFuncPtr(DllPath, "mpv_get_property", True)
        vTbl(mpv_set_property) = New_c.GetFuncPtr(DllPath, "mpv_set_property", True)
        vTbl(mpv_free) = New_c.GetFuncPtr(DllPath, "mpv_free", True)
    but my problem is that I can not find information to transform this code:

    Code:
            public static IntPtr AllocateUtf8IntPtrArrayWithSentinel(string[] arr, out IntPtr[] byteArrayPointers)
            {
                int numberOfStrings = arr.Length + 1; // add extra element for extra null pointer last (sentinel)
                byteArrayPointers = new IntPtr[numberOfStrings];
                IntPtr rootPointer = Marshal.AllocCoTaskMem(IntPtr.Size * numberOfStrings);
                for (int index = 0; index < arr.Length; index++)
                {
                    var bytes = GetUtf8Bytes(arr[index]);
                    IntPtr unmanagedPointer = Marshal.AllocHGlobal(bytes.Length);
                    Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length);
                    byteArrayPointers[index] = unmanagedPointer;
                }
                Marshal.Copy(byteArrayPointers, 0, rootPointer, numberOfStrings);
                return rootPointer;
            }
    Also say that as it puts the title, I do not know if this is posible, use this dll.

    excuse me my english

  5. #5
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,137

    Re: MPV player into vb proyect, is possible...?

    you wouldn't want to transform that particular code. VB6 is unmanaged so we don't have to worry about 99% of the marshalling issues .NET does.

    those vTbl lines should just be replaced with Declare statements.

    if someone took the time to translate that C# example it would probably take half the code.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2017
    Posts
    5

    Re: MPV player into vb proyect, is possible...?

    Quote Originally Posted by DEXWERX View Post
    you wouldn't want to transform that particular code. VB6 is unmanaged so we don't have to worry about 99% of the marshalling issues .NET does.

    those vTbl lines should just be replaced with Declare statements.

    if someone took the time to translate that C# example it would probably take half the code.
    Thank you.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,367

    Re: MPV player into vb proyect, is possible...?

    You always have "dependencies." Unlike this 3rd Party library though, wmp.dll is part of Windows and does not need to be deployed.

    You only make your deployment task that much harder if you use this thing. But since you are determined to do so anyway for other reasons... good luck.

  8. #8
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,137

    Re: MPV player into vb proyect, is possible...?

    MPV.cls
    Code:
    Option Explicit
    
    Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryW" (ByVal lpLibFileName As Long) As Long
    Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Private Declare Function DispCallFunc Lib "oleaut32" (ByVal pvInstance As Long, ByVal oVft As Long, ByVal cc As Long, ByVal vtReturn As Integer, ByVal cActuals As Long, ByRef prgvt As Integer, ByRef prgpvarg As Long, ByRef pvargResult As Variant) As Long
    Private Declare Function SysAllocStringByteLen Lib "oleaut32" (ByVal psz As Long, ByVal cblen As Long) As Long
    Private Declare Function lstrlenA Lib "kernel32" (ByVal lpString As Long) As Long
    Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpWideCharStr As Any, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cbMultiByte As Long, Optional ByVal lpDefaultChar As Long, Optional ByVal lpUsedDefaultChar As Long) As Long
    Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cbMultiByte As Long, ByRef lpWideCharStr As Any, ByVal cchWideChar As Long) As Long
    Private Declare Function GetMem4 Lib "msvbvm60" (Src As Any, Dst As Any) As Long
    Private Const CP_UTF8 As Long = 65001
    Private Const MPV_FORMAT_STRING As Long = 1&
    
    Private m_Dll As Long
    Private m_Handle As Long
    
    Private Function ToUTF8(ByVal Str As String) As String ' String to String encoding...
        GetMem4 SysAllocStringByteLen(0&, WideCharToMultiByte(CP_UTF8, 0&, ByVal StrPtr(Str), Len(Str), ByVal 0&, 0&)), ByVal VarPtr(ToUTF8)
        WideCharToMultiByte CP_UTF8, 0&, ByVal StrPtr(Str), Len(Str), ByVal StrPtr(ToUTF8), LenB(ToUTF8)
    End Function
    
    Private Function FromUTF8Ptr(ByVal psz As Long) As String 'Ptr to String decoding
        FromUTF8Ptr = String$(MultiByteToWideChar(CP_UTF8, 0&, ByVal psz, lstrlenA(psz), ByVal 0&, 0&), vbNullChar)
        MultiByteToWideChar CP_UTF8, 0&, ByVal psz, lstrlenA(psz), ByVal StrPtr(FromUTF8Ptr), Len(FromUTF8Ptr)
    End Function
    
    Private Function MpvExport(ByVal Export As String) As Long
        Static Exports As New Collection
        On Error GoTo EH
        MpvExport = Exports(Export)
        On Error GoTo 0
        If MpvExport = 0 Then Err.Raise 5, "MpvExport()", "Can't find export: " & Export
        Exit Function
    EH: Exports.Add GetProcAddress(m_Dll, Export), Export
        Resume
    End Function
    
    Private Function MpvCall(ByVal Export As String, ByVal ReturnType As VbVarType, ParamArray Args())
        Const CC_CDECL As Long = 1&
        Const MAX_ARGS As Long = 8&
        Static VarTypes(MAX_ARGS) As Integer
        Static VarPtrs(MAX_ARGS) As Long
        Dim hRes As Long
        Dim Arg As Long
        Dim ByValArgs() As Variant
        
        ByValArgs = Args
        For Arg = 0 To UBound(ByValArgs)
            VarTypes(Arg) = VarType(ByValArgs(Arg))
            VarPtrs(Arg) = VarPtr(ByValArgs(Arg))
        Next
        
        hRes = DispCallFunc(0&, MpvExport(Export), CC_CDECL, ReturnType, Arg, VarTypes(0), VarPtrs(0), MpvCall)
        If hRes < 0 Then Err.Raise hRes, "MpvCall()"
    End Function
    
    Private Sub Class_Initialize()
        ' The dll is included in the DEV builds by lachs0r: https://mpv.srsfckn.biz/
        If m_Dll = 0 Then m_Dll = LoadLibrary(StrPtr("mpv-1.dll"))
        If m_Dll = 0 Then Err.Raise 17, "MPV.Class_Initialize()", "Failed to load mpv-1.dll"
        If m_Handle = 0 Then m_Handle = MpvCall("mpv_create", vbLong)
        If m_Handle = 0 Then Err.Raise 17, "mpv_create"
        If MpvCall("mpv_initialize", vbLong, m_Handle) Then Err.Raise 17, "mpv_initialize"
    End Sub
    
    Private Function MpvCommand(ParamArray Commands()) As Long
        Static Buffer() As String
        If m_Handle = 0 Then Exit Function
        ReDim Buffer(UBound(Commands) + 1)
        Dim Index As Long
        For Index = 0 To UBound(Commands)
            Buffer(Index) = ToUTF8(Commands(Index))
        Next
        Buffer(Index) = vbNullString
        MpvCommand = MpvCall("mpv_command", vbLong, m_Handle, VarPtr(Buffer(0)))
    End Function
    
    Private Property Let MpvOption(ByVal Name As String, ByVal Value As String)
        If m_Handle = 0 Then Exit Property 
        MpvCall "mpv_set_option_string", vbLong, m_Handle, StrPtr(ToUTF8(Name)), StrPtr(ToUTF8(Value))
    End Property
    
    Private Property Get MpvProperty(ByVal Name As String) As String
        Dim psz As Long
        If m_Handle = 0 Then Exit Property 
        MpvCall "mpv_get_property", vbLong, m_Handle, StrPtr(ToUTF8(Name)), MPV_FORMAT_STRING, VarPtr(psz)
        If psz Then MpvProperty = FromUTF8Ptr(psz)
        MpvCall "mpv_free", vbEmpty, psz
    End Property
    
    Private Property Let MpvProperty(ByVal Name As String, ByVal Value As String)
        If m_Handle = 0 Then Exit Property 
        MpvCall "mpv_set_property", vbLong, m_Handle, StrPtr(ToUTF8(Name)), MPV_FORMAT_STRING, VarPtr(ToUTF8(Value))
    End Property
    
    Public Sub Pause()
        MpvProperty("pause") = "yes"
    End Sub
    
    Public Sub Play()
        MpvProperty("pause") = "no"
    End Sub
    
    Public Function IsPaused() As Boolean
        If m_Handle Then
            IsPaused = (MpvProperty("pause") = "yes")
        Else
            IsPaused = True
        End If
    End Function
    
    Public Sub Load(File As String, hWnd As Long)
        Class_Terminate
        Class_Initialize
        MpvOption("keep-open") = "always"
        MpvOption("wid") = Str$(hWnd)
        MpvCommand "loadfile", File
    End Sub
    
    Public Sub SetTime(Value As Double)
        MpvCommand "seek", Str$(Value), "absolute"
    End Sub
    
    Private Sub Class_Terminate()
        If m_Handle Then
            MpvCall "mpv_terminate_destroy", vbLong, m_Handle
            m_Handle = 0
        End If
    End Sub
    NOTE: make sure you use an older dev build, if a recent version of mpv-1.dll doesn't work for you.
    Last edited by DEXWERX; Mar 22nd, 2018 at 01:34 PM.

  9. #9
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,139

    Re: MPV player into vb proyect, is possible...?

    Quote Originally Posted by DEXWERX View Post
    MPV.cls
    NOTE: make sure you use an older dev build, if a recent version of mpv-1.dll doesn't work for you.
    Hi DEXWERX,

    Where can I get MPV-1.dll? Do I need to compile the following source code myself?
    Https://github.com/mpv-player/mpv

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,864

    Re: MPV player into vb proyect, is possible...?

    I've used MPlayer with the SMPlayer GUI wrapper with my primary VB6 project for years (both "portable" versions). I have the entire thing wrapped up in the resources of the project. When I need it, I unpack it into ...AppData\Local\SMPlayer and then use it from there to play whatever movies I want. My entire application is completely portable (i.e., no "registered" dependencies). Here's one little (incomplete) procedure that's executed anytime I need to play a movie file:

    Code:
    
    Public Sub MakeSureMoviePlayerIsOnLocalComputer()
        Dim sLocalFolder As String
        '
        sLocalFolder = GetSpecialFolder(CSIDL_LOCAL_APPDATA) & "SMPlayer"
        '
        ' The following is to make sure we're using the latest version.
        If bFolderExists(sLocalFolder) Then
            If Not bFileExists(sLocalFolder & "\radio.m3u8") Then ' It's the old version.
                KillFolder sLocalFolder
            End If
        End If
        '
        ' Create the local SMPlayer folder, if needed.
        If Not bFolderExists(sLocalFolder) Then MkDir sLocalFolder
        sLocalFolder = sLocalFolder & "\"
        '
        ' Make sure the SMPlayer is on the local computer.
        BackupSourceToDestination SMPlayerFolder, sLocalFolder, , AddressOf FilenameFilterForMoviePlayerCopying
        '
        ' Force a refresh of the SMPlayer.ini file.
        FileCopy SMPlayerFolder & "smplayer.ini", sLocalFolder & "smplayer.ini"
    End Sub
    
    

    I'm on a consulting gig and don't have a great deal of time at the moment. However, within the next few days, I'll outline it in more detail, if you think this would help you. Now, the movies don't play on a VB6 form. But the MPlayer is entirely open-source, as well as the SMPlayer GUI wrapper for it. And the SMPlayer is entirely customizable via an INI file. And never any banners or advertisements. And, the MPlayer will play just about anything you can throw at it.

    Hope That Helps,
    Elroy

    EDIT1: Just as an FYI, my entire application is portable and in a single EXE file. No installation needed. It does "unwrap" several things to execute, but it gets them all from the same EXE file.
    Last edited by Elroy; Aug 30th, 2018 at 05:52 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  11. #11
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,139

    Re: MPV player into vb proyect, is possible...?

    Hi Elroy, thank you for your detailed reply. I don't just need to play video files, I also need to draw sound waveforms while the video files are playing. Being able to play whatever movies is the first step I have to complete. I don't know whether your code can achieve my goals, but I think it will be useful to others and me. I really like to see different solutions.

  12. #12
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,137

    Re: MPV player into vb proyect, is possible...?

    Where to get the DLL, was hidden somewhere in the comments.
    Code:
    ' The dll is included in the DEV builds by lachs0r: https://mpv.srsfckn.biz/

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,864

    Re: MPV player into vb proyect, is possible...?

    Quote Originally Posted by dreammanor View Post
    Hi Elroy, thank you for your detailed reply. I don't just need to play video files, I also need to draw sound waveforms while the video files are playing. Being able to play whatever movies is the first step I have to complete. I don't know whether your code can achieve my goals, but I think it will be useful to others and me. I really like to see different solutions.
    Hi Dreammanor,

    Yeah, what I'm doing wouldn't be able to synchronize the waveforms. That's going to be complicated. If I were trying to do that, I'd still probably try to lean on the MPlayer.

    I'd probably try to write my own "front-end" for it in VB6, which would allow me to start, stop, pause, slow-motion, etcetera from my code. And then, I'd just deal with the waveform directly (with a PictureBox), which I suspect you're already doing.

    I'm just not familiar with the precision of MPlayer, and whether you can query it to get things like the precise timing of where it is upon a pause. You'd definitely need to do some testing to make sure your synchronization (between the movie (or sound) and the waveform) was dead-on.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  14. #14
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,864

    Re: MPV player into vb proyect, is possible...?

    Hi Dreammanor,

    Just to make one more comment after reading through your other thread ... personally the idea of DirectShow (using DX9) would be rather exciting to me. I haven't looked at it, but I suspect there may not be all that much to it. And then, you could manage everything from within VB6 (i.e., no need for any external video player).

    And then, you'd have total control, and could precisely check the synchronization between your waveform display and the movie.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  15. #15
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,139

    Re: MPV player into vb proyect, is possible...?

    Quote Originally Posted by DEXWERX View Post
    MPV.cls
    Code:
    Option Explicit
    
    Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryW" (ByVal lpLibFileName As Long) As Long
    Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Private Declare Function DispCallFunc Lib "oleaut32" (ByVal pvInstance As Long, ByVal oVft As Long, ByVal cc As Long, ByVal vtReturn As Integer, ByVal cActuals As Long, ByRef prgvt As Integer, ByRef prgpvarg As Long, ByRef pvargResult As Variant) As Long
    Private Declare Function SysAllocStringByteLen Lib "oleaut32" (ByVal psz As Long, ByVal cblen As Long) As Long
    Private Declare Function lstrlenA Lib "kernel32" (ByVal lpString As Long) As Long
    Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpWideCharStr As Any, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cbMultiByte As Long, Optional ByVal lpDefaultChar As Long, Optional ByVal lpUsedDefaultChar As Long) As Long
    Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cbMultiByte As Long, ByRef lpWideCharStr As Any, ByVal cchWideChar As Long) As Long
    Private Declare Function GetMem4 Lib "msvbvm60" (Src As Any, Dst As Any) As Long
    Private Const CP_UTF8 As Long = 65001
    Private Const MPV_FORMAT_STRING As Long = 1&
    
    Private m_Dll As Long
    Private m_Handle As Long
    
    Private Function ToUTF8(ByVal Str As String) As String ' String to String encoding...
        GetMem4 SysAllocStringByteLen(0&, WideCharToMultiByte(CP_UTF8, 0&, ByVal StrPtr(Str), Len(Str), ByVal 0&, 0&)), ByVal VarPtr(ToUTF8)
        WideCharToMultiByte CP_UTF8, 0&, ByVal StrPtr(Str), Len(Str), ByVal StrPtr(ToUTF8), LenB(ToUTF8)
    End Function
    
    Private Function FromUTF8Ptr(ByVal psz As Long) As String 'Ptr to String decoding
        FromUTF8Ptr = String$(MultiByteToWideChar(CP_UTF8, 0&, ByVal psz, lstrlenA(psz), ByVal 0&, 0&), vbNullChar)
        MultiByteToWideChar CP_UTF8, 0&, ByVal psz, lstrlenA(psz), ByVal StrPtr(FromUTF8Ptr), Len(FromUTF8Ptr)
    End Function
    
    Private Function MpvExport(ByVal Export As String) As Long
        Static Exports As New Collection
        On Error GoTo EH
        MpvExport = Exports(Export)
        On Error GoTo 0
        If MpvExport = 0 Then Err.Raise 5, "MpvExport()", "Can't find export: " & Export
        Exit Function
    EH: Exports.Add GetProcAddress(m_Dll, Export), Export
        Resume
    End Function
    
    Private Function MpvCall(ByVal Export As String, ByVal ReturnType As VbVarType, ParamArray Args())
        Const CC_CDECL As Long = 1&
        Const MAX_ARGS As Long = 8&
        Static VarTypes(MAX_ARGS) As Integer
        Static VarPtrs(MAX_ARGS) As Long
        Dim hRes As Long
        Dim Arg As Long
        Dim ByValArgs() As Variant
        
        ByValArgs = Args
        For Arg = 0 To UBound(ByValArgs)
            VarTypes(Arg) = VarType(ByValArgs(Arg))
            VarPtrs(Arg) = VarPtr(ByValArgs(Arg))
        Next
        
        hRes = DispCallFunc(0&, MpvExport(Export), CC_CDECL, ReturnType, Arg, VarTypes(0), VarPtrs(0), MpvCall)
        If hRes < 0 Then Err.Raise hRes, "MpvCall()"
    End Function
    
    Private Sub Class_Initialize()
        ' The dll is included in the DEV builds by lachs0r: https://mpv.srsfckn.biz/
        If m_Dll = 0 Then m_Dll = LoadLibrary(StrPtr("mpv-1.dll"))
        If m_Dll = 0 Then Err.Raise 17, "MPV.Class_Initialize()", "Failed to load mpv-1.dll"
        If m_Handle = 0 Then m_Handle = MpvCall("mpv_create", vbLong)
        If m_Handle = 0 Then Err.Raise 17, "mpv_create"
        If MpvCall("mpv_initialize", vbLong, m_Handle) Then Err.Raise 17, "mpv_initialize"
    End Sub
    
    Private Function MpvCommand(ParamArray Commands()) As Long
        Static Buffer() As String
        If m_Handle = 0 Then Exit Function
        ReDim Buffer(UBound(Commands) + 1)
        Dim Index As Long
        For Index = 0 To UBound(Commands)
            Buffer(Index) = ToUTF8(Commands(Index))
        Next
        Buffer(Index) = vbNullString
        MpvCommand = MpvCall("mpv_command", vbLong, m_Handle, VarPtr(Buffer(0)))
    End Function
    
    Private Property Let MpvOption(ByVal Name As String, ByVal Value As String)
        If m_Handle = 0 Then Exit Property 
        MpvCall "mpv_set_option_string", vbLong, m_Handle, StrPtr(ToUTF8(Name)), StrPtr(ToUTF8(Value))
    End Property
    
    Private Property Get MpvProperty(ByVal Name As String) As String
        Dim psz As Long
        If m_Handle = 0 Then Exit Property 
        MpvCall "mpv_get_property", vbLong, m_Handle, StrPtr(ToUTF8(Name)), MPV_FORMAT_STRING, VarPtr(psz)
        If psz Then MpvProperty = FromUTF8Ptr(psz)
        MpvCall "mpv_free", vbEmpty, psz
    End Property
    
    Private Property Let MpvProperty(ByVal Name As String, ByVal Value As String)
        If m_Handle = 0 Then Exit Property 
        MpvCall "mpv_set_property", vbLong, m_Handle, StrPtr(ToUTF8(Name)), MPV_FORMAT_STRING, VarPtr(ToUTF8(Value))
    End Property
    
    Public Sub Pause()
        MpvProperty("pause") = "yes"
    End Sub
    
    Public Sub Play()
        MpvProperty("pause") = "no"
    End Sub
    
    Public Function IsPaused() As Boolean
        If m_Handle Then
            IsPaused = (MpvProperty("pause") = "yes")
        Else
            IsPaused = True
        End If
    End Function
    
    Public Sub Load(File As String, hWnd As Long)
        Class_Terminate
        Class_Initialize
        MpvOption("keep-open") = "always"
        MpvOption("wid") = Str$(hWnd)
        MpvCommand "loadfile", File
    End Sub
    
    Public Sub SetTime(Value As Double)
        MpvCommand "seek", Str$(Value), "absolute"
    End Sub
    
    Private Sub Class_Terminate()
        If m_Handle Then
            MpvCall "mpv_terminate_destroy", vbLong, m_Handle
            m_Handle = 0
        End If
    End Sub
    NOTE: make sure you use an older dev build, if a recent version of mpv-1.dll doesn't work for you.
    Hi DEXWERX, thank you.

    I'd like to know Why can't the code use the latest dev build? I used the latest mpv-1.dll (2018-08-01). I got an error when executing "m_Handle = MpvCall("mpv_create", vbLong)":

    Run-time error '17':
    Can't perform requested operation


    Code:
    Private Sub Class_Initialize()
        ' The dll is included in the DEV builds by lachs0r: https://mpv.srsfckn.biz/
        If m_Dll = 0 Then m_Dll = LoadLibrary(StrPtr("mpv-1.dll"))
        If m_Dll = 0 Then Err.Raise 17, "MPV.Class_Initialize()", "Failed to load mpv-1.dll"
        If m_Handle = 0 Then m_Handle = MpvCall("mpv_create", vbLong)
        If m_Handle = 0 Then Err.Raise 17, "mpv_create"
        If MpvCall("mpv_initialize", vbLong, m_Handle) Then Err.Raise 17, "mpv_initialize"
    End Sub
    Last edited by dreammanor; Aug 31st, 2018 at 08:05 PM.

  16. #16
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,139

    Re: MPV player into vb proyect, is possible...?

    Quote Originally Posted by Elroy View Post
    Hi Dreammanor,

    Just to make one more comment after reading through your other thread ... personally the idea of DirectShow (using DX9) would be rather exciting to me. I haven't looked at it, but I suspect there may not be all that much to it. And then, you could manage everything from within VB6 (i.e., no need for any external video player).

    And then, you'd have total control, and could precisely check the synchronization between your waveform display and the movie.

    Good Luck,
    Elroy
    Hi Elroy, thank you for your advice. I'm testing and studying The trick's code about DirectShow.

  17. #17
    Junior Member
    Join Date
    Sep 2016
    Posts
    20

    Re: MPV player into vb proyect, is possible...?

    Hi DEXWERX,
    Thanks for MPV.cls. It works fine. May be you will improve this class in the future ?
    Regards

  18. #18
    Junior Member
    Join Date
    Sep 2016
    Posts
    20

    Re: MPV player into vb proyect, is possible...?

    Hi DEXWERX,
    Thanks for MPV.cls. It works fine. May be you will improve this class in the future ?
    Regards

  19. #19
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,137

    Re: MPV player into vb proyect, is possible...?

    The critical functions MpvCommand, MpvOption and the R/W MpvProperty - should be enough of framework to add whatever functionality is missing. Was there something specific you had in mind?

  20. #20
    Junior Member
    Join Date
    Sep 2016
    Posts
    20

    Re: MPV player into vb proyect, is possible...?

    For example: 'ao-volume' property was successed read but when i try to define a new value like:

    Public Sub SetVolume(Value As String)
    MpvProperty("ao-volume") = Value
    'here i send 20
    End Sub

    the Max Volume value stay definitely to 20 and i'm unable to reset it ?!?!

  21. #21
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,137

    Re: MPV player into vb proyect, is possible...?

    --volume=<value>
    Set the startup volume. 0 means silence, 100 means no volume reduction or amplification. Negative values can be passed for compatibility, but are treated as 0.

    Since mpv 0.18.1, this always controls the internal mixer (aka "softvol").
    ao-volume (RW)
    System volume. This property is available only if mpv audio output is currently active, and only if the underlying implementation supports volume control. What this option does depends on the API. For example, on ALSA this usually changes system-wide audio, while with PulseAudio this controls per-application volume.
    MPV.cls
    Code:
    Public Property Get Volume() As Long
        Volume = MpvProperty("volume")
    End Property
    Public Property Let Volume(ByVal Value As Long)
        MpvProperty("volume") = Value
    End Property
    Form?
    Code:
    Private Sub mnuVolDown_Click()
        Dim Vol As Long
        Vol = MPV.Volume
        If Vol > 0 Then
            Vol = Vol - 10
            MPV.Volume = Vol
        End If
    End Sub
    
    Private Sub mnuVolUp_Click()
        Dim Vol As Long
        Vol = MPV.Volume
        If Vol < 100 Then
            Vol = Vol + 10
            MPV.Volume = Vol
        End If
    End Sub
    Last edited by DEXWERX; Oct 8th, 2018 at 12:04 PM.

  22. #22
    Junior Member
    Join Date
    Sep 2016
    Posts
    20

    Re: MPV player into vb proyect, is possible...?

    Thank you so much DEXWERX now it is ok.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width