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

Commit

Permalink
支持视频无痕播放 (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy authored Oct 10, 2022
1 parent 445dbf2 commit 8f2d634
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/App/Controls/Videos/VideoItem/VideoItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
xmlns:muxc="using:Microsoft.UI.Xaml.Controls">

<MenuFlyout x:Key="DefaultVideoItemContextFlyout">
<MenuFlyoutItem Command="{Binding PlayInPrivateCommand}" Text="{loc:Locale Name=PlayInPrivate}">
<MenuFlyoutItem.Icon>
<icons:RegularFluentIcon Symbol="WindowInprivate20" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
Command="{Binding Publisher.ShowDetailCommand}"
IsEnabled="{Binding Publisher.User, Converter={StaticResource ObjectToBoolConverter}}"
Expand Down
3 changes: 3 additions & 0 deletions src/App/Resources/Strings/zh-Hans/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,9 @@ UGC优先级:分P &gt; 播放列表 &gt; 合集视频 &gt; 关联视频 (如
<data name="PlayerTypeDescription" xml:space="preserve">
<value>对于集显或无显,建议使用原生播放;独显或者原生播放有问题的,可以使用FFmpeg播放</value>
</data>
<data name="PlayInPrivate" xml:space="preserve">
<value>无痕播放</value>
</data>
<data name="PlayLine" xml:space="preserve">
<value>线路</value>
</data>
Expand Down
5 changes: 4 additions & 1 deletion src/App/Resources/Strings/zh-Hant/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,9 @@ UGC優先級:分P &gt; 播放列表 &gt; 合集影片 &gt; 關聯影片 (如
<data name="PlayerTypeDescription" xml:space="preserve">
<value>對於集顯或無顯,建議使用原生播放;獨顯或者原生播放有問題的,可以使用FFmpeg播放</value>
</data>
<data name="PlayInPrivate" xml:space="preserve">
<value>無痕播放</value>
</data>
<data name="PlayLine" xml:space="preserve">
<value>線路</value>
</data>
Expand Down Expand Up @@ -1714,4 +1717,4 @@ UGC優先級:分P &gt; 播放列表 &gt; 合集影片 &gt; 關聯影片 (如
<data name="ZoomOut" xml:space="preserve">
<value>縮小</value>
</data>
</root>
</root>
5 changes: 5 additions & 0 deletions src/Models/Models.Data/Local/PlaySnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ public PlaySnapshot(string vid, string sid, VideoType type)
/// 是否需要借助 BiliPlus 服务获取视频对应的剧集信息.
/// </summary>
public bool NeedBiliPlus { get; set; }

/// <summary>
/// 是否以无痕模式浏览.
/// </summary>
public bool IsInPrivate { get; set; }
}
}
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 @@ -540,6 +540,7 @@ public enum LanguageNames
HDFirst,
PreferQuality,
EnterUserSpace,
PlayInPrivate,
#pragma warning restore SA1602 // Enumeration items should be documented
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ public interface IMediaPlayerViewModel : INotifyPropertyChanged, IReloadViewMode
/// 设置视频播放数据.
/// </summary>
/// <param name="data">视频视图数据.</param>
void SetVideoData(VideoPlayerView data);
/// <param name="isInPrivate">是否为无痕浏览.</param>
void SetVideoData(VideoPlayerView data, bool isInPrivate = false);

/// <summary>
/// 设置 PGC 播放数据.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public interface IVideoItemViewModel : IVideoBaseViewModel<VideoInformation>, II
/// </summary>
public IRelayCommand PlayCommand { get; }

/// <summary>
/// 无痕播放命令.
/// </summary>
public IRelayCommand PlayInPrivateCommand { get; }

/// <summary>
/// 发布者.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private async Task ReportViewProgressAsync()
var progress = _player.Position;
if (progress != _lastReportProgress && progress > TimeSpan.Zero)
{
if (_videoType == VideoType.Video)
if (_videoType == VideoType.Video && !_isInPrivate)
{
var view = _viewData as VideoPlayerView;
var aid = view.Information.Identifier.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public sealed partial class MediaPlayerViewModel
private IPlayerViewModel _player;
private VideoType _videoType;
private object _viewData;
private bool _isInPrivate;
private VideoIdentifier _currentPart;
private EpisodeInformation _currentEpisode;
private LivePlaylineInformation _currentPlayline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ public MediaPlayerViewModel(
}

/// <inheritdoc/>
public void SetVideoData(VideoPlayerView data)
public void SetVideoData(VideoPlayerView data, bool isInPrivate = false)
{
_viewData = data;
_isInPrivate = isInPrivate;
_videoType = VideoType.Video;
ReloadCommand.ExecuteAsync(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public sealed partial class VideoItemViewModel
/// <inheritdoc/>
public IRelayCommand PlayCommand { get; }

/// <inheritdoc/>
public IRelayCommand PlayInPrivateCommand { get; }

/// <inheritdoc/>
public override bool Equals(object obj) => obj is VideoItemViewModel model && EqualityComparer<VideoInformation>.Default.Equals(Data, model.Data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public VideoItemViewModel(
_navigationViewModel = navigationViewModel;
_callerViewModel = callerViewModel;

PlayCommand = new RelayCommand(Play);
PlayCommand = new RelayCommand(() => Play());
PlayInPrivateCommand = new RelayCommand(() => Play(true));
AddToViewLaterCommand = new AsyncRelayCommand(AddToViewLaterAsync);
RemoveFromViewLaterCommand = new AsyncRelayCommand(RemoveFromViewLaterAsync);
RemoveFromHistoryCommand = new AsyncRelayCommand(RemoveFromHistoryAsync);
Expand Down Expand Up @@ -96,9 +97,10 @@ private void InitializeData()
}
}

private void Play()
private void Play(bool isInPrivate = false)
{
var snapshot = new Models.Data.Local.PlaySnapshot(Data.Identifier.Id, "0", VideoType.Video);
snapshot.IsInPrivate = isInPrivate;
if (_navigationViewModel.IsPlayViewShown && _navigationViewModel.PlayViewId == PageIds.VideoPlayer)
{
var videoPlayerPageVM = Locator.Instance.GetService<IVideoPlayerPageViewModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public sealed partial class VideoPlayerPageViewModel

private string _presetVideoId;
private Action _playNextVideoAction;
private bool _isInPrivate;

[ObservableProperty]
private VideoPlayerView _view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void SetSnapshot(PlaySnapshot snapshot)
{
ReloadMediaPlayer();
_presetVideoId = snapshot.VideoId;
_isInPrivate = snapshot.IsInPrivate;
var defaultPlayMode = _settingsToolkit.ReadLocalSetting(SettingNames.DefaultPlayerDisplayMode, PlayerDisplayMode.Default);
MediaPlayerViewModel.DisplayMode = snapshot.DisplayMode ?? defaultPlayMode;
ReloadCommand.ExecuteAsync(null);
Expand Down Expand Up @@ -150,7 +151,7 @@ private async Task GetDataAsync()
InitializeSections();
InitializeInterop();

MediaPlayerViewModel.SetVideoData(View);
MediaPlayerViewModel.SetVideoData(View, _isInPrivate);
}

private void Clear()
Expand Down

0 comments on commit 8f2d634

Please sign in to comment.