Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Martin Finkel
LibVLCSharp
Commits
5febe9fe
Commit
5febe9fe
authored
Oct 01, 2018
by
Martin Finkel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix media mrl UTF8 marshalling
(cherry picked from commit 18b1464145486812a63badccd76e11c5f5e243f5)
parent
814dd9a5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
8 deletions
+49
-8
LibVLCSharp.Tests/BaseSetup.cs
LibVLCSharp.Tests/BaseSetup.cs
+3
-0
LibVLCSharp.Tests/LibVLCSharp.Tests.csproj
LibVLCSharp.Tests/LibVLCSharp.Tests.csproj
+3
-0
LibVLCSharp.Tests/MediaTests.cs
LibVLCSharp.Tests/MediaTests.cs
+32
-1
LibVLCSharp.Tests/motörhead.mp3
LibVLCSharp.Tests/motörhead.mp3
+0
-0
LibVLCSharp/Shared/Media.cs
LibVLCSharp/Shared/Media.cs
+10
-6
LibVLCSharp/Shared/Utf8StringMarshaler.cs
LibVLCSharp/Shared/Utf8StringMarshaler.cs
+1
-1
No files found.
LibVLCSharp.Tests/BaseSetup.cs
View file @
5febe9fe
...
...
@@ -17,5 +17,8 @@ namespace LibVLCSharp.Tests
protected
string
RealMp3Path
=>
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
SetupInformation
.
ApplicationBase
,
"sample.mp3"
);
protected
string
RealMp3PathSpecialCharacter
=>
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
SetupInformation
.
ApplicationBase
,
"motörhead.mp3"
);
}
}
\ No newline at end of file
LibVLCSharp.Tests/LibVLCSharp.Tests.csproj
View file @
5febe9fe
...
...
@@ -17,6 +17,9 @@
<ProjectReference Include="..\LibVLCSharp\LibVLCSharp.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="motörhead.mp3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="sample.mp3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
...
...
LibVLCSharp.Tests/MediaTests.cs
View file @
5febe9fe
...
...
@@ -63,6 +63,7 @@ namespace LibVLCSharp.Tests
media
.
Parse
();
Assert
.
True
(
media
.
IsParsed
);
Assert
.
AreEqual
(
Media
.
MediaParsedStatus
.
Done
,
media
.
ParsedStatus
);
Assert
.
NotZero
(
media
.
Duration
);
using
(
var
mp
=
new
MediaPlayer
(
media
))
{
...
...
@@ -108,5 +109,35 @@ namespace LibVLCSharp.Tests
media
.
Parse
();
Assert
.
AreEqual
(
1
,
media
.
Tracks
);
}
[
Test
]
public
async
Task
CreateRealMediaSpecialCharacters
()
{
using
(
var
libVLC
=
new
LibVLC
())
{
libVLC
.
Log
+=
LibVLC_Log
;
using
(
var
media
=
new
Media
(
libVLC
,
RealMp3PathSpecialCharacter
,
Media
.
FromType
.
FromPath
))
{
Assert
.
False
(
media
.
IsParsed
);
media
.
Parse
();
await
Task
.
Delay
(
5000
);
Assert
.
True
(
media
.
IsParsed
);
Assert
.
AreEqual
(
Media
.
MediaParsedStatus
.
Done
,
media
.
ParsedStatus
);
using
(
var
mp
=
new
MediaPlayer
(
media
))
{
Assert
.
True
(
mp
.
Play
());
await
Task
.
Delay
(
10000
);
mp
.
Stop
();
}
}
libVLC
.
Log
-=
LibVLC_Log
;
}
}
private
void
LibVLC_Log
(
object
sender
,
LogEventArgs
e
)
{
System
.
Diagnostics
.
Debug
.
WriteLine
(
e
.
Message
);
}
}
}
}
\ No newline at end of file
LibVLCSharp.Tests/motörhead.mp3
0 → 100644
View file @
5febe9fe
File added
LibVLCSharp/Shared/Media.cs
View file @
5febe9fe
...
...
@@ -18,17 +18,17 @@ namespace LibVLCSharp.Shared
[
SuppressUnmanagedCodeSecurity
]
[
DllImport
(
Constants
.
LibraryName
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"libvlc_media_new_location"
)]
internal
static
extern
IntPtr
LibVLCMediaNewLocation
(
IntPtr
libVLC
,
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
string
mrl
);
internal
static
extern
IntPtr
LibVLCMediaNewLocation
(
IntPtr
libVLC
,
IntPtr
mrl
);
[
SuppressUnmanagedCodeSecurity
]
[
DllImport
(
Constants
.
LibraryName
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"libvlc_media_new_path"
)]
internal
static
extern
IntPtr
LibVLCMediaNewPath
(
IntPtr
libVLC
,
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
string
path
);
internal
static
extern
IntPtr
LibVLCMediaNewPath
(
IntPtr
libVLC
,
IntPtr
path
);
[
SuppressUnmanagedCodeSecurity
]
[
DllImport
(
Constants
.
LibraryName
,
CallingConvention
=
CallingConvention
.
Cdecl
,
EntryPoint
=
"libvlc_media_new_as_node"
)]
internal
static
extern
IntPtr
LibVLCMediaNewAsNode
(
IntPtr
libVLC
,
[
MarshalAs
(
UnmanagedType
.
LPStr
)]
string
name
);
internal
static
extern
IntPtr
LibVLCMediaNewAsNode
(
IntPtr
libVLC
,
IntPtr
name
);
[
SuppressUnmanagedCodeSecurity
]
[
DllImport
(
Constants
.
LibraryName
,
CallingConvention
=
CallingConvention
.
Cdecl
,
...
...
@@ -326,14 +326,18 @@ namespace LibVLCSharp.Shared
if
(
libVLC
==
null
)
throw
new
ArgumentNullException
(
nameof
(
libVLC
));
if
(
string
.
IsNullOrEmpty
(
mrl
))
throw
new
ArgumentNullException
(
nameof
(
mrl
));
var
mrlPtr
=
Utf8StringMarshaler
.
GetInstance
().
MarshalManagedToNative
(
mrl
);
if
(
mrlPtr
==
IntPtr
.
Zero
)
throw
new
ArgumentException
(
$"error marshalling
{
mrl
}
to UTF-8 for native interop"
);
switch
(
type
)
{
case
FromType
.
FromLocation
:
return
Native
.
LibVLCMediaNewLocation
(
libVLC
.
NativeReference
,
mrl
);
return
Native
.
LibVLCMediaNewLocation
(
libVLC
.
NativeReference
,
mrl
Ptr
);
case
FromType
.
FromPath
:
return
Native
.
LibVLCMediaNewPath
(
libVLC
.
NativeReference
,
mrl
);
return
Native
.
LibVLCMediaNewPath
(
libVLC
.
NativeReference
,
mrl
Ptr
);
case
FromType
.
AsNode
:
return
Native
.
LibVLCMediaNewAsNode
(
libVLC
.
NativeReference
,
mrl
);
return
Native
.
LibVLCMediaNewAsNode
(
libVLC
.
NativeReference
,
mrl
Ptr
);
default
:
return
IntPtr
.
Zero
;
}
...
...
LibVLCSharp/Shared/Utf8StringMarshaler.cs
View file @
5febe9fe
...
...
@@ -59,7 +59,7 @@ namespace LibVLCSharp.Shared
return
-
1
;
}
public
static
ICustomMarshaler
GetInstance
()
public
static
ICustomMarshaler
GetInstance
(
string
cookie
=
null
)
{
return
_instance
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment