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

支持自动播放关联视频 #897

Merged
merged 1 commit into from
Mar 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +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 readonly Dictionary<int, List<DanmakuModel>> _danmakuDictionary;

Expand Down Expand Up @@ -100,10 +101,13 @@ public partial class BiliPlayerTransportControls
private Button _decreasePlayRateButton;
private Button _increaseVolumeButton;
private Button _decreaseVolumeButton;
private HyperlinkButton _playNextVideoButton;

private int _segmentIndex;
private double _cursorStayTime;
private double _historyMessageHoldSeconds;
private double _tempMessageHoldSeconds;
private double _nextVideoHoldSeconds;

private double _manipulationDeltaX = 0d;
private double _manipulationDeltaY = 0d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected override void OnApplyTemplate()
_decreasePlayRateButton = GetTemplateChild(DecreasePlayRateButtonName) as Button;
_increaseVolumeButton = GetTemplateChild(IncreaseVolumeButtonName) as Button;
_decreaseVolumeButton = GetTemplateChild(DecreaseVolumeButtonName) as Button;
_playNextVideoButton = GetTemplateChild(PlayNextVideoButtonName) as HyperlinkButton;

_fullWindowPlayModeButton.Click += OnPlayModeButtonClick;
_fullScreenPlayModeButton.Click += OnPlayModeButtonClick;
Expand All @@ -117,6 +118,7 @@ protected override void OnApplyTemplate()
_decreasePlayRateButton.Click += OnDecreasePlayRateButtonClick;
_increaseVolumeButton.Click += OnIncreaseVolumeButtonClick;
_decreaseVolumeButton.Click += OnDecreaseVolumeButtonClick;
_playNextVideoButton.Click += OnPlayNextVideoButtonClickAsync;

if (_formatListView != null)
{
Expand Down Expand Up @@ -339,8 +341,8 @@ private async void OnHomeButtonClickAsync(object sender, RoutedEventArgs e)

private async void OnContinuePreviousViewButtonClickAsync(object sender, RoutedEventArgs e)
{
ViewModel.IsShowHistory = false;
ViewModel.HistoryText = string.Empty;
ViewModel.IsShowHistoryTip = false;
ViewModel.HistoryTipText = string.Empty;
await ViewModel.JumpToHistoryAsync();
}

Expand Down Expand Up @@ -563,7 +565,7 @@ private void InitializeNormalTimer()
{
_normalTimer = new DispatcherTimer();
_normalTimer.Interval = TimeSpan.FromSeconds(0.5);
_normalTimer.Tick += OnNormalTimerTick;
_normalTimer.Tick += OnNormalTimerTickAsync;
}
}

Expand Down Expand Up @@ -776,7 +778,7 @@ private void OnCursorTimerTickAsync(object sender, object e)
}
}

private void OnNormalTimerTick(object sender, object e)
private async void OnNormalTimerTickAsync(object sender, object e)
{
if (_tempMessageHoldSeconds >= 2)
{
Expand All @@ -787,15 +789,41 @@ private void OnNormalTimerTick(object sender, object e)
_tempMessageHoldSeconds += 0.5;
}

if (ViewModel.IsShowHistory)
if (ViewModel.IsShowHistoryTip)
{
_historyMessageHoldSeconds += 0.5;
if (_historyMessageHoldSeconds > 4)
{
ViewModel.IsShowHistory = false;
ViewModel.IsShowHistoryTip = false;
_historyMessageHoldSeconds = 0;
}
}
else
{
_historyMessageHoldSeconds = 0;
}

if (ViewModel.IsShowNextVideoTip)
{
_nextVideoHoldSeconds += 0.5;

if (_nextVideoHoldSeconds > 5)
{
_nextVideoHoldSeconds = 0;
ViewModel.NextVideoCountdown = 0;
ViewModel.IsShowNextVideoTip = false;

await ViewModel.PlayNextVideoAsync();
}
else
{
ViewModel.NextVideoCountdown = Math.Ceiling(5 - _nextVideoHoldSeconds);
}
}
else
{
_nextVideoHoldSeconds = 0;
}
}

private void OnFocusTimerTick(object sender, object e)
Expand Down Expand Up @@ -969,6 +997,13 @@ private void OnIncreaseVolumeButtonClick(object sender, RoutedEventArgs e)
}
}

private async void OnPlayNextVideoButtonClickAsync(object sender, RoutedEventArgs e)
{
ViewModel.IsShowNextVideoTip = false;
_nextVideoHoldSeconds = 0;
await ViewModel.PlayNextVideoAsync();
}

