Skip to content

Commit

Permalink
添加播放速率选择 (Richasy#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy committed Oct 1, 2021
1 parent c63f410 commit bb6ae34
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,33 @@
Modifiers="Control" />
</Button.KeyboardAccelerators>
</Button>
<Button x:Name="PlaybackRateButton" Style="{StaticResource MTCButtonStyle}">
<Button
x:Name="RateButton"
AutomationProperties.Name="{loc:LocaleLocator Name=PlaybackRate}"
Style="{StaticResource MTCButtonStyle}"
ToolTipService.ToolTip="{loc:LocaleLocator Name=PlaybackRate}">
<Button.Content>
<icons:RegularFluentIcon Symbol="Replay20" />
</Button.Content>
<Button.Flyout>
<Flyout>
<StackPanel Spacing="4">
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" HorizontalAlignment="Left">
<Run Text="{loc:LocaleLocator Name=PlaybackRate}" />
<Run Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlaybackRate, Mode=TwoWay}" />
</TextBlock>
<Slider
x:Name="RateSlider"
Width="200"
Maximum="3"
Minimum="0.5"
StepFrequency="0.1"
TickFrequency="0.1"
TickPlacement="Outside"
Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlaybackRate, Mode=TwoWay}" />
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsLive}">
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 @@ -728,6 +728,9 @@
<data name="PgcNotFollow" xml:space="preserve">
<value>追</value>
</data>
<data name="PlaybackRate" xml:space="preserve">
<value>播放速率</value>
</data>
<data name="PlayCount" 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 @@ -370,6 +370,7 @@ public enum LanguageNames
FailedToLoadInteractionVideo,
InteractionEnd,
BackToStart,
PlaybackRate,
#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 @@ -36,6 +36,7 @@ public enum SettingNames
DoubleClickBehavior,
IsShowDanmakuBar,
CanShowSubtitle,
PlaybackRate,
#pragma warning disable SA1602 // Enumeration items should be documented
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ private void OnMediaPlayerOpened(MediaPlayer sender, object args)
session.Position = _initializeProgress;
_initializeProgress = TimeSpan.Zero;
}

session.PlaybackRate = PlaybackRate;
}

var props = _currentPlaybackItem.GetDisplayProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,12 @@ public partial class PlayerViewModel
[Reactive]
public ObservableCollection<SubtitleIndexItemViewModel> SubtitleIndexCollection { get; set; }

/// <summary>
/// 播放速率.
/// </summary>
[Reactive]
public double PlaybackRate { get; set; }

/// <summary>
/// 选项集合.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public PlayerViewModel()
IsShowDanmakuBar = _settingsToolkit.ReadLocalSetting(SettingNames.IsShowDanmakuBar, false);
CanShowSubtitle = _settingsToolkit.ReadLocalSetting(SettingNames.CanShowSubtitle, true);
Volume = _settingsToolkit.ReadLocalSetting(SettingNames.Volume, 100d);
PlaybackRate = _settingsToolkit.ReadLocalSetting(SettingNames.PlaybackRate, 1d);
InitializeTimer();
this.PropertyChanged += OnPropertyChanged;
LiveDanmakuCollection.CollectionChanged += OnLiveDanmakuCollectionChanged;
Expand Down Expand Up @@ -595,6 +596,14 @@ private void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
case nameof(CanShowSubtitle):
_settingsToolkit.WriteLocalSetting(SettingNames.CanShowSubtitle, CanShowSubtitle);
break;
case nameof(PlaybackRate):
if (_currentVideoPlayer != null && _currentVideoPlayer.PlaybackSession != null)
{
_currentVideoPlayer.PlaybackSession.PlaybackRate = PlaybackRate;
}

_settingsToolkit.WriteLocalSetting(SettingNames.PlaybackRate, PlaybackRate);
break;
default:
break;
}
Expand Down

0 comments on commit bb6ae34

Please sign in to comment.