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:
Projekt im Anhang.
Diesmal das projekt von ErfinderDesRades da er wohl eine Virenfreie DLL gefunden hat
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
- Imports System
- Imports System.Collections
- Imports System.ComponentModel
- Imports System.Drawing
- Imports System.Runtime.InteropServices
- Imports System.Windows.Forms
- Imports DirectShowLib
- Public Class mainApp1
- Enum PlayState
- Stopped
- Paused
- Running
- Init
- End Enum
- Enum MediaType
- Audio
- Video
- End Enum
- Private Const WMGraphNotify As Integer = 13
- Private Const VolumeFull As Integer = 0
- Private Const VolumeSilence As Integer = -10000
- Private graphBuilder As IGraphBuilder = Nothing
- Private mediaControl As IMediaControl = Nothing
- Private mediaEventEx As IMediaEventEx = Nothing
- Private videoWindow As IVideoWindow = Nothing
- Private basicAudio As IBasicAudio = Nothing
- Private basicVideo As IBasicVideo = Nothing
- Private mediaSeeking As IMediaSeeking = Nothing
- Private mediaPosition As IMediaPosition = Nothing
- Private frameStep As IVideoFrameStep = Nothing
- Private filename As String = String.Empty
- Private isAudioOnly As Boolean = False
- Private isFullScreen As Boolean = False
- Private currentVolume As Integer = VolumeFull
- Private currentState As PlayState = PlayState.Stopped
- Private currentPlaybackRate As Double = 1.0
- Private UseHand As IntPtr
- Private UseCtrl As System.Windows.Forms.Control
- Private FsDrain As IntPtr = IntPtr.Zero
- Private Event MedClose()
- #If DEBUG Then
- Private rot As DsROTEntry = Nothing
- #End If
- '----------------Start--------------------------------------------------------
- Private Sub OpenFile(ByVal fName As String, ByVal VidHand As IntPtr, ByVal VidCtrl As System.Windows.Forms.Panel)
- filename = ""
- CloseClip()
- UseHand = VidHand 'Handle to Display Video if any
- UseCtrl = VidCtrl 'Control to Display Video if any
- filename = fName
- currentState = PlayState.Stopped 'Reset State to Stopped
- currentVolume = VolumeFull 'Reset Volume
- PlayMedia(fName) 'Call Main Sub
- End Sub
- Private Sub PlayMedia(ByVal fName As String)
- Dim hr As Integer = 0
- If fName = Nothing Then Exit Sub
- Try
- graphBuilder = DirectCast(New FilterGraph, IFilterGraph2) 'Load Graph Builder Device
- hr = graphBuilder.RenderFile(fName, Nothing) ' Initialize Graph Builder
- DsError.ThrowExceptionForHR(hr)
- mediaControl = DirectCast(graphBuilder, IMediaControl)
- mediaEventEx = DirectCast(graphBuilder, IMediaEventEx)
- mediaSeeking = DirectCast(graphBuilder, IMediaSeeking)
- mediaPosition = DirectCast(graphBuilder, IMediaPosition)
- videoWindow = DirectCast(graphBuilder, IVideoWindow)
- With videoWindow
- .put_Owner(Panel1.Handle)
- .put_AutoShow(OABool.True)
- .put_WindowState(DirectShowLib.WindowState.ShowMaximized)
- .put_WindowStyle(WindowStyle.Child Or WindowStyle.ClipSiblings Or WindowStyle.ClipChildren)
- End With
- 'videoWindow.put_WindowState(DirectShowLib.WindowState.ShowMaximized)
- basicAudio = DirectCast(graphBuilder, IBasicVideo)
- basicVideo = DirectCast(graphBuilder, IBasicAudio)
- If isAudioOnly = False Then
- hr = mediaEventEx.SetNotifyWindow(UseHand, WMGraphNotify, IntPtr.Zero)
- DsError.ThrowExceptionForHR(hr)
- hr = videoWindow.put_Owner(UseHand)
- DsError.ThrowExceptionForHR(hr)
- hr = videoWindow.put_WindowStyle(WindowStyle.Child And WindowStyle.ClipSiblings And WindowStyle.ClipChildren)
- DsError.ThrowExceptionForHR(hr)
- End If
- #If DEBUG Then
- rot = New DsROTEntry(graphBuilder)
- #End If
- Me.Focus()
- hr = mediaControl.Run
- DsError.ThrowExceptionForHR(hr)
- currentState = PlayState.Running
- If isAudioOnly = False Then
- DsError.ThrowExceptionForHR(hr)
- End If
- Catch ex As Exception
- MsgBox("Error " & ex.Message, MsgBoxStyle.Critical, "Error")
- RaiseEvent MedClose()
- End Try
- End Sub
- Private Sub CloseClip()
- Try
- Dim hr As Integer = 0
- currentState = PlayState.Stopped
- isAudioOnly = True
- isFullScreen = False
- filename = ""
- Call CloseInterfaces()
- currentState = PlayState.Init
- Catch ex As Exception
- MsgBox("Errpr " & ex.Message, MsgBoxStyle.Critical, "Error")
- RaiseEvent MedClose()
- End Try
- End Sub
- Private Sub CloseInterfaces()
- Try
- Dim hr As Integer = 0
- If isAudioOnly = False Then
- hr = videoWindow.put_Visible(OABool.False)
- DsError.ThrowExceptionForHR(hr)
- hr = videoWindow.put_Owner(IntPtr.Zero)
- DsError.ThrowExceptionForHR(hr)
- End If
- If mediaEventEx Is Nothing = False Then
- hr = mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero)
- DsError.ThrowExceptionForHR(hr)
- End If
- #If DEBUG Then
- If rot Is Nothing = False Then
- rot.Dispose()
- rot = Nothing
- End If
- #End If
- mediaEventEx = Nothing
- mediaSeeking = Nothing
- mediaPosition = Nothing
- mediaControl = Nothing
- basicAudio = Nothing
- basicVideo = Nothing
- videoWindow = Nothing
- frameStep = Nothing
- Marshal.ReleaseComObject(graphBuilder)
- graphBuilder = Nothing
- GC.Collect()
- Catch ex As Exception
- End Try
- End Sub
- Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- CloseClip()
- End Sub
- Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
- Dim TmpFileExt As String
- With OpenFileDialog1
- TmpFileExt = "Mp3 File(*.mp3)|*.mp3|Wav File(*.wav)|*.wav|Mpeg Video(*.mpg)|*.mpg|Windows Video(*.avi)|*.avi|Wmp Video(*.wmv)|*.wmv|All Files(*.*)|*.*"
- .Filter = TmpFileExt
- .Title = "Open Media File"
- .Multiselect = False
- .ShowDialog()
- End With
- TmpFileExt = Nothing
- End Sub
- Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
- CloseClip()
- filename = Nothing
- End Sub
- Private Sub StopToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- mediaControl.Stop()
- mediaPosition.put_CurrentPosition(0)
- End Sub
- Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
- 'If e.Cancel = True Then Exit Sub
- 'Call The Sub to Open the File. OpenFile(FilePath, Handle of Window, Control Name)
- 'OpenFile(OpenFileDialog1.FileName, Panel1.Handle, Panel1)
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- OpenFile(OpenFileDialog1.FileName, Panel1.Handle, Panel1)
- mediaControl.Run()
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- mediaControl.Pause()
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- mediaControl.Stop()
- mediaPosition.put_CurrentPosition(0)
- End Sub
- End Class
Projekt im Anhang.
Diesmal das projekt von ErfinderDesRades da er wohl eine Virenfreie DLL gefunden hat
![:)](https://www.vb-paradise.de/wcf/images/smilies/smile.png)