Directshow Problem

  • VB.NET

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von TheGameSiders.

    Directshow Problem

    Hi.

    Ich habe im Anhang ein Directshow Beispiel.

    Alles funktioniert auch.

    Ich möchte aber nun 2 Panel haben und 2 Verschiedene Videos abspielen können.
    Habe echt alles probiert aber nie hat es funktioniert.
    Ich kann nur 1 Video abspielen.
    Kann mir einer den Source unten so bearbeiten, dass das Panel1 Das Video vom Openfiledialog1 ist und im Panel2 das Video vom Openfiledialog2 ist oder das Projekt ändern?

    Das wäre sehr nett weil ich nicht mehr durchblicke..
    Habe schon alles verdoppelt und überall eine 2 hinter gemacht aber immer kommt dann "Keine Objektinstanz" etc. und nur das eine Panel spielt ab..
    Danke!

    Mfg. TGS

    Source:


    VB.NET-Quellcode

    1. Imports System
    2. Imports System.Collections
    3. Imports System.ComponentModel
    4. Imports System.Drawing
    5. Imports System.Runtime.InteropServices
    6. Imports System.Windows.Forms
    7. Imports DirectShowLib
    8. Public Class mainApp1
    9. Enum PlayState
    10. Stopped
    11. Paused
    12. Running
    13. Init
    14. End Enum
    15. Enum MediaType
    16. Audio
    17. Video
    18. End Enum
    19. Private Const WMGraphNotify As Integer = 13
    20. Private Const VolumeFull As Integer = 0
    21. Private Const VolumeSilence As Integer = -10000
    22. Private graphBuilder As IGraphBuilder = Nothing
    23. Private mediaControl As IMediaControl = Nothing
    24. Private mediaEventEx As IMediaEventEx = Nothing
    25. Private videoWindow As IVideoWindow = Nothing
    26. Private basicAudio As IBasicAudio = Nothing
    27. Private basicVideo As IBasicVideo = Nothing
    28. Private mediaSeeking As IMediaSeeking = Nothing
    29. Private mediaPosition As IMediaPosition = Nothing
    30. Private frameStep As IVideoFrameStep = Nothing
    31. Private filename As String = String.Empty
    32. Private isAudioOnly As Boolean = False
    33. Private isFullScreen As Boolean = False
    34. Private currentVolume As Integer = VolumeFull
    35. Private currentState As PlayState = PlayState.Stopped
    36. Private currentPlaybackRate As Double = 1.0
    37. Private UseHand As IntPtr
    38. Private UseCtrl As System.Windows.Forms.Control
    39. Private FsDrain As IntPtr = IntPtr.Zero
    40. Private Event MedClose()
    41. #If DEBUG Then
    42. Private rot As DsROTEntry = Nothing
    43. #End If
    44. '----------------Start--------------------------------------------------------
    45. Private Sub OpenFile(ByVal fName As String, ByVal VidHand As IntPtr, ByVal VidCtrl As System.Windows.Forms.Panel)
    46. filename = ""
    47. CloseClip()
    48. UseHand = VidHand 'Handle to Display Video if any
    49. UseCtrl = VidCtrl 'Control to Display Video if any
    50. filename = fName
    51. currentState = PlayState.Stopped 'Reset State to Stopped
    52. currentVolume = VolumeFull 'Reset Volume
    53. PlayMedia(fName) 'Call Main Sub
    54. End Sub
    55. Private Sub PlayMedia(ByVal fName As String)
    56. Dim hr As Integer = 0
    57. If fName = Nothing Then Exit Sub
    58. Try
    59. graphBuilder = DirectCast(New FilterGraph, IFilterGraph2) 'Load Graph Builder Device
    60. hr = graphBuilder.RenderFile(fName, Nothing) ' Initialize Graph Builder
    61. DsError.ThrowExceptionForHR(hr)
    62. mediaControl = DirectCast(graphBuilder, IMediaControl)
    63. mediaEventEx = DirectCast(graphBuilder, IMediaEventEx)
    64. mediaSeeking = DirectCast(graphBuilder, IMediaSeeking)
    65. mediaPosition = DirectCast(graphBuilder, IMediaPosition)
    66. videoWindow = DirectCast(graphBuilder, IVideoWindow)
    67. With videoWindow
    68. .put_Owner(Panel1.Handle)
    69. .put_AutoShow(OABool.True)
    70. .put_WindowState(DirectShowLib.WindowState.ShowMaximized)
    71. .put_WindowStyle(WindowStyle.Child Or WindowStyle.ClipSiblings Or WindowStyle.ClipChildren)
    72. End With
    73. 'videoWindow.put_WindowState(DirectShowLib.WindowState.ShowMaximized)
    74. basicAudio = DirectCast(graphBuilder, IBasicVideo)
    75. basicVideo = DirectCast(graphBuilder, IBasicAudio)
    76. If isAudioOnly = False Then
    77. hr = mediaEventEx.SetNotifyWindow(UseHand, WMGraphNotify, IntPtr.Zero)
    78. DsError.ThrowExceptionForHR(hr)
    79. hr = videoWindow.put_Owner(UseHand)
    80. DsError.ThrowExceptionForHR(hr)
    81. hr = videoWindow.put_WindowStyle(WindowStyle.Child And WindowStyle.ClipSiblings And WindowStyle.ClipChildren)
    82. DsError.ThrowExceptionForHR(hr)
    83. End If
    84. #If DEBUG Then
    85. rot = New DsROTEntry(graphBuilder)
    86. #End If
    87. Me.Focus()
    88. hr = mediaControl.Run
    89. DsError.ThrowExceptionForHR(hr)
    90. currentState = PlayState.Running
    91. If isAudioOnly = False Then
    92. DsError.ThrowExceptionForHR(hr)
    93. End If
    94. Catch ex As Exception
    95. MsgBox("Error " & ex.Message, MsgBoxStyle.Critical, "Error")
    96. RaiseEvent MedClose()
    97. End Try
    98. End Sub
    99. Private Sub CloseClip()
    100. Try
    101. Dim hr As Integer = 0
    102. currentState = PlayState.Stopped
    103. isAudioOnly = True
    104. isFullScreen = False
    105. filename = ""
    106. Call CloseInterfaces()
    107. currentState = PlayState.Init
    108. Catch ex As Exception
    109. MsgBox("Errpr " & ex.Message, MsgBoxStyle.Critical, "Error")
    110. RaiseEvent MedClose()
    111. End Try
    112. End Sub
    113. Private Sub CloseInterfaces()
    114. Try
    115. Dim hr As Integer = 0
    116. If isAudioOnly = False Then
    117. hr = videoWindow.put_Visible(OABool.False)
    118. DsError.ThrowExceptionForHR(hr)
    119. hr = videoWindow.put_Owner(IntPtr.Zero)
    120. DsError.ThrowExceptionForHR(hr)
    121. End If
    122. If mediaEventEx Is Nothing = False Then
    123. hr = mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero)
    124. DsError.ThrowExceptionForHR(hr)
    125. End If
    126. #If DEBUG Then
    127. If rot Is Nothing = False Then
    128. rot.Dispose()
    129. rot = Nothing
    130. End If
    131. #End If
    132. mediaEventEx = Nothing
    133. mediaSeeking = Nothing
    134. mediaPosition = Nothing
    135. mediaControl = Nothing
    136. basicAudio = Nothing
    137. basicVideo = Nothing
    138. videoWindow = Nothing
    139. frameStep = Nothing
    140. Marshal.ReleaseComObject(graphBuilder)
    141. graphBuilder = Nothing
    142. GC.Collect()
    143. Catch ex As Exception
    144. End Try
    145. End Sub
    146. Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    147. CloseClip()
    148. End Sub
    149. Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
    150. Dim TmpFileExt As String
    151. With OpenFileDialog1
    152. TmpFileExt = "Mp3 File(*.mp3)|*.mp3|Wav File(*.wav)|*.wav|Mpeg Video(*.mpg)|*.mpg|Windows Video(*.avi)|*.avi|Wmp Video(*.wmv)|*.wmv|All Files(*.*)|*.*"
    153. .Filter = TmpFileExt
    154. .Title = "Open Media File"
    155. .Multiselect = False
    156. .ShowDialog()
    157. End With
    158. TmpFileExt = Nothing
    159. End Sub
    160. Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
    161. CloseClip()
    162. filename = Nothing
    163. End Sub
    164. Private Sub StopToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    165. mediaControl.Stop()
    166. mediaPosition.put_CurrentPosition(0)
    167. End Sub
    168. Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
    169. 'If e.Cancel = True Then Exit Sub
    170. 'Call The Sub to Open the File. OpenFile(FilePath, Handle of Window, Control Name)
    171. 'OpenFile(OpenFileDialog1.FileName, Panel1.Handle, Panel1)
    172. End Sub
    173. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    174. OpenFile(OpenFileDialog1.FileName, Panel1.Handle, Panel1)
    175. mediaControl.Run()
    176. End Sub
    177. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    178. mediaControl.Pause()
    179. End Sub
    180. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    181. mediaControl.Stop()
    182. mediaPosition.put_CurrentPosition(0)
    183. End Sub
    184. End Class


    Projekt im Anhang.
    Diesmal das projekt von ErfinderDesRades da er wohl eine Virenfreie DLL gefunden hat :)
    Dateien
    • Directshow.rar

      (375,32 kB, 52 mal heruntergeladen, zuletzt: )
    Kann mir da keiner helfen?
    Was muss ich denn alles ändern, um ein 2 mal ein video öffnen zu können in einem neuen panel?

    Alles gut, habs geschafft :)
    Hatte vergessen bei einem Sub eine 2 hinter zu machen!

    Mfg. TGS

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „TheGameSiders“ ()