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

Commit

Permalink
支持播放速率快速切换 (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy authored Mar 22, 2022
1 parent d334278 commit d7dab3a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public partial class BiliPlayerTransportControls
private const string PreviousEpisodeButtonName = "PreviousEpisodeButton";
private const string NextEpisodeButtonName = "NextEpisodeButton";
private const string ScreenshotButtonName = "ScreenshotButton";
private const string PlaybackRateNodeComboBoxName = "PlaybackRateNodeComboBox";

private readonly Dictionary<int, List<DanmakuModel>> _danmakuDictionary;

Expand Down Expand Up @@ -90,6 +91,7 @@ public partial class BiliPlayerTransportControls
private TextBlock _subtitleBlock;
private Grid _tempMessageContainer;
private TextBlock _tempMessageBlock;
private ComboBox _playbackRateNodeComboBox;
private int _segmentIndex;
private double _cursorStayTime;
private double _tempMessageHoldSeconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected override void OnApplyTemplate()
_subtitleBlock = GetTemplateChild(SubtitleBlockName) as TextBlock;
_tempMessageContainer = GetTemplateChild(TempMessageContaienrName) as Grid;
_tempMessageBlock = GetTemplateChild(TempMessageBlockName) as TextBlock;
_playbackRateNodeComboBox = GetTemplateChild(PlaybackRateNodeComboBoxName) as ComboBox;

_fullWindowPlayModeButton.Click += OnPlayModeButtonClick;
_fullScreenPlayModeButton.Click += OnPlayModeButtonClick;
Expand All @@ -107,6 +108,7 @@ protected override void OnApplyTemplate()
_previousEpisodeButton.Click += OnPreviousEpisodeButtonClickAsync;
_nextEpisodeButton.Click += OnNextEpisodeButtonClickAsync;
_screenshotButton.Click += OnScreenshotButtonClickAsync;
_playbackRateNodeComboBox.SelectionChanged += OnPlaybackRateNodeComboBoxSelectionChanged;

if (_formatListView != null)
{
Expand Down Expand Up @@ -877,6 +879,16 @@ private void OnInteractionControlManipulationStarted(object sender, Manipulation
}
}

private void OnPlaybackRateNodeComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = _playbackRateNodeComboBox.SelectedItem;
if (item is double rate)
{
ViewModel.PlaybackRate = rate;
_playbackRateNodeComboBox.SelectedItem = null;
}
}

private void ShowTempMessage(string message)
{
_tempMessageContainer.Visibility = Visibility.Visible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,20 @@
<Run Text="{loc:LocaleLocator Name=PlaybackRate}" />
<Run Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlaybackRate, Mode=TwoWay}" />
</TextBlock>
<ComboBox
x:Name="PlaybackRateNodeComboBox"
HorizontalAlignment="Stretch"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlaybackRateNodeCollection}"
PlaceholderText="{loc:LocaleLocator Name=QuickSelection}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<Run Text="{Binding}" />
<Run Text="x" />
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Slider
x:Name="RateSlider"
Width="200"
Expand Down
3 changes: 3 additions & 0 deletions src/App/Resources/Strings/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,9 @@ BV号以 BV 开头,是一串英文数字混合的编号, 如 BV1JL4y1875w</v
<data name="QualitySuffix" xml:space="preserve">
<value>加入清晰度后缀</value>
</data>
<data name="QuickSelection" xml:space="preserve">
<value>快速选择</value>
</data>
<data name="Rank" xml:space="preserve">
<value>排行榜</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/Models/Models.Enums/App/LanguageNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ public enum LanguageNames
GlobalPlaybackRateDescription,
MyFavoriteAnime,
FirstClickTagTip,
QuickSelection,
#pragma warning restore SA1602 // Enumeration items should be documented
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Richasy. All rights reserved.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -1000,6 +1001,15 @@ private void InitializePlaybackRateProperties()
MaxPlaybackRate = isEnhancement ? 6d : 3d;
PlaybackRateStep = isEnhancement ? 0.2 : 0.1;

PlaybackRateNodeCollection.Clear();
var defaultList = new List<double> { 0.5, 0.75, 1.0, 1.25, 1.5, 2.0 };
if (isEnhancement)
{
defaultList = defaultList.Union(new List<double> { 2.5, 3.0, 3.5, 5.0 }).ToList();
}

defaultList.ForEach(p => PlaybackRateNodeCollection.Add(p));

var isGlobal = _settingsToolkit.ReadLocalSetting(SettingNames.GlobalPlaybackRate, false);
if (!isGlobal)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ public partial class PlayerViewModel
/// </summary>
public ObservableCollection<InteractionChoice> ChoiceCollection { get; }

/// <summary>
/// 播放速率节点集合.
/// </summary>
public ObservableCollection<double> PlaybackRateNodeCollection { get; }

/// <summary>
/// 当前分P.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public PlayerViewModel()
StaffCollection = new ObservableCollection<UserViewModel>();
ChoiceCollection = new ObservableCollection<InteractionChoice>();
TagCollection = new ObservableCollection<VideoTag>();
PlaybackRateNodeCollection = new ObservableCollection<double>();
_audioList = new List<DashItem>();
_videoList = new List<DashItem>();
_subtitleList = new List<SubtitleItem>();
Expand Down

0 comments on commit d7dab3a

Please sign in to comment.