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

修复因播放提示导致的崩溃问题 #974

Merged
merged 1 commit into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/App/App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="Controls\Common\VerticalRepeaterView\VerticalRepeaterView.Properties.cs" />
<Compile Include="Controls\Common\VideoCard\VideoCard.cs" />
<Compile Include="Controls\Common\VideoCard\VideoCard.Properties.cs" />
<Compile Include="Controls\Player\PlayerTip\PlayerTip.cs" />
<Compile Include="Controls\Player\Related\ViewLaterView.xaml.cs">
<DependentUpon>ViewLaterView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -571,6 +572,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Controls\Player\PlayerTip\PlayerTip.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\Player\Related\ViewLaterView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
6 changes: 3 additions & 3 deletions src/App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Log(LogLevel level, string message)
/// <param name="e">Detailed information about the start request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
OnLaunchedOrActivated(e);
OnLaunchedOrActivatedAsync(e);
}

/// <summary>
Expand All @@ -68,10 +68,10 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
/// <param name="args">Detailed information about the active request and process.</param>
protected override void OnActivated(IActivatedEventArgs args)
{
OnLaunchedOrActivated(args);
OnLaunchedOrActivatedAsync(args);
}

private async void OnLaunchedOrActivated(IActivatedEventArgs e)
private async void OnLaunchedOrActivatedAsync(IActivatedEventArgs e)
{
// 用于解析Flv视频
if (RuntimeInformation.ProcessArchitecture != Architecture.Arm64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Richasy.Bili.Models.Enums.App;
using Richasy.Bili.ViewModels.Uwp;
using Richasy.Bili.ViewModels.Uwp.Common;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
Expand Down Expand Up @@ -53,7 +52,7 @@ public partial class BiliPlayerTransportControls
private const string SubtitleBlockName = "SubtitleBlock";
private const string HomeButtonName = "HomeButton";
private const string BackToDefaultButtonName = "BackToDefaultButton";
private const string ContinuePreviousViewButtonName = "ContinuePreviousViewButton";
private const string PreviousViewInformerName = "PreviousViewInformer";
private const string LiveRefreshButtonName = "LiveRefreshButton";
private const string TempMessageContaienrName = "TempMessageContainer";
private const string TempMessageBlockName = "TempMessageBlock";
Expand All @@ -65,7 +64,7 @@ public partial class BiliPlayerTransportControls
private const string DecreasePlayRateButtonName = "DecreasePlayRateButton";
private const string IncreaseVolumeButtonName = "IncreaseVolumeButton";
private const string DecreaseVolumeButtonName = "DecreaseVolumeButton";
private const string PlayNextVideoButtonName = "PlayNextVideoButton";
private const string NextVideoInformerName = "NextVideoInformer";
private const string VisibilityStateGroupName = "ControlPanelVisibilityStates";
private const string FormatButtonName = "FormatButtonName";
private const string LiveQualityButtonName = "LiveQualityButtonName";
Expand All @@ -92,7 +91,6 @@ public partial class BiliPlayerTransportControls
private Button _danmakuBarVisibilityButton;
private Button _homeButton;
private Button _backToDefaultButton;
private Button _continuePreviousViewButton;
private Button _liveRefreshButton;
private Button _previousEpisodeButton;
private Button _nextEpisodeButton;
Expand All @@ -105,7 +103,8 @@ public partial class BiliPlayerTransportControls
private Button _decreasePlayRateButton;
private Button _increaseVolumeButton;
private Button _decreaseVolumeButton;
private HyperlinkButton _playNextVideoButton;
private PlayerTip _previousViewInformer;
private PlayerTip _nextVidepInformer;
private Grid _rootGrid;
private VisualStateGroup _visibilityStateGroup;
private Button _formatButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ protected override void OnApplyTemplate()
_danmakuBarVisibilityButton = GetTemplateChild(DanmakuBarVisibilityButtonName) as Button;
_homeButton = GetTemplateChild(HomeButtonName) as Button;
_backToDefaultButton = GetTemplateChild(BackToDefaultButtonName) as Button;
_continuePreviousViewButton = GetTemplateChild(ContinuePreviousViewButtonName) as Button;
_liveRefreshButton = GetTemplateChild(LiveRefreshButtonName) as Button;
_previousEpisodeButton = GetTemplateChild(PreviousEpisodeButtonName) as Button;
_nextEpisodeButton = GetTemplateChild(NextEpisodeButtonName) as Button;
Expand All @@ -95,7 +94,8 @@ protected override void OnApplyTemplate()
_decreasePlayRateButton = GetTemplateChild(DecreasePlayRateButtonName) as Button;
_increaseVolumeButton = GetTemplateChild(IncreaseVolumeButtonName) as Button;
_decreaseVolumeButton = GetTemplateChild(DecreaseVolumeButtonName) as Button;
_playNextVideoButton = GetTemplateChild(PlayNextVideoButtonName) as HyperlinkButton;
_nextVidepInformer = GetTemplateChild(NextVideoInformerName) as PlayerTip;
_previousViewInformer = GetTemplateChild(PreviousViewInformerName) as PlayerTip;
_formatButton = GetTemplateChild(FormatButtonName) as Button;
_liveQualityButton = GetTemplateChild(LiveQualityButtonName) as Button;
_rootGrid = GetTemplateChild(RootGridName) as Grid;
Expand All @@ -114,7 +114,6 @@ protected override void OnApplyTemplate()
_homeButton.Click += OnHomeButtonClickAsync;
_backToDefaultButton.Click += OnBackButtonClick;
_liveRefreshButton.Click += OnLiveRefreshButtonClickAsync;
_continuePreviousViewButton.Click += OnContinuePreviousViewButtonClickAsync;
_previousEpisodeButton.Click += OnPreviousEpisodeButtonClickAsync;
_nextEpisodeButton.Click += OnNextEpisodeButtonClickAsync;
_screenshotButton.Click += OnScreenshotButtonClickAsync;
Expand All @@ -123,7 +122,8 @@ protected override void OnApplyTemplate()
_decreasePlayRateButton.Click += OnDecreasePlayRateButtonClick;
_increaseVolumeButton.Click += OnIncreaseVolumeButtonClick;
_decreaseVolumeButton.Click += OnDecreaseVolumeButtonClick;
_playNextVideoButton.Click += OnPlayNextVideoButtonClickAsync;
_previousViewInformer.ActionClick += OnContinuePreviousViewButtonClickAsync;
_nextVidepInformer.ActionClick += OnPlayNextVideoButtonClickAsync;

if (_formatListView != null)
{
Expand Down Expand Up @@ -352,7 +352,7 @@ private async void OnHomeButtonClickAsync(object sender, RoutedEventArgs e)
await ViewModel.BackToInteractionStartAsync();
}

private async void OnContinuePreviousViewButtonClickAsync(object sender, RoutedEventArgs e)
private async void OnContinuePreviousViewButtonClickAsync(object sender, EventArgs e)
{
ViewModel.IsShowHistoryTip = false;
ViewModel.HistoryTipText = string.Empty;
Expand Down Expand Up @@ -1011,7 +1011,7 @@ private void OnIncreaseVolumeButtonClick(object sender, RoutedEventArgs e)
}
}

private async void OnPlayNextVideoButtonClickAsync(object sender, RoutedEventArgs e)
private async void OnPlayNextVideoButtonClickAsync(object sender, EventArgs e)
{
ViewModel.IsShowNextVideoTip = false;
_nextVideoHoldSeconds = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@
x:Key="MediaControlButtonStyle"
BasedOn="{StaticResource DefaultButtonStyle}"
TargetType="Button" />
<Style x:Key="MediaControlInfoBarStyle" TargetType="muxc:InfoBar">
<Setter Property="Background" Value="{ThemeResource MediaTransportControlsPanelBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource MediaTransportControlsBorderBrush}" />
<Setter Property="IsClosable" Value="True" />
<Setter Property="IsIconVisible" Value="False" />
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
</Style>

<Style BasedOn="{StaticResource DefaultMTCStyle}" TargetType="local:BiliPlayerTransportControls" />

Expand Down Expand Up @@ -425,41 +418,24 @@
</Grid>
</Grid>
<Border x:Name="PreviousViewInformer_Border" Grid.Column="1">
<muxc:InfoBar
<local:PlayerTip
x:Name="PreviousViewInformer"
Style="{StaticResource MediaControlInfoBarStyle}"
CornerRadius="{TemplateBinding CornerRadius}"
Title="{loc:LocaleLocator Name=ViewHistory}"
HorizontalAlignment="Right"
ActionContent="{loc:LocaleLocator Name=ContinuePreviousView}"
IsOpen="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsShowHistoryTip, Mode=TwoWay}"
Message="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.HistoryTipText}"
RenderTransformOrigin="0.5,0.5">
<muxc:InfoBar.ActionButton>
<Button
x:Name="ContinuePreviousViewButton"
MinWidth="120"
Content="{loc:LocaleLocator Name=ContinuePreviousView}" />
</muxc:InfoBar.ActionButton>
</muxc:InfoBar>
Message="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.HistoryTipText}" />
</Border>

<Border x:Name="NextVideoInformer_Border" Grid.Column="1">
<muxc:InfoBar
<local:PlayerTip
x:Name="NextVideoInformer"
Title="{loc:LocaleLocator Name=PlayNextVideo}"
Style="{StaticResource MediaControlInfoBarStyle}"
CornerRadius="{TemplateBinding CornerRadius}"
IsIconVisible="True"
HorizontalAlignment="Right"
ActionContent="{loc:LocaleLocator Name=PlayNow}"
AdditionalTitle="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.NextVideoCountdown}"
IsOpen="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsShowNextVideoTip, Mode=TwoWay}"
Message="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.NextVideoTipText}"
Severity="Informational">
<muxc:InfoBar.ActionButton>
<HyperlinkButton x:Name="PlayNextVideoButton">
<TextBlock>
<Run Text="{loc:LocaleLocator Name=PlayNow}" />
<Run Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.NextVideoCountdown}" />
</TextBlock>
</HyperlinkButton>
</muxc:InfoBar.ActionButton>
</muxc:InfoBar>
Message="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.NextVideoTipText}" />
</Border>
</Grid>

Expand Down
124 changes: 124 additions & 0 deletions src/App/Controls/Player/PlayerTip/PlayerTip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright (c) Richasy. All rights reserved.

using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Richasy.Bili.App.Controls
{
/// <summary>
/// 播放器提示,通常从右侧弹出.
/// </summary>
public sealed class PlayerTip : Control
{
/// <summary>
/// <see cref="IsOpen"/> 的依赖属性.
/// </summary>
public static readonly DependencyProperty IsOpenProperty =
DependencyProperty.Register(nameof(IsOpen), typeof(bool), typeof(PlayerTip), new PropertyMetadata(default));

/// <summary>
/// <see cref="Message"/> 的依赖属性.
/// </summary>
public static readonly DependencyProperty MessageProperty =
DependencyProperty.Register(nameof(Message), typeof(string), typeof(PlayerTip), new PropertyMetadata(string.Empty));

/// <summary>
/// <see cref="Title"/> 的依赖属性.
/// </summary>
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(nameof(Title), typeof(string), typeof(PlayerTip), new PropertyMetadata(string.Empty));

/// <summary>
/// <see cref="ActionContent"/> 的依赖属性.
/// </summary>
public static readonly DependencyProperty ActionContentProperty =
DependencyProperty.Register(nameof(ActionContent), typeof(string), typeof(PlayerTip), new PropertyMetadata(string.Empty));

/// <summary>
/// <see cref="AdditionalTitle"/> 的依赖属性.
/// </summary>
public static readonly DependencyProperty AdditionalTitleProperty =
DependencyProperty.Register(nameof(AdditionalTitle), typeof(string), typeof(PlayerTip), new PropertyMetadata(string.Empty));

private const string ActionButtonName = "ActionButton";
private const string CloseButtonName = "CloseButton";

private Button _actionButton;
private Button _closeButton;

/// <summary>
/// Initializes a new instance of the <see cref="PlayerTip"/> class.
/// </summary>
public PlayerTip()
{
this.DefaultStyleKey = typeof(PlayerTip);
}

/// <summary>
/// 动作按钮被点击时触发.
/// </summary>
public event EventHandler ActionClick;

/// <summary>
/// 标题.
/// </summary>
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}

/// <summary>
/// 消息内容.
/// </summary>
public string Message
{
get { return (string)GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}

/// <summary>
/// 是否显示.
/// </summary>
public bool IsOpen
{
get { return (bool)GetValue(IsOpenProperty); }
set { SetValue(IsOpenProperty, value); }
}

/// <summary>
/// 动作按钮的内容.
/// </summary>
public string ActionContent
{
get { return (string)GetValue(ActionContentProperty); }
set { SetValue(ActionContentProperty, value); }
}

/// <summary>
/// 附加标题.
/// </summary>
public string AdditionalTitle
{
get { return (string)GetValue(AdditionalTitleProperty); }
set { SetValue(AdditionalTitleProperty, value); }
}

/// <inheritdoc/>
protected override void OnApplyTemplate()
{
_actionButton = GetTemplateChild(ActionButtonName) as Button;
_closeButton = GetTemplateChild(CloseButtonName) as Button;

_actionButton.Click += OnActionButtonClick;
_closeButton.Click += OnCloseButtonClick;
}

private void OnCloseButtonClick(object sender, RoutedEventArgs e)
=> IsOpen = false;

private void OnActionButtonClick(object sender, RoutedEventArgs e)
=> ActionClick?.Invoke(this, EventArgs.Empty);
}
}
Loading