ZeBobo5 / Vlc.DotNet

.NET control that hosts the audio/video capabilities of the VLC libraries
MIT License
945 stars 418 forks source link

SetMedia fails in PowerShell #330

Open tmontney opened 6 years ago

tmontney commented 6 years ago

As discussed on Gitter, the following code does not work in PowerShell. Tested in x86 and x64 PowerShell. PowerShell version is 5.1.15063.502, running Windows 10 x64 1703. Error is System.AccessViolationException (Vlc.DotNet.Core.Interops.VlcManager.GetMediaStats(Vlc.DotNet.Core.Interops.VlcMediaInstance) ).

Add-Type -Path ".\Other\VLC\Vlc.DotNet.Core.dll"
Add-Type -Path ".\Other\VLC\Vlc.DotNet.Core.Interops.dll"

$Cameras = New-Object System.Collections.ArrayList
$Test = New-Object System.Uri("rtsp://192.168.0.50/axis-media/media.amp?camera=1")
$Cameras.Add($Test)

$VlcLibDirPath = (Get-Location).Path + ".\Other\VLC\libvlc_x64"
$VlcLibDir = New-Object System.IO.DirectoryInfo($VlcLibDirPath)
$VlcOpt = "--rtsp-user=admin", "--rtsp-pwd=12345"
$Plyr = New-Object Vlc.DotNet.Core.VlcMediaPlayer($VlcLibDir, $VlcOpt)
for ($i=0; $i -lt $Cameras.Count; $i++)
{
    $Plyr.SetMedia($Cameras[$i]) #Fails here with System.AccessViolationException
    $Plyr.Play
    $Plyr.Stop
}
jeremyVignelles commented 6 years ago

A workaround has been posted here : https://stackoverflow.com/q/46779644/2663813 In a nutshell, you need to ignore the result of SetMedia if you don't use it:

[null]$Plyr.SetMedia($Cameras[$i]) 

or

$null = $Plyr.SetMedia($Cameras[$i]) 

It only solves a part of the issue : The library should not make access violation exceptions, even in case of a bad usage.

jeremyVignelles commented 6 years ago

Sent patch to the VideoLan's mailing list : https://mailman.videolan.org/pipermail/vlc-devel/2017-October/115858.html