Skip to content

Commit 5fff418

Browse files
committed
Tested and succeeded playing issue #531
Addressing #526 Upgrading to dot net 5.0
1 parent 9ddfae1 commit 5fff418

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+389
-388
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*.cs]
4+
indent_style = space
5+
indent_size = 4
6+
7+
# CA2000: Dispose objects before losing scope
8+
dotnet_diagnostic.CA2000.severity = suggestion

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- If you would like to support this project, you can show your appreciation via [PayPal.Me](https://www.paypal.me/mariodivece/50usd)
1616
- Current Status: (2019-12-28) - Release 4.2.330 is now available, (see the <a href="https://github.com/unosquare/ffmediaelement/releases">Releases</a>)
1717
- NuGet Package available here: https://www.nuget.org/packages/FFME.Windows/
18-
- FFmpeg Version: 4.2.1 <a href="https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.2.1-win32-shared.zip">32-bit</a> or <a href="https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.2.1-win64-shared.zip">64-bit</a>
18+
- FFmpeg Version: <a href="https://ffmpeg.org/download.html">4.3.1</a> -- Make sure you download one built as a SHARED library and for your right architecture (typically x64)
1919
- BREAKING CHANGE: Starting realease 4.1.320 the `Source` dependency property has been downgraded to a notification property. Please use the asynchronous `Open` and `Close` methods instead.
2020

2121
*Please note the current NuGet realease might require a different version of the FFmpeg binaries than the ones of the current state of the source code.*
@@ -25,7 +25,7 @@
2525
Here is a quick guide on how to get started.
2626
1. Open Visual Studio (v2019 preview recommended), and create a new WPF Application. Target Framework must be 4.6.1 or above, or .Net Core 3.0 or above.
2727
2. Install the NuGet Package from your Package Manager Console: `PM> Install-Package FFME.Windows`
28-
3. You need FFmpeg **shared** binaries (64 or 32 bit, depending on your app's target architecture). Build your own or download a compatible build from [Zeranoe FFmpeg Builds site](https://ffmpeg.zeranoe.com/builds/).
28+
3. You need FFmpeg **shared** binaries (64 or 32 bit, depending on your app's target architecture). Build your own or download a compatible build from [FFmpeg Windows Downloads](https://ffmpeg.org/download.html).
2929
4. Your FFmpeg build should have a `bin` folder with 3 exe files and some dll files. Copy all those files to a folder such as `c:\ffmpeg`
3030
5. Within you application's startup code (`Main` method), set `Unosquare.FFME.Library.FFmpegDirectory = @"c:\ffmpeg";`.
3131
6. Use the FFME `MediaElement` control as any other WPF control.
@@ -96,7 +96,7 @@ A high-level diagram is provided as additional reference below.
9696
*Please note that I am unable to distribute FFmpeg's binaries because I don't know if I am allowed to do so. Follow the instructions below to compile, run and test FFME.*
9797

9898
1. Clone this repository and make sure you have <a href="https://dotnet.microsoft.com/download/dotnet-core/3.1">.Net Core 3.1 or above</a> installed.
99-
2. Download the FFmpeg **shared** binaries for your target architecture: <a href="https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.2.1-win32-shared.zip">32-bit</a> or <a href="https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.2.1-win64-shared.zip">64-bit</a>.
99+
2. Download the FFmpeg **shared** binaries for your target architecture: <a href="https://ffmpeg.org/download.html">FFmpeg Windows Downloads</a>.
100100
3. Extract the contents of the <code>zip</code> file you just downloaded and go to the <code>bin</code> folder that got extracted. You should see 3 <code>exe</code> files and multiple <code>dll</code> files. Select and copy all of them.
101101
4. Now paste all files from the prior step onto a well-known folder. Take note of the full path. (I used `c:\ffmpeg\`)
102102
5. Open the solution and set the <code>Unosquare.FFME.Windows.Sample</code> project as the startup project. You can do this by right clicking on the project and selecting <code>Set as startup project</code>. Please note that you will need Visual Studio 2019 with dotnet Core 3.0 SDK for your target architecture installed.
@@ -139,7 +139,6 @@ The source code for this project contains a very capable media player (`FFME.Win
139139
*In no particular order*
140140

141141
- To the <a href="http://ffmpeg.org/">FFmpeg team</a> for making the Swiss Army Knife of media. I encourage you to donate to them.
142-
- To Kyle Schwarz for creating and making <a href="http://ffmpeg.zeranoe.com/builds/">Zeranoe FFmpeg builds available to everyone</a>.
143142
- To the <a href="https://github.com/naudio/NAudio">NAudio</a> team for making the best audio library out there for .NET -- one day I will contribute some improvements I have noticed they need.
144143
- To Ruslan Balanukhin for his FFmpeg interop bindings generator tool: <a href="https://github.com/Ruslan-B/FFmpeg.AutoGen">FFmpeg.AutoGen</a>.
145144
- To Martin Bohme for his <a href="http://dranger.com/ffmpeg/">tutorial</a> on creating a video player with FFmpeg.

Support/nugetdoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Here is a quick guide on how to get started.
22
1. Open Visual Studio (v2019 recommended), and create a new WPF Application. Target Framework must be .Net Core 3+ or .Net Framework 4.6.1+.
33
2. Install the NuGet Package from your Package Manager Console: `PM> Install-Package FFME.Windows`
4-
3. You need FFmpeg **shared** binaries (64 or 32 bit, depending on your app's target architecture). Build your own or download a compatible build from [Zeranoe FFmpeg Builds site](https://ffmpeg.zeranoe.com/builds/).
4+
3. You need FFmpeg **shared** binaries (64 or 32 bit, depending on your app's target architecture). Build your own or download a compatible build from [FFmpeg Windows Downloads](https://ffmpeg.org/download.html).
55
4. Your FFmpeg build should have a `bin` folder with 3 exe files and some dll files. Copy all those files to a folder such as `c:\ffmpeg`
66
5. Within you application's startup code (`Main` method), set `Unosquare.FFME.Library.FFmpegDirectory = @"c:\ffmpeg";`.
77
6. Use the FFME `MediaElement` control as any other WPF control.

Support/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ How to use FFME
33
In order to use the FFME MediaElement control, you will need to setup a folder with FFmpeg binaries and point to it from your application code.
44
Here are the steps:
55

6-
1. You can build your own FFmpeg shared binaries or download a compatible build from the wonderful Zeranoe FFmpeg Builds site: (https://ffmpeg.zeranoe.com/).
6+
1. You can build your own FFmpeg **shared** binaries or download a compatible build from the FFmpeg Windows Downloads page: (https://ffmpeg.org/download.html).
77
2. Your FFmpeg build (see the bin folder) should have 3 exe files and a number of dll files and must match your app's architecture (32-bit or 64-bit). Copy all of them to a folder such as (c:\ffmpeg)
88
3. Within you application's startup code (Main method), set Unosquare.FFME.Library.FFmpegDirectory = @"path to ffmpeg binaries from the previous step";.
99
4. Use the FFME MediaElement control as any other WPF control!

Unosquare.FFME.MediaElement/MediaElement.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public partial class MediaElement : ILoggingHandler, ILoggingSource, INotifyProp
2929
/// <returns>The awaitable command.</returns>
3030
public ConfiguredTaskAwaitable<bool> ChangeMedia() => Task.Run(async () =>
3131
{
32-
try { return await MediaCore.ChangeMedia(); }
32+
try { return await MediaCore.ChangeMedia().ConfigureAwait(false); }
3333
catch (Exception ex) { PostMediaFailedEvent(ex); }
3434
return false;
3535
}).ConfigureAwait(true);
@@ -40,7 +40,7 @@ public ConfiguredTaskAwaitable<bool> ChangeMedia() => Task.Run(async () =>
4040
/// <returns>The awaitable command.</returns>
4141
public ConfiguredTaskAwaitable<bool> Play() => Task.Run(async () =>
4242
{
43-
try { return await MediaCore.Play(); }
43+
try { return await MediaCore.Play().ConfigureAwait(false); }
4444
catch (Exception ex) { PostMediaFailedEvent(ex); }
4545
return false;
4646
}).ConfigureAwait(true);
@@ -51,7 +51,7 @@ public ConfiguredTaskAwaitable<bool> Play() => Task.Run(async () =>
5151
/// <returns>The awaitable command.</returns>
5252
public ConfiguredTaskAwaitable<bool> Pause() => Task.Run(async () =>
5353
{
54-
try { return await MediaCore.Pause(); }
54+
try { return await MediaCore.Pause().ConfigureAwait(false); }
5555
catch (Exception ex) { PostMediaFailedEvent(ex); }
5656
return false;
5757
}).ConfigureAwait(true);
@@ -62,7 +62,7 @@ public ConfiguredTaskAwaitable<bool> Pause() => Task.Run(async () =>
6262
/// <returns>The awaitable command.</returns>
6363
public ConfiguredTaskAwaitable<bool> Stop() => Task.Run(async () =>
6464
{
65-
try { return await MediaCore.Stop(); }
65+
try { return await MediaCore.Stop().ConfigureAwait(false); }
6666
catch (Exception ex) { PostMediaFailedEvent(ex); }
6767
return false;
6868
}).ConfigureAwait(true);
@@ -75,7 +75,7 @@ public ConfiguredTaskAwaitable<bool> Stop() => Task.Run(async () =>
7575
/// <returns>The awaitable command.</returns>
7676
public ConfiguredTaskAwaitable<bool> Seek(TimeSpan target) => Task.Run(async () =>
7777
{
78-
try { return await MediaCore.Seek(target); }
78+
try { return await MediaCore.Seek(target).ConfigureAwait(false); }
7979
catch (Exception ex) { PostMediaFailedEvent(ex); }
8080
return false;
8181
}).ConfigureAwait(true);
@@ -86,7 +86,7 @@ public ConfiguredTaskAwaitable<bool> Seek(TimeSpan target) => Task.Run(async ()
8686
/// <returns>The awaitable command.</returns>
8787
public ConfiguredTaskAwaitable<bool> StepForward() => Task.Run(async () =>
8888
{
89-
try { return await MediaCore.StepForward(); }
89+
try { return await MediaCore.StepForward().ConfigureAwait(false); }
9090
catch (Exception ex) { PostMediaFailedEvent(ex); }
9191
return false;
9292
}).ConfigureAwait(true);
@@ -97,7 +97,7 @@ public ConfiguredTaskAwaitable<bool> StepForward() => Task.Run(async () =>
9797
/// <returns>The awaitable command.</returns>
9898
public ConfiguredTaskAwaitable<bool> StepBackward() => Task.Run(async () =>
9999
{
100-
try { return await MediaCore.StepBackward(); }
100+
try { return await MediaCore.StepBackward().ConfigureAwait(false); }
101101
catch (Exception ex) { PostMediaFailedEvent(ex); }
102102
return false;
103103
}).ConfigureAwait(true);
@@ -111,7 +111,7 @@ public ConfiguredTaskAwaitable<bool> StepBackward() => Task.Run(async () =>
111111
/// <returns>The awaitable task.</returns>
112112
public ConfiguredTaskAwaitable<bool> Open(Uri uri) => Task.Run(async () =>
113113
{
114-
try { return await MediaCore.Open(uri); }
114+
try { return await MediaCore.Open(uri).ConfigureAwait(false); }
115115
catch (Exception ex) { PostMediaFailedEvent(ex); }
116116

117117
return false;
@@ -124,7 +124,7 @@ public ConfiguredTaskAwaitable<bool> Open(Uri uri) => Task.Run(async () =>
124124
/// <returns>The awaitable task.</returns>
125125
public ConfiguredTaskAwaitable<bool> Open(IMediaInputStream stream) => Task.Run(async () =>
126126
{
127-
try { return await MediaCore.Open(stream); }
127+
try { return await MediaCore.Open(stream).ConfigureAwait(false); }
128128
catch (Exception ex) { PostMediaFailedEvent(ex); }
129129

130130
return false;
@@ -136,7 +136,7 @@ public ConfiguredTaskAwaitable<bool> Open(IMediaInputStream stream) => Task.Run(
136136
/// <returns>The awaitable command.</returns>
137137
public ConfiguredTaskAwaitable<bool> Close() => Task.Run(async () =>
138138
{
139-
try { return await MediaCore.Close(); }
139+
try { return await MediaCore.Close().ConfigureAwait(false); }
140140
catch (Exception ex) { PostMediaFailedEvent(ex); }
141141

142142
return false;

Unosquare.FFME.MediaElement/Platform/MediaConnector.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ public void OnMediaEnded(MediaEngine sender)
4747

4848
if (behavior == MediaPlaybackState.Close)
4949
{
50-
await sender.Close();
50+
await sender.Close().ConfigureAwait(true);
5151
}
5252
else if (behavior == MediaPlaybackState.Play)
5353
{
54-
await sender.Stop();
55-
await sender.Play();
54+
await sender.Stop().ConfigureAwait(true);
55+
await sender.Play().ConfigureAwait(true);
5656
}
5757
else if (behavior == MediaPlaybackState.Stop)
5858
{
59-
await sender.Stop();
59+
await sender.Stop().ConfigureAwait(true);
6060
}
6161
});
6262
}
@@ -88,14 +88,14 @@ public void OnMediaOpened(MediaEngine sender, MediaInfo mediaInfo)
8888
// Start playback if we don't support pausing
8989
if (sender.State.CanPause == false)
9090
{
91-
await sender.Play();
91+
await sender.Play().ConfigureAwait(true);
9292
return;
9393
}
9494

9595
if (Parent.LoadedBehavior == MediaPlaybackState.Play)
96-
await sender.Play();
96+
await sender.Play().ConfigureAwait(true);
9797
else if (Parent.LoadedBehavior == MediaPlaybackState.Pause)
98-
await sender.Pause();
98+
await sender.Pause().ConfigureAwait(true);
9999
}
100100
finally
101101
{

Unosquare.FFME.Windows.Sample/.editorconfig

Lines changed: 0 additions & 5 deletions
This file was deleted.

Unosquare.FFME.Windows.Sample/App.xaml.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public partial class App
2020
public App()
2121
{
2222
// Change the default location of the ffmpeg binaries (same directory as application)
23-
// You can get the 32-bit binaries here: https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.2.1-win32-shared.zip
24-
// You can get the 64-bit binaries here: https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.2.1-win64-shared.zip
23+
// You can get the 64-bit binaries here: https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z
2524
Library.FFmpegDirectory = @"c:\ffmpeg" + (Environment.Is64BitProcess ? @"\x64" : string.Empty);
2625

2726
// You can pick which FFmpeg binaries are loaded. See issue #28
@@ -34,7 +33,7 @@ public App()
3433
// dispatcher threads to render video frames. This is an experimental feature
3534
// and might become deprecated in the future as no real performance enhancements
3635
// have been detected.
37-
Library.EnableWpfMultiThreadedVideo = !Debugger.IsAttached; // test with true and false
36+
Library.EnableWpfMultiThreadedVideo = false; // !Debugger.IsAttached; // test with true and false
3837
}
3938

4039
/// <summary>
@@ -101,7 +100,7 @@ await dispatcher.BeginInvoke(new Action(() =>
101100
$"Unable to Load FFmpeg Libraries from path:\r\n {Library.FFmpegDirectory}" +
102101
$"\r\nMake sure the above folder contains FFmpeg shared binaries (dll files) for the " +
103102
$"applicantion's architecture ({(Environment.Is64BitProcess ? "64-bit" : "32-bit")})" +
104-
$"\r\nTIP: You can download builds from https://ffmpeg.zeranoe.com/builds/" +
103+
$"\r\nTIP: You can download builds from https://ffmpeg.org/download.html" +
105104
$"\r\n{ex.GetType().Name}: {ex.Message}\r\n\r\nApplication will exit.",
106105
"FFmpeg Error",
107106
MessageBoxButton.OK,

Unosquare.FFME.Windows.Sample/Foundation/CustomPlaylistEntryCollection.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// </summary>
1313
public class CustomPlaylistEntryCollection : PlaylistEntryCollection<CustomPlaylistEntry>
1414
{
15-
private readonly object SyncRoot = new object();
15+
private readonly object SyncRoot = new();
1616
private readonly PlaylistViewModel ViewModel;
1717

1818
/// <summary>
@@ -66,6 +66,8 @@ public CustomPlaylistEntry FindEntryByMediaSource(Uri mediaSource)
6666
/// <param name="info">The media information.</param>
6767
public void AddOrUpdateEntry(Uri mediaSource, MediaInfo info)
6868
{
69+
if (info == null) throw new ArgumentNullException(nameof(info));
70+
6971
lock (SyncRoot)
7072
{
7173
var entry = FindEntryByMediaSource(mediaSource);
@@ -115,7 +117,7 @@ public void AddOrUpdateEntry(Uri mediaSource, MediaInfo info)
115117
foreach (var c in metaKey)
116118
{
117119
if (char.IsWhiteSpace(c))
118-
sb.Append("-");
120+
sb.Append('-');
119121
else
120122
sb.Append(c);
121123
}
@@ -134,6 +136,8 @@ public void AddOrUpdateEntry(Uri mediaSource, MediaInfo info)
134136
/// <param name="bitmap">The bitmap.</param>
135137
public void AddOrUpdateEntryThumbnail(Uri mediaSource, BitmapDataBuffer bitmap)
136138
{
139+
if (bitmap == null) throw new ArgumentNullException(nameof(bitmap));
140+
137141
lock (SyncRoot)
138142
{
139143
var entry = FindEntryByMediaSource(mediaSource);

Unosquare.FFME.Windows.Sample/Foundation/WindowStatus.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ public static void EnableDisplayTimeout()
7676
}
7777

7878
/// <summary>
79-
/// Captures the specified window state.
79+
/// Captures the specified window object.
8080
/// </summary>
81-
/// <param name="w">The w.</param>
81+
/// <param name="w">The window state object.</param>
8282
public void Capture(Window w)
8383
{
84+
if (w == null) throw new ArgumentNullException(nameof(w));
85+
8486
WindowState = w.WindowState;
8587
Top = w.Top;
8688
Left = w.Left;
@@ -95,6 +97,8 @@ public void Capture(Window w)
9597
/// <param name="w">The w.</param>
9698
public void Apply(Window w)
9799
{
100+
if (w == null) throw new ArgumentNullException(nameof(w));
101+
98102
w.WindowState = WindowState;
99103
w.Top = Top;
100104
w.Left = Left;

0 commit comments

Comments
 (0)