private void ShowTempMessage(string message)
{
_tempMessageContainer.Visibility = Visibility.Visible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
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 @@ -420,24 +427,40 @@
<Border x:Name="PreviousViewInformer_Border" Grid.Column="1">
<muxc:InfoBar
x:Name="PreviousViewInformer"
Background="{ThemeResource MediaTransportControlsPanelBackground}"
BorderBrush="{ThemeResource MediaTransportControlsBorderBrush}"
BorderThickness="{ThemeResource MediaTransportControlsBorderThickness}"
Style="{StaticResource MediaControlInfoBarStyle}"
CornerRadius="{TemplateBinding CornerRadius}"
IsClosable="True"
IsIconVisible="False"
IsOpen="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsShowHistory, Mode=TwoWay}"
Message="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.HistoryText}"
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"
Click="JumpToHistoryAsync"
Content="{loc:LocaleLocator Name=ContinuePreviousView}" />
</muxc:InfoBar.ActionButton>
</muxc:InfoBar>
</Border>

<Border x:Name="NextVideoInformer_Border" Grid.Column="1">
<muxc:InfoBar
x:Name="NextVideoInformer"
Title="{loc:LocaleLocator Name=PlayNextVideo}"
Style="{StaticResource MediaControlInfoBarStyle}"
CornerRadius="{TemplateBinding CornerRadius}"
IsIconVisible="True"
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>
</Border>
</Grid>

<Border x:Name="ControlPanel_ControlPanelVisibilityStates_Border" MaxWidth="820">
Expand Down
18 changes: 18 additions & 0 deletions src/App/Controls/Settings/PlayerModeSettingSection.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@
</exp:ExpanderExWrapper.WrapContent>
</exp:ExpanderExWrapper>
<exp:ExpanderExItemSeparator />
<exp:ExpanderExWrapper Style="{StaticResource WrapperInExpanderContentStyle}">
<exp:ExpanderExWrapper.MainContent>
<StackPanel Orientation="Horizontal" Spacing="4">
<TextBlock VerticalAlignment="Center" Text="{loc:LocaleLocator Name=AutoNextRelatedVideo}" />
<uwp:RegularFluentIcon
VerticalAlignment="Center"
FontSize="12"
Foreground="{ThemeResource SystemFillColorAttentionBrush}"
Symbol="QuestionCircle16"
ToolTipService.ToolTip="{loc:LocaleLocator Name=AutoNextRelatedVideoDescription}" />
</StackPanel>

</exp:ExpanderExWrapper.MainContent>
<exp:ExpanderExWrapper.WrapContent>
<ToggleSwitch Style="{StaticResource RightAlignedCompactToggleSwitchStyle}" IsOn="{x:Bind ViewModel.IsAutoPlayNextRelatedVideo, Mode=TwoWay}" />
</exp:ExpanderExWrapper.WrapContent>
</exp:ExpanderExWrapper>
<exp:ExpanderExItemSeparator />
<exp:ExpanderExWrapper Style="{StaticResource WrapperInExpanderContentStyle}">
<exp:ExpanderExWrapper.MainContent>
<TextBlock VerticalAlignment="Center" Text="{loc:LocaleLocator Name=DefaultPlayerDisplayMode}" />
Expand Down
2 changes: 1 addition & 1 deletion src/App/Pages/SettingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<controls:StartupSettingSection />
<controls:LoggerSettingSection />
<controls:CacheSettingSection />
<controls:InitialCheckSection />

<TextBlock
Style="{StaticResource BodyTextBlockStyle}"
Expand All @@ -47,7 +48,6 @@
<controls:PlayerControlSettingSection />
<controls:MTCSettingSection />
<controls:ScreenshotSettingSection />
<controls:InitialCheckSection />
<StackPanel
Margin="0,12,0,0"
HorizontalAlignment="Left"
Expand Down
12 changes: 12 additions & 0 deletions src/App/Resources/Strings/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@
<data name="Automatic" xml:space="preserve">
<value>自动</value>
</data>
<data name="AutoNextRelatedVideo" xml:space="preserve">
<value>自动播放关联视频</value>
</data>
<data name="AutoNextRelatedVideoDescription" xml:space="preserve">
<value>在视频播放结束后,如果有关联视频,则在 5 秒倒计时结束后自动播放下一个视频</value>
</data>
<data name="AutoPlayWhenLoaded" xml:space="preserve">
<value>加载完成后自动播放</value>
</data>
Expand Down Expand Up @@ -926,6 +932,12 @@ BV号以 BV 开头,是一串英文数字混合的编号, 如 BV1JL4y1875w</v
<data name="PlayLine" xml:space="preserve">
<value>线路</value>
</data>
<data name="PlayNextVideo" xml:space="preserve">
<value>即将播放下一个视频</value>
</data>
<data name="PlayNow" xml:space="preserve">
<value>立即播放</value>
</data>
<data name="PlayPause" xml:space="preserve">
<value>播放/暂停</value>
</data>
Expand Down
4 changes: 4 additions & 0 deletions src/Models/Models.Enums/App/LanguageNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ public enum LanguageNames
FirstClickTagTip,
QuickSelection,
CurrentPlaybackRate,
AutoNextRelatedVideo,
AutoNextRelatedVideoDescription,
PlayNow,
PlayNextVideo,
#pragma warning restore SA1602 // Enumeration items should be documented
}
}
1 change: 1 addition & 0 deletions src/Models/Models.Enums/App/SettingNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public enum SettingNames
PlaybackRateEnhancement,
GlobalPlaybackRate,
IsFirstClickTag,
IsAutoPlayNextRelatedVideo,
#pragma warning disable SA1602 // Enumeration items should be documented
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private async void ResetAsync()
CurrentPgcEpisode = null;
CurrentVideoPart = null;
Publisher = null;
HistoryText = string.Empty;
HistoryTipText = string.Empty;
_initializeProgress = TimeSpan.Zero;
_lastReportProgress = TimeSpan.Zero;
IsShowEpisode = false;
Expand All @@ -45,7 +45,8 @@ private async void ResetAsync()
IsShowRelatedVideos = false;
IsShowChat = false;
IsShowReply = true;
IsShowHistory = false;
IsShowHistoryTip = false;
IsShowNextVideoTip = false;
IsPlayInformationError = false;
IsCurrentEpisodeInPgcSection = false;
IsShowEmptyLiveMessage = true;
Expand Down Expand Up @@ -318,7 +319,7 @@ private void InitializeVideoDetail()
}

