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
41b134c5
Commit
41b134c5
authored
Nov 28, 2018
by
Martin Finkel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add MediaPlayer and LibVLC overrides and tests
(cherry picked from commit
103ad604
)
parent
c55dd5f3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
5 deletions
+82
-5
LibVLCSharp.Tests/LibVLCTests.cs
LibVLCSharp.Tests/LibVLCTests.cs
+22
-1
LibVLCSharp.Tests/MediaPlayerTests.cs
LibVLCSharp.Tests/MediaPlayerTests.cs
+15
-0
LibVLCSharp/Shared/LibVLC.cs
LibVLCSharp/Shared/LibVLC.cs
+19
-4
LibVLCSharp/Shared/MediaPlayer.cs
LibVLCSharp/Shared/MediaPlayer.cs
+26
-0
No files found.
LibVLCSharp.Tests/
Instance
Tests.cs
→
LibVLCSharp.Tests/
LibVLC
Tests.cs
View file @
41b134c5
...
...
@@ -2,6 +2,7 @@
using
System.Diagnostics
;
using
System.IO
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
LibVLCSharp.Shared
;
using
NUnit.Framework
;
...
...
@@ -9,7 +10,7 @@ using NUnit.Framework;
namespace
LibVLCSharp.Tests
{
[
TestFixture
]
public
class
Instance
Tests
:
BaseSetup
public
class
LibVLC
Tests
:
BaseSetup
{
[
Test
]
public
void
DisposeInstanceNativeRelease
()
...
...
@@ -140,5 +141,25 @@ namespace LibVLCSharp.Tests
var
logs
=
File
.
ReadAllText
(
path
);
Assert
.
True
(
logs
.
StartsWith
(
"VLC media player"
));
}
[
Test
]
public
void
DisposeLibVLC
()
{
var
libvlc
=
new
LibVLC
();
libvlc
.
SetLog
((
data
,
logLevel
,
logContext
,
format
,
args
)
=>
{
});
libvlc
.
SetDialogHandlers
((
title
,
text
)
=>
Task
.
CompletedTask
,
(
dialog
,
title
,
text
,
defaultUsername
,
askStore
,
token
)
=>
Task
.
CompletedTask
,
(
dialog
,
title
,
text
,
type
,
cancelText
,
firstActionText
,
secondActonText
,
token
)
=>
Task
.
CompletedTask
,
(
dialog
,
title
,
text
,
indeterminate
,
position
,
cancelText
,
token
)
=>
Task
.
CompletedTask
,
(
dialog
,
position
,
text
)
=>
Task
.
CompletedTask
);
Assert
.
IsTrue
(
libvlc
.
DialogHandlersSet
);
libvlc
.
Dispose
();
Assert
.
AreEqual
(
IntPtr
.
Zero
,
libvlc
.
NativeReference
);
Assert
.
IsFalse
(
libvlc
.
DialogHandlersSet
);
}
}
}
\ No newline at end of file
LibVLCSharp.Tests/MediaPlayerTests.cs
View file @
41b134c5
...
...
@@ -156,5 +156,20 @@ namespace LibVLCSharp.Tests
callCountRegisterOne
++;
Debug
.
WriteLine
(
$"Mp_Playing called with
{
callCountRegisterOne
}
"
);
}
[
Test
]
public
async
Task
DisposeMediaPlayer
()
{
var
libvlc
=
new
LibVLC
();
var
mp
=
new
MediaPlayer
(
libvlc
);
mp
.
Play
(
new
Media
(
libvlc
,
"http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"
,
Media
.
FromType
.
FromLocation
));
await
Task
.
Delay
(
1000
);
mp
.
Dispose
();
Assert
.
AreEqual
(
IntPtr
.
Zero
,
mp
.
NativeReference
);
}
}
}
LibVLCSharp/Shared/LibVLC.cs
View file @
41b134c5
...
...
@@ -240,14 +240,25 @@ namespace LibVLCSharp.Shared
NativeToManagedMap
[
NativeReference
]
=
this
;
}
p
ublic
override
void
Dispose
()
p
rotected
override
void
Dispose
(
bool
disposing
)
{
if
(
_logCallback
!=
null
)
if
(
IsDisposed
||
NativeReference
==
IntPtr
.
Zero
)
return
;
if
(
disposing
)
{
UnsetLog
();
UnsetDialogHandlers
();
base
.
Dispose
();
UnsetDialogHandlers
();
}
base
.
Dispose
(
disposing
);
}
~
LibVLC
()
{
Dispose
(
false
);
}
public
static
bool
operator
==(
LibVLC
obj1
,
LibVLC
obj2
)
{
return
obj1
?.
NativeReference
==
obj2
?.
NativeReference
;
...
...
@@ -328,9 +339,13 @@ namespace LibVLCSharp.Shared
/// </remarks>
public
void
UnsetLog
()
{
if
(
_logCallback
==
null
)
return
;
Native
.
LibVLCLogUnset
(
NativeReference
);
if
(!
CloseLogFile
())
throw
new
VLCException
(
"Could not close log file"
);
_logCallback
=
null
;
}
public
void
UnsetDialogHandlers
()
...
...
LibVLCSharp/Shared/MediaPlayer.cs
View file @
41b134c5
...
...
@@ -1995,6 +1995,32 @@ namespace LibVLCSharp.Shared
}
#
endregion
protected
override
void
Dispose
(
bool
disposing
)
{
if
(
IsDisposed
||
NativeReference
==
IntPtr
.
Zero
)
return
;
if
(
disposing
)
{
if
(
IsPlaying
)
{
Stop
();
}
if
(
Media
!=
null
)
{
Media
.
Dispose
();
}
}
base
.
Dispose
(
disposing
);
}
~
MediaPlayer
()
{
Dispose
(
false
);
}
}
/// <summary>Description for titles</summary>
...
...
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