Skip to content

Commit ad2cef3

Browse files
committed
修复原生播放器崩溃的问题
1 parent 4d9df90 commit ad2cef3

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/Desktop/BiliCopilot.UI/Controls/Core/Player/NativePlayer.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ protected async override void OnControlLoaded()
3131
/// <inheritdoc/>
3232
protected override void OnApplyTemplate()
3333
{
34-
_playerElement = GetTemplateChild("PlayerElement") as MediaPlayerElement;
34+
var rootGrid = GetTemplateChild("RootGrid") as Grid;
35+
_playerElement = new MediaPlayerElement();
36+
_playerElement.HorizontalAlignment = HorizontalAlignment.Stretch;
37+
_playerElement.VerticalAlignment = VerticalAlignment.Stretch;
38+
_playerElement.AreTransportControlsEnabled = false;
39+
rootGrid.Children.Add(_playerElement);
3540
}
3641

3742
/// <inheritdoc/>

src/Desktop/BiliCopilot.UI/Controls/Core/Player/PlayerResources.xaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,7 @@
9191
<Setter Property="Template">
9292
<Setter.Value>
9393
<ControlTemplate TargetType="local:NativePlayer">
94-
<Grid Background="Black">
95-
<MediaPlayerElement
96-
x:Name="PlayerElement"
97-
HorizontalAlignment="Stretch"
98-
VerticalAlignment="Stretch"
99-
AreTransportControlsEnabled="False" />
100-
</Grid>
94+
<Grid x:Name="RootGrid" Background="Black" />
10195
</ControlTemplate>
10296
</Setter.Value>
10397
</Setter>

src/Desktop/BiliCopilot.UI/ViewModels/Core/NativePlayerViewModel/NativePlayerViewModel.Overrides.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected override async Task OnLoadPlayDataAsync()
140140
await LoadDashVideoSourceAsync();
141141
}
142142

143-
_element.SetMediaPlayer(Player);
143+
_element?.SetMediaPlayer(Player);
144144
}
145145

146146
/// <inheritdoc/>

0 commit comments

Comments
 (0)