var ts = TimeSpan.FromSeconds(_videoDetail.History.Progress);
HistoryText = $"{_resourceToolkit.GetLocaleString(LanguageNames.PreviousView)}{title} {ts}";
HistoryTipText = $"{_resourceToolkit.GetLocaleString(LanguageNames.PreviousView)}{title} {ts}";
}
}

Expand Down Expand Up @@ -930,7 +931,14 @@ private async void OnMediaPlayerEndedAsync(MediaPlayer sender, object args)
}
else
{
PlayerDisplayMode = PlayerDisplayMode.Default;
if (HasNextVideo() && _settingsToolkit.ReadLocalSetting(SettingNames.IsAutoPlayNextRelatedVideo, false))
{
IsShowNextVideoTip = true;
}
else
{
PlayerDisplayMode = PlayerDisplayMode.Default;
}
}
}
});
Expand All @@ -954,9 +962,9 @@ private async void OnMediaPlayerCurrentStateChangedAsync(MediaPlayer sender, obj
case MediaPlaybackState.Playing:
PlayerStatus = PlayerStatus.Playing;
IsPlayInformationError = false;
if (!string.IsNullOrEmpty(HistoryText) && _initializeProgress == TimeSpan.Zero && _isFirstShowHistory)
if (!string.IsNullOrEmpty(HistoryTipText) && _initializeProgress == TimeSpan.Zero && _isFirstShowHistory)
{
IsShowHistory = true;
IsShowHistoryTip = true;
_isFirstShowHistory = false;
}

Expand All @@ -966,6 +974,11 @@ private async void OnMediaPlayerCurrentStateChangedAsync(MediaPlayer sender, obj
_initializeProgress = TimeSpan.Zero;
}

if (IsShowNextVideoTip)
{
IsShowNextVideoTip = false;
}

break;
case MediaPlaybackState.Buffering:
PlayerStatus = PlayerStatus.Buffering;
Expand Down Expand Up @@ -1022,5 +1035,21 @@ private void InitializePlaybackRateProperties()
PlaybackRate = 1d;
}
}

private bool HasNextVideo()
{
var result = !IsInteraction
&& _videoType == VideoType.Video
&& IsShowRelatedVideos
&& RelatedVideoCollection.Count > 0;

if (result)
{
var nextVideo = RelatedVideoCollection.First();
NextVideoTipText = nextVideo.Title;
}

return result;
}
}
}
Loading