Skip to content

Commit

Permalink
Issue #409 PReventShutdown to ElementHostBase
Browse files Browse the repository at this point in the history
  • Loading branch information
mariodivece committed Jul 1, 2019
1 parent e0134aa commit 13788a2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

## Current NuGet Release Status
- If you would like to support this project, you can show your appreciation via [PayPal.Me](https://www.paypal.me/mariodivece/50usd)
- Current Status: (2019-04-19) - Release 4.1.300 is now available, (see the <a href="https://github.com/unosquare/ffmediaelement/releases">Releases</a>)
- Current Status: (2019-06-30) - Release 4.1.310 is now available, (see the <a href="https://github.com/unosquare/ffmediaelement/releases">Releases</a>)
- NuGet Package available here: https://www.nuget.org/packages/FFME.Windows/
- FFmpeg Version: 4.1.1 <a href="https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.1.1-win32-shared.zip">32-bit</a> or <a href="https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.1.1-win64-shared.zip">64-bit</a>
- FFmpeg Version: 4.1.3 <a href="https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.1.3-win32-shared.zip">32-bit</a> or <a href="https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.1.3-win64-shared.zip">64-bit</a>

*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.*

Expand Down Expand Up @@ -94,7 +94,7 @@ A high-level diagram is provided as additional reference below.
*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.*

1. Clone this repository.
2. Download the FFmpeg **shared** binaries for your target architecture: <a href="https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.1.1-win32-shared.zip">32-bit</a> or <a href="https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.1.1-win64-shared.zip">64-bit</a>.
2. Download the FFmpeg **shared** binaries for your target architecture: <a href="https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.1.3-win32-shared.zip">32-bit</a> or <a href="https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.1.3-win64-shared.zip">64-bit</a>.
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.
4. Now paste all files from the prior step onto a well-known folder. Take note of the full path. (I used `c:\ffmpeg\`)
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.
Expand Down
14 changes: 13 additions & 1 deletion Unosquare.FFME.Windows/MediaElement.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,19 @@ public MediaPlaybackState UnloadedBehavior
/// </summary>
public static readonly DependencyProperty UnloadedBehaviorProperty = DependencyProperty.Register(
nameof(UnloadedBehavior), typeof(MediaPlaybackState), typeof(MediaElement),
new FrameworkPropertyMetadata(MediaPlaybackState.Close));
new FrameworkPropertyMetadata(MediaPlaybackState.Close, OnUnloadedBehaviorPropertyChanged));

private static void OnUnloadedBehaviorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d == null || d is MediaElement == false)
return;

var element = (MediaElement)d;
if (element.VideoView == null) return;

var behavior = element.UnloadedBehavior;
element.VideoView.PreventShutdown = behavior != MediaPlaybackState.Close;
}

#endregion

Expand Down
17 changes: 16 additions & 1 deletion Unosquare.FFME.Windows/Rendering/ElementHostBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public event RoutedEventHandler ElementLoaded
/// </summary>
public bool HasOwnDispatcher { get; }

/// <summary>
/// Gets or sets if the independent dispatcher should be prevented
/// from being shutdown when the host visual is removed from the visual tree (unloaded).
/// </summary>
public bool PreventShutdown { get; set; }

/// <summary>
/// Gets the dispatcher this element is hosted on.
/// </summary>
Expand Down Expand Up @@ -160,7 +166,10 @@ protected virtual void Dispose(bool alsoManaged)
if (!m_IsDisposed)
{
if (alsoManaged)
{
PreventShutdown = false;
HandleUnloadedEvent(this, EventArgs.Empty);
}

m_IsDisposed = true;
}
Expand Down Expand Up @@ -256,8 +265,14 @@ protected virtual void HandleUnloadedEvent(object sender, EventArgs e)
{
lock (UnloadLock)
{
if (!HasOwnDispatcher || ElementDispatcher == null || ElementDispatcher.HasShutdownStarted || ElementDispatcher.HasShutdownFinished)
if (PreventShutdown ||
!HasOwnDispatcher ||
ElementDispatcher == null ||
ElementDispatcher.HasShutdownStarted ||
ElementDispatcher.HasShutdownFinished)
{
return;
}

ElementDispatcher.ShutdownFinished += (s, ev) =>
{
Expand Down
2 changes: 1 addition & 1 deletion Unosquare.FFME.Windows/Unosquare.FFME.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageIconUrl>https://github.com/unosquare/ffmediaelement/raw/master/Support/ffme.png</PackageIconUrl>
<PackageTags>ffme hls wpf ffmpeg mediaelement h264 h265 hevc audio video decoding playback frame</PackageTags>
<PackageReleaseNotes>
This is a release package of the Floyd Engine build referencing bindings to FFmpeg version 4.1.1
This is a release package of the Floyd Engine build referencing bindings to FFmpeg version 4.1.3
This package does not contain the required FFmpeg binaries. Please refer to the following URL for instructions on how to obtain the binaries: https://github.com/unosquare/ffmediaelement
Release details: https://github.com/unosquare/ffmediaelement/milestone/12?closed=1
</PackageReleaseNotes>
Expand Down

0 comments on commit 13788a2

Please sign in to comment.