Skip to content

Commit

Permalink
修复播放崩溃的问题 (#821)
Browse files Browse the repository at this point in the history
* 调整弹幕加载逻辑

* Update
  • Loading branch information
Richasy authored Oct 15, 2024
1 parent db50d11 commit 7f5d650
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ private void OnRootPointerEntered(object sender, PointerRoutedEventArgs e)

private void OnRootPointerMoved(object sender, PointerRoutedEventArgs e)
{
_gestureRecognizer.ProcessMoveEvents(e.GetIntermediatePoints((UIElement)sender));
HandlePointerEvent(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid x:Name="RootGrid" Visibility="{x:Bind ViewModel.IsShowDanmaku, Mode=OneWay}" />
<Grid
x:Name="RootGrid"
x:Load="{x:Bind ViewModel.CanShowDanmaku, Mode=OneWay}"
Visibility="{x:Bind ViewModel.IsShowDanmaku, Mode=OneWay}" />
</local:DanmakuControlBase>
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void ResetDanmakuStyle()

private void Redraw()
{
DispatcherQueue.TryEnqueue(() =>
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Low, () =>
{
_danmakuController?.Close();
_danmakuController = new DanmakuFrostMaster(RootGrid, this.Get<ILogger<DanmakuFrostMaster>>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid x:Name="RootGrid" Visibility="{x:Bind ViewModel.IsShowDanmaku, Mode=OneWay}" />
<Grid
x:Name="RootGrid"
x:Load="{x:Bind ViewModel.CanShowDanmaku, Mode=OneWay}"
Visibility="{x:Bind ViewModel.IsShowDanmaku, Mode=OneWay}" />
</local:DanmakuControlBase>
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ private async void OnDanmakuListAddedAsync(object? sender, IReadOnlyList<Danmaku
_cachedDanmakus = _cachedDanmakus.Concat(items).Distinct().ToList();
if (isFirstLoad)
{
await Task.Delay(150);
await Task.Delay(250);
Redraw(true);
return;
}

_danmakuController?.AddDanmakuList(items);
else
{
_danmakuController?.AddDanmakuList(items);
}
}

private void OnRequestClearDanmaku(object? sender, EventArgs e)
Expand Down Expand Up @@ -194,16 +195,10 @@ private void Redraw(bool force = false)
return;
}

DispatcherQueue?.TryEnqueue(() =>
DispatcherQueue?.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Low, () =>
{
if (_danmakuController is not null)
{
_danmakuController?.Clear();
}
else
{
_danmakuController = new DanmakuFrostMaster(RootGrid, this.Get<ILogger<DanmakuFrostMaster>>());
}
_danmakuController?.Close();
_danmakuController = new DanmakuFrostMaster(RootGrid, this.Get<ILogger<DanmakuFrostMaster>>());

if (_cachedDanmakus.Any())
{
Expand All @@ -212,11 +207,6 @@ private void Redraw(bool force = false)

_danmakuController.UpdateTime(Convert.ToUInt32(_lastProgress * 1000));
ResetDanmakuStyle();

if (!ViewModel.IsPaused)
{
_danmakuController.Resume();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void ClearAll()
_duration = 0;
_aid = string.Empty;
_cid = string.Empty;
CanShowDanmaku = false;
ClearDanmaku();
}

Expand Down Expand Up @@ -146,10 +147,10 @@ private async Task LoadDanmakusAsync(int duration)

if (totalDanmakus.Count > 0)
{
CanShowDanmaku = true;
ListAdded?.Invoke(this, totalDanmakus);
}

Redraw();
IsLoading = false;
}

Expand All @@ -171,6 +172,7 @@ private async Task SendDanmakuAsync(string text)
[RelayCommand]
private void AddDanmaku(string text)
{
CanShowDanmaku = true;
RequestAddSingleDanmaku?.Invoke(this, text);
}

Expand Down Expand Up @@ -208,11 +210,6 @@ partial void OnIsShowDanmakuChanged(bool value)
{
Redraw();
}
else
{
ClearDanmaku();
ResetStyle();
}

SettingsToolkit.WriteLocalSetting(Models.Constants.SettingNames.IsShowDanmaku, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void ClearAll()
_aid = default;
_cid = default;
_subtitles = default;
Metas = default;
SelectedMeta = default;
_position = 0;
IsAvailable = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,7 @@ private void ClearView()
BvId = default;
FavoriteFolders = default;
HasNextVideo = false;

Formats = default;
SelectedFormat = default;

Sections = default;
SelectedSection = default;
}

private void CalcPlayerHeight()
Expand Down
10 changes: 7 additions & 3 deletions src/Libs/Danmaku.Core/DanmakuFrostMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public DanmakuFrostMaster(Grid rootGrid, ILogger<DanmakuFrostMaster> logger = de
return;
}

var canvas = new CanvasSwapChainPanel();
var canvas = new CanvasAnimatedControl();
canvas.UseSharedDevice = true;
canvas.DpiScale = (float)rootGrid.XamlRoot.RasterizationScale;
canvas.ClearColor = Colors.Transparent;
canvas.Background = new SolidColorBrush(Colors.Transparent);
rootGrid.Children.Add(canvas);
Logger.SetLogger(logger);

Expand Down Expand Up @@ -179,6 +183,7 @@ public void Seek(uint targetMs)
}

_isSeeking = true;
Stop();
lock (_danmakuList)
{
_lastIndex = 0;
Expand All @@ -192,10 +197,9 @@ public void Seek(uint targetMs)
break;
}
}

_render?.Start();
}
_lastTimeMs = targetMs;
Resume();
_isSeeking = false;
}
}
Expand Down
Loading

0 comments on commit 7f5d650

Please sign in to comment.