Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

修复在播放结束后有时会卡死的问题 #1067

Merged
merged 1 commit into from
Apr 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected override void OnPointerExited(PointerRoutedEventArgs e)

if (IsControlPanelShown() && e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
{
HideControls();
HideControlsAsync();
}

_cursorStayTime = 0;
Expand Down Expand Up @@ -484,7 +484,11 @@ private void OnRequestClearDanmaku(object sender, EventArgs e)
_segmentIndex = 1;
_danmakuDictionary.Clear();
_danmakuTimer.Stop();
_danmakuView.ClearAll();

if (_danmakuView != null)
{
_danmakuView.ClearAll();
}
}

private void OnMediaPlayerUdpated(object sender, EventArgs e)
Expand All @@ -502,11 +506,11 @@ private void OnDanmakuViewModelPropertyChanged(object sender, PropertyChangedEve
{
CheckDanmakuZoom();
}
else if (e.PropertyName == nameof(DanmakuViewModel.DanmakuArea))
else if (e.PropertyName == nameof(DanmakuViewModel.DanmakuArea) && _danmakuView != null)
{
_danmakuView.DanmakuArea = DanmakuViewModel.DanmakuArea;
}
else if (e.PropertyName == nameof(DanmakuViewModel.DanmakuSpeed))
else if (e.PropertyName == nameof(DanmakuViewModel.DanmakuSpeed) && _danmakuView != null)
{
_danmakuView.DanmakuDuration = Convert.ToInt32((2.1 - DanmakuViewModel.DanmakuSpeed) * 10);
}
Expand Down Expand Up @@ -556,16 +560,16 @@ await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
if (sender.PlaybackState == MediaPlaybackState.Buffering)
{
_danmakuView.PauseDanmaku();
_danmakuView?.PauseDanmaku();
}
else if (sender.PlaybackState == MediaPlaybackState.Paused && sender.Position < sender.NaturalDuration)
{
_danmakuView.PauseDanmaku();
_danmakuView?.PauseDanmaku();
}
else if (sender.PlaybackState == MediaPlaybackState.Playing)
{
_danmakuView.ResumeDanmaku();
HideControls();
_danmakuView?.ResumeDanmaku();
HideControlsAsync();
}

_playPauseButton?.Focus(FocusState.Programmatic);
Expand Down Expand Up @@ -797,7 +801,7 @@ await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
foreach (var item in data)
{
_danmakuView.AddScreenDanmaku(item, false);
_danmakuView?.AddScreenDanmaku(item, false);
}
});
}
Expand All @@ -814,19 +818,19 @@ private void OnCursorTimerTickAsync(object sender, object e)
{
if (_isTouch && IsControlPanelShown())
{
HideControls();
HideControlsAsync();
}
else if (IsCursorInMediaElement() && !IsCursorInControlPanel())
{
Window.Current.CoreWindow.PointerCursor = null;
if (IsControlPanelShown())
{
HideControls();
HideControlsAsync();
}
}
else if (!ViewModel.IsPointerInMediaElement && IsControlPanelShown())
{
HideControls();
HideControlsAsync();
}

_cursorStayTime = 0;
Expand Down Expand Up @@ -1120,10 +1124,13 @@ private bool IsCursorInMediaElement()
return rootBounds.Contains(pointerPosition);
}

private void HideControls()
private async void HideControlsAsync()
{
Hide();
ViewModel.IsFocusInputControl = false;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
Hide();
ViewModel.IsFocusInputControl = false;
});
}
}
}