Skip to content

Commit 7f5d650

Browse files
authored
修复播放崩溃的问题 (#821)
* 调整弹幕加载逻辑 * Update
1 parent db50d11 commit 7f5d650

File tree

10 files changed

+76
-105
lines changed

10 files changed

+76
-105
lines changed

src/Desktop/BiliCopilot.UI/Controls/Core/Player/BiliPlayer.Methods.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ private void OnRootPointerEntered(object sender, PointerRoutedEventArgs e)
278278

279279
private void OnRootPointerMoved(object sender, PointerRoutedEventArgs e)
280280
{
281-
_gestureRecognizer.ProcessMoveEvents(e.GetIntermediatePoints((UIElement)sender));
282281
HandlePointerEvent(e);
283282
}
284283

src/Desktop/BiliCopilot.UI/Controls/Danmaku/LiveDanmakuPanel.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
99
mc:Ignorable="d">
1010

11-
<Grid x:Name="RootGrid" Visibility="{x:Bind ViewModel.IsShowDanmaku, Mode=OneWay}" />
11+
<Grid
12+
x:Name="RootGrid"
13+
x:Load="{x:Bind ViewModel.CanShowDanmaku, Mode=OneWay}"
14+
Visibility="{x:Bind ViewModel.IsShowDanmaku, Mode=OneWay}" />
1215
</local:DanmakuControlBase>

src/Desktop/BiliCopilot.UI/Controls/Danmaku/LiveDanmakuPanel.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void ResetDanmakuStyle()
129129

130130
private void Redraw()
131131
{
132-
DispatcherQueue.TryEnqueue(() =>
132+
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Low, () =>
133133
{
134134
_danmakuController?.Close();
135135
_danmakuController = new DanmakuFrostMaster(RootGrid, this.Get<ILogger<DanmakuFrostMaster>>());

src/Desktop/BiliCopilot.UI/Controls/Danmaku/VideoDanmakuPanel.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
99
mc:Ignorable="d">
1010

11-
<Grid x:Name="RootGrid" Visibility="{x:Bind ViewModel.IsShowDanmaku, Mode=OneWay}" />
11+
<Grid
12+
x:Name="RootGrid"
13+
x:Load="{x:Bind ViewModel.CanShowDanmaku, Mode=OneWay}"
14+
Visibility="{x:Bind ViewModel.IsShowDanmaku, Mode=OneWay}" />
1215
</local:DanmakuControlBase>

src/Desktop/BiliCopilot.UI/Controls/Danmaku/VideoDanmakuPanel.xaml.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ private async void OnDanmakuListAddedAsync(object? sender, IReadOnlyList<Danmaku
104104
_cachedDanmakus = _cachedDanmakus.Concat(items).Distinct().ToList();
105105
if (isFirstLoad)
106106
{
107-
await Task.Delay(150);
107+
await Task.Delay(250);
108108
Redraw(true);
109-
return;
110109
}
111-
112-
_danmakuController?.AddDanmakuList(items);
110+
else
111+
{
112+
_danmakuController?.AddDanmakuList(items);
113+
}
113114
}
114115

115116
private void OnRequestClearDanmaku(object? sender, EventArgs e)
@@ -194,16 +195,10 @@ private void Redraw(bool force = false)
194195
return;
195196
}
196197

197-
DispatcherQueue?.TryEnqueue(() =>
198+
DispatcherQueue?.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Low, () =>
198199
{
199-
if (_danmakuController is not null)
200-
{
201-
_danmakuController?.Clear();
202-
}
203-
else
204-
{
205-
_danmakuController = new DanmakuFrostMaster(RootGrid, this.Get<ILogger<DanmakuFrostMaster>>());
206-
}
200+
_danmakuController?.Close();
201+
_danmakuController = new DanmakuFrostMaster(RootGrid, this.Get<ILogger<DanmakuFrostMaster>>());
207202

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

213208
_danmakuController.UpdateTime(Convert.ToUInt32(_lastProgress * 1000));
214209
ResetDanmakuStyle();
215-
216-
if (!ViewModel.IsPaused)
217-
{
218-
_danmakuController.Resume();
219-
}
220210
});
221211
}
222212
}

src/Desktop/BiliCopilot.UI/ViewModels/Core/DanmakuViewModel/DanmakuViewModel.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void ClearAll()
9191
_duration = 0;
9292
_aid = string.Empty;
9393
_cid = string.Empty;
94+
CanShowDanmaku = false;
9495
ClearDanmaku();
9596
}
9697

@@ -146,10 +147,10 @@ private async Task LoadDanmakusAsync(int duration)
146147

147148
if (totalDanmakus.Count > 0)
148149
{
150+
CanShowDanmaku = true;
149151
ListAdded?.Invoke(this, totalDanmakus);
150152
}
151153

152-
Redraw();
153154
IsLoading = false;
154155
}
155156

@@ -171,6 +172,7 @@ private async Task SendDanmakuAsync(string text)
171172
[RelayCommand]
172173
private void AddDanmaku(string text)
173174
{
175+
CanShowDanmaku = true;
174176
RequestAddSingleDanmaku?.Invoke(this, text);
175177
}
176178

@@ -208,11 +210,6 @@ partial void OnIsShowDanmakuChanged(bool value)
208210
{
209211
Redraw();
210212
}
211-
else
212-
{
213-
ClearDanmaku();
214-
ResetStyle();
215-
}
216213

217214
SettingsToolkit.WriteLocalSetting(Models.Constants.SettingNames.IsShowDanmaku, value);
218215
}

src/Desktop/BiliCopilot.UI/ViewModels/Core/SubtitleViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public void ClearAll()
9696
_aid = default;
9797
_cid = default;
9898
_subtitles = default;
99-
Metas = default;
10099
SelectedMeta = default;
101100
_position = 0;
102101
IsAvailable = false;

src/Desktop/BiliCopilot.UI/ViewModels/View/VideoPlayerPageViewModel/VideoPlayerPageViewModel.Methods.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@ private void ClearView()
177177
BvId = default;
178178
FavoriteFolders = default;
179179
HasNextVideo = false;
180-
181-
Formats = default;
182180
SelectedFormat = default;
183-
184-
Sections = default;
185-
SelectedSection = default;
186181
}
187182

188183
private void CalcPlayerHeight()

src/Libs/Danmaku.Core/DanmakuFrostMaster.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public DanmakuFrostMaster(Grid rootGrid, ILogger<DanmakuFrostMaster> logger = de
4646
return;
4747
}
4848

49-
var canvas = new CanvasSwapChainPanel();
49+
var canvas = new CanvasAnimatedControl();
50+
canvas.UseSharedDevice = true;
51+
canvas.DpiScale = (float)rootGrid.XamlRoot.RasterizationScale;
52+
canvas.ClearColor = Colors.Transparent;
53+
canvas.Background = new SolidColorBrush(Colors.Transparent);
5054
rootGrid.Children.Add(canvas);
5155
Logger.SetLogger(logger);
5256

@@ -179,6 +183,7 @@ public void Seek(uint targetMs)
179183
}
180184

181185
_isSeeking = true;
186+
Stop();
182187
lock (_danmakuList)
183188
{
184189
_lastIndex = 0;
@@ -192,10 +197,9 @@ public void Seek(uint targetMs)
192197
break;
193198
}
194199
}
195-
196-
_render?.Start();
197200
}
198201
_lastTimeMs = targetMs;
202+
Resume();
199203
_isSeeking = false;
200204
}
201205
}

0 commit comments

Comments
 (0)