UserControl in Visual Basic



  • Hallo

    ich wollte mir ein UserControl in Visual Basic erstellen, mit dem ich dank Marx VlcWrapper dann Filme abspielen kann.

    Imports WinControls.VlcWrapper
    Imports System.IO
    Imports System.Reflection
    
    Namespace WinControls.VlcControl
        Public Enum PlayerState
            NothingSpecial = 0
            Opening
            Buffering
            Playing
            Paused
            Stopped
            Forward
            Backward
            Ended
            ErrorState
        End Enum
    
    Public Partial Class VLCWrapperControl 
    Inherits UserControl
    
        Private libvlc_media As Marx_libvlc_media               = Nothing
        Private libvlc_media_player As Marx_libvlc_media_player = Nothing
        Private libvlc_core As Marx_libvlc_core                 = Nothing
        Private working As Boolean                              = False
        Private ex As libvlc_exception_struct                   = New libvlc_exception_struct()
        Private exClass As Marx_libvlc_exception                = Nothing
        Private dllInstallDirectory As String                   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Substring(6)
    
        Private standardArgs As ArrayList = New ArrayList(New String() { _
                "-I", _
                "test", _
                "--dummy-quiet", _
                "--quiet-synchro", _
                "--quiet", _
                "-v0", _
                "--ignore-config", _
                "--no-one-instance", _
                "--no-loop", _
                "--no-osd", _
                "--drop-late-frames", _
                "--no-drop-late-frames", _
                "--disable-screensaver", _
                "--vout", _
                "vout_direct3d", _
                "vout_directx", _
                "--no-plugins-cache", _
                "--plugin-path", _
                dllInstallDirectory + "\plugins" _
        })
    
        Property Args() As ArrayList
            Get
                Args = StandardArgs
            End Get
            Set(ByVal value As ArrayList)
                If Not IsNothing(value) Then
                    StandardArgs = value
                End If
            End Set
        End Property
    
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Sub HandleResponseNet(ByVal method As String, ByVal exnet As Exception)
            System.Diagnostics.Debug.Write("Error in libVLC" + _
             IIf(String.IsNullOrEmpty(method), "", "(" + method + ")") + _
                        ": " + _
                        exnet.Message + _
                        IIf(exnet.TargetSite Is Nothing, " ", exnet.TargetSite.Name) + _
                        IIf(exnet.InnerException Is Nothing, "", exnet.InnerException.ToString()))
        End Sub
    
        Private Sub arbeit(ByVal work As Boolean)
            working = work
        End Sub
    
        Public ReadOnly Property IsPlaying() As Boolean
            Get
                If Me.State = PlayerState.Playing Then
                    IsPlaying = True
                Else
                    IsPlaying = False
                End If
            End Get
        End Property
    
        Public ReadOnly Property IsPaused() As Boolean
            Get
                If Me.State = PlayerState.Paused Then
                    IsPaused = True
                Else
                    IsPaused = False
                End If
            End Get
        End Property
    
        Public ReadOnly Property IsPlayingOrIsPaused() As Boolean
            Get
                If Me.State = PlayerState.Playing Or Me.State = PlayerState.Paused Then
                    IsPlayingOrIsPaused = True
                Else
                    IsPlayingOrIsPaused = False
                End If
            End Get
        End Property
    
        Public ReadOnly Property busy() As Boolean
            Get
                busy = working
            End Get
        End Property
    
        Public ReadOnly Property State() As PlayerState
            Get
                Dim res As PlayerState = PlayerState.NothingSpecial
                State = res
                Try
                    If Not IsNothing(Me.libvlc_media_player) Then
                        Dim i As libvlc_state_t = Me.libvlc_media_player.get_state(ex)
    
                        Select Case i
                            Case libvlc_state_t.libvlc_Stopped
                                res = PlayerState.Stopped
                            Case libvlc_state_t.libvlc_Paused
                                res = PlayerState.Paused
                            Case libvlc_state_t.libvlc_Playing
                                res = PlayerState.Playing
                        End Select
                    End If
                Catch excp As Exception
                    Me.HandleResponseNet("State", excp)
                End Try
                State = res
            End Get
        End Property
    
        Public Function AddMedia(ByVal media As String, ByVal options As String) As IntPtr
            AddMedia = Nothing
            If working Then
                Return Nothing
                Me.arbeit(True)
            End If
    
            Try
                Dim hDT As IntPtr       = Me.Handle
                Dim forceGC As Boolean  = False
    
                If IsNothing(libvlc_media_player) Then
                    libvlc_media_player.Handle.Dispose()
                    libvlc_media_player = Nothing
                    forceGC = true
                End If
    
                If IsNothing(libvlc_media) Then
                    libvlc_media.Handle.Dispose()
                    libvlc_media = Nothing
                    forceGC = true
                End If
    
                If IsNothing(libvlc_core) Then
                    libvlc_core.Handle.Dispose()
                    libvlc_core = Nothing
                    forceGC = true
                End If
    
                Dim opz As ArrayList = CType(Args.Clone(), ArrayList)
                If Not(String.IsNullOrEmpty(options)) Then
                    Dim s As String
                    For Each s In options.Split("\n")
                        opz.Add(s)
                    Next
                End If
    
                Dim aopz() As String = CType(opz.ToArray(GetType(String)), String())
                libvlc_core = new Marx_libvlc_core(aopz, ex)
    
                libvlc_media = new Marx_libvlc_media(libvlc_core.Handle, media, ex)
                libvlc_media_player = new Marx_libvlc_media_player(libvlc_media.Handle, ex)
    
                If IsNothing(libvlc_media) Then
                    libvlc_media.Handle.Dispose()
                    libvlc_media = Nothing
                    forceGC = true
                End If
    
                If (forceGC) Then
                    GC.Collect()
                    GC.WaitForPendingFinalizers()
                End If
    
               AddMedia = hDT
            Catch excp As Exception
                Me.HandleResponseNet("AddMedia", excp)
    
            Finally
                Me.arbeit(False)
            End Try
    
        End Function
    
        Public Sub Play(hDt As IntPtr)
             #If DEPRECATED
                    libvlc_media_player.play(ex)
                    libvlc_media_player.video_set_parent(libvlc_core.Handle, hDT, ex)
                    exClass.clear(ex)
            #Else
                    libvlc_media_player.set_drawable(hDT, ex)
                    libvlc_media_player.play(ex)
            #End If
        End Sub
    
        Public Sub StopPlay()
            If (working) Then
                Return
            End If
            Me.arbeit(True)
            Try
                If Not IsNothing(Me.libvlc_media_player) Then
                    Me.libvlc_media_player.stop(ex)
                End If
            Catch excp As Exception
                Me.HandleResponseNet("Stop", excp)
            End Try
            Me.arbeit(False)
        End Sub
    
        Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
            MyBase.OnLoad(e)
            If Not Me.DesignMode And Me.Parent Is Nothing Then
                exClass = New Marx_libvlc_exception(ex)
            End If
        End Sub
    
        Private Sub InitializeComponent()
                Me.SuspendLayout()
                '
                'VLCWapperControl
                '
                Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
                Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
                Me.Name = "VLCWapperControl"
                Me.ResumeLayout(False)
    
            End Sub
    End Class
    End Namespace
    

    Versuche ich nun mein Projekt zu testen sagt mir Visual Studio das das Projekt das falsche Format hat.

    Das Projekt ohne meinen Code funktioniert allerdings. Füge ich aber zu dem Funktionierenden Code eine Codezeile wie diese
    Private libvlc_core As Marx_libvlc_core = Nothing
    hinzu kann das Projekt nicht mehr ausgeführt werden.

    Jemand eine Idee an was das leigen kann?

    Danke



  • lol ... wieso schreibst du dass denn in ein C# Forum?



  • weil mir langweilig ist 😃

    Ne weil ich dachte das ist das C# und .Net Forum und ich dachte das ist ja nicht unbedingt ein Visual Basic Problem sondern vielmehr eine Einstellungssache im Visual Studio



  • funktioniert nun wieso weiß ich allerdings auch nicht 😕


Anmelden zum Antworten