Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Setting Audio.Outputs.Current property throws AccessViolationException (
Browse files Browse the repository at this point in the history
#493)

Fixes #492 

Thanks @Rukhlov
  • Loading branch information
Rukhlov authored and jeremyVignelles committed Jan 19, 2019
1 parent fcb247b commit f0d3e2a
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 13 deletions.
33 changes: 29 additions & 4 deletions src/Samples/Samples.WinForms.Advanced/Sample.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions src/Samples/Samples.WinForms.Advanced/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,42 @@
using Vlc.DotNet.Core.Interops.Signatures;
using Vlc.DotNet.Forms;

using System.Linq;
using System.Collections.Generic;

namespace Samples.WinForms.Advanced
{
public partial class Sample : Form
{
public Sample()
{
InitializeComponent();

if (myVlcControl.Audio != null)
{
var outputs = myVlcControl.Audio.Outputs;
if (outputs != null)
{

myCbxAudioOutputs.DataSource = new List<AudioOutputDescription>(outputs.All);
myCbxAudioOutputs.DisplayMember = "Description";
myCbxAudioOutputs.Enabled = true;
myCbxAudioOutputs.SelectedIndex = -1;
myCbxAudioOutputs.SelectedValueChanged += (o, a) =>
{
var val = myCbxAudioOutputs.SelectedValue;
if (val != null)
{
var output = val as AudioOutputDescription;
if (output != null)
{
outputs.Current = output;
}
}
};

}
}
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Samples/Samples.WinForms.MultiplePlayers/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
</startup>
</configuration>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ namespace Vlc.DotNet.Core.Interops.Signatures
/// </summary>
[LibVlcFunction("libvlc_audio_output_set")]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void SetAudioOutput(IntPtr mediaPlayerInstance, Utf8StringHandle audioOutputName);
internal delegate int SetAudioOutput(IntPtr mediaPlayerInstance, Utf8StringHandle audioOutputName);
}
8 changes: 4 additions & 4 deletions src/Vlc.DotNet.Core.Interops/VlcManager.SetAudioOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ namespace Vlc.DotNet.Core.Interops
{
public sealed partial class VlcManager
{
public void SetAudioOutput(AudioOutputDescriptionStructure output)
public int SetAudioOutput(VlcMediaPlayerInstance mediaPlayerInstance, AudioOutputDescriptionStructure output)
{
SetAudioOutput(output.Name);
return SetAudioOutput(mediaPlayerInstance, output.Name);
}

public void SetAudioOutput(string outputName)
public int SetAudioOutput(VlcMediaPlayerInstance mediaPlayerInstance, string outputName)
{
EnsureVlcInstance();

using (var outputInterop = Utf8InteropStringConverter.ToUtf8StringHandle(outputName))
{
GetInteropDelegate<SetAudioOutput>().Invoke(myVlcInstance, outputInterop);
return GetInteropDelegate<SetAudioOutput>().Invoke(mediaPlayerInstance, outputInterop);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Vlc.DotNet.Core/AudioOutputsManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public AudioOutputDescription Current
{
throw new NotSupportedException("Not implemented in LibVlc.");
}
set { myManager.SetAudioOutput(value.Name); }
set { myManager.SetAudioOutput(myMediaPlayerInstance, value.Name); }
}
}
}
5 changes: 5 additions & 0 deletions src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public IntPtr VideoHostControlHandle
set { Manager.SetMediaPlayerVideoHostHandle(myMediaPlayerInstance, value); }
}

public int SetAudioOutput(string outputName)
{
return this.Manager.SetAudioOutput(myMediaPlayerInstance, outputName);
}

public void Dispose()
{
Dispose(true);
Expand Down

0 comments on commit f0d3e2a

Please sign in to comment.