Interop and WPF & .NET 3.5

This forum is about all development around libVLC.
Tazzer
New Cone
New Cone
Posts: 2
Joined: 07 Sep 2009 11:42

Interop and WPF & .NET 3.5

Postby Tazzer » 07 Sep 2009 12:13

Hi,

I needed a decent Video playback engine for a small project I was doing and VLC is the best media player out there in my opinion.

I wanted to use VLC with WPF as the playback engine as MediaElement is rubbish. I've seen a lot of Interop wrappers but after a bit of research it is simple enough to Interop VLC into WPF so you don't need a 3rd party wrapper.

This is a decent article on how to interop media player
http://msdn.microsoft.com/en-us/library/ms748870.aspx

If your not aware, VS2005 & 2008 has a big bug with regards to Interop, unless you complile your Windows form control Interop wrapper with US regional settings the WPF designer crashes in Visual Studio although you can still run the code and edit the XAML manually. You need to change to US settings before you create wrapper project ! You can change back afterwards.

The problem is described here
http://connect.microsoft.com/VisualStud ... kID=392896

By following these steps you can get VLC into WPF quite nicely.

The VLC instance is defined here in XAML after adding the references to the project.

<Page x:Class="MovieSelect"
xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:ax="clr-namespace:AxAXVLC;assembly=AxInterop.AXVLC"
Title="MovieSelect" Name="pgMovieSelect" Focusable="True">
<Grid>
<WindowsFormsHost Name="wfh" Margin="0,0,0,0">
<ax:AxVLCPlugin2 x:Name="VLCPlayer" >

</ax:AxVLCPlugin2>
</WindowsFormsHost>
</Grid>
</Page>


You can then call it from your .cs or .vb file.

Dim strFilename As String

strFilename = "\\SERVER\Movies\Goodfellas.mpg"
Me.VLCPlayer.playlist.add(strFilename, Nothing, Nothing)
Me.VLCPlayer.playlist.play()

This works a treat and all the usual VLC ActiveX interfaces are exposed.

Maybe I'm missing something and this approach has some limitations but for media playback it works fine, it's simple enough to create the interop wrapper and it seems stable under XP (SP3) and Vista SP1. It doesn't seem to leak although I force a System.GC.Collect() periodically to clear up memory.

I'm using AxVLCPlugin21 wrapper. You need to reference axvlc.dll in the pluggin sub directory as well in your Windows Forms Control.

I not trying to suggest this method is better than the other wrappers as I know the creators have put a lot of hard work into them, I just thought I'd post a solution I found to the problem.

Tazzer
New Cone
New Cone
Posts: 2
Joined: 07 Sep 2009 11:42

Re: Interop and WPF & .NET 3.5 (ActiveX Reboot)

Postby Tazzer » 17 Sep 2009 12:10

Just a quick update on this.

The Interop to WPF has the same reboot issue when you dispose() the player, I seen this affecting people using the .NET activeX wrapper in VS 2005 & 2008.

I eventually got it stable by using the following steps

When playing get the handle returns:

lSleepWait=300 '// 300 milliseconds

sOptions = Split(My.Settings.MoviePlayerOptions, ";")
m_lMovieHnd = Me.VLCPlayer.playlist.add(sURL, oMediaQuery.First.media_name, sOptions)
Me.VLCPlayer.playlist.playItem(m_lMovieHnd)

I use the keydown event to stop the movie as it's a WPF RC driven app but query unload should work too in a windows forms application.


Me.VLCPlayer.playlist.stop()
Sleep(lSleepWait)
Me.VLCPlayer.playlist.items.remove(m_lMovieHnd)
Me.VLCPlayer.playlist.items.clear()
Sleep(m_lSleepWait)

** and finally

Private Sub Movieviewer_Unloaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Unloaded
Me.VLCPlayer.Dispose()
Sleep(m_lSleepWait)
End Sub


The sleep call is declared as follows:

Declare Auto Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

If you don't add these sleep() calls then you get a blue screen or the PC just reboots, I tested this on three different chipsets on XP and Vista and got the same result.

It seems that adding the sleep statements Gives the VLC ActiveX wrapper time to process and exit gracefully.

I would suggest making the sleep value application configurable.

Freebuster
New Cone
New Cone
Posts: 1
Joined: 23 Oct 2010 15:03

Re: Interop and WPF & .NET 3.5

Postby Freebuster » 23 Oct 2010 15:05

Please, could you post a complete project as an example ?
Thank you.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 14 guests