Skip to content

Commit

Permalink
#831 #767 #723 #587 支持设置优先播放器类型
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed Sep 29, 2024
1 parent b239e72 commit 56acfcf
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/BiliLite.UWP/BiliLite.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
<Compile Include="Models\Common\Danmaku\BiliDanmakuItem.cs" />
<Compile Include="Models\Common\Dynamic\DynamicUgcSeasonCardModel.cs" />
<Compile Include="Models\Common\MarkdownViewerPagerParameter.cs" />
<Compile Include="Models\Common\Player\RealPlayerType.cs" />
<Compile Include="Models\Common\Player\PlaySpeedMenu.cs" />
<Compile Include="Models\Common\Season\EpisodeSkip.cs" />
<Compile Include="Models\Common\Player\PlayerSkipItem.cs" />
Expand Down
4 changes: 3 additions & 1 deletion src/BiliLite.UWP/Controls/Player.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ private MediaSourceConfig CreateFFmpegInteropConfig(string userAgent, string ref
if (referer != null && referer.Length > 0)
{
_ffmpegConfig.FFmpegOptions.Add("referer", referer);
_ffmpegConfig.FFmpegOptions.Add("headers", $"Referer: {referer}");
}

_ffmpegConfig.VideoDecoderMode = passthrough ? VideoDecoderMode.ForceSystemDecoder : VideoDecoderMode.ForceFFmpegSoftwareDecoder;
Expand Down Expand Up @@ -520,7 +521,7 @@ public async Task<PlayerOpenResult> PlayerDashUseNative(BiliDashPlayUrlInfo dash
message = "创建MediaSource失败"
};
}

m_playerVideo.Source = MediaSource.CreateFromAdaptiveMediaSource(mediaSource);
Buffering = true;

Expand Down Expand Up @@ -665,6 +666,7 @@ public async Task<PlayerOpenResult> PlayDashUseFFmpegInterop(BiliDashPlayUrlInfo
//关闭正在播放的视频
ClosePlay();
var _ffmpegConfig = CreateFFmpegInteropConfig(userAgent, referer);

if (isLocal)
{

Expand Down
40 changes: 19 additions & 21 deletions src/BiliLite.UWP/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,31 +1566,29 @@ private async Task<PlayerOpenResult> ChangeQualityPlayVideo(BiliPlayUrlInfo qual
};
if (quality.PlayUrlType == BiliPlayUrlType.DASH)
{
var audio = audioQuality == null ? quality.DashInfo.Audio : audioQuality.Audio;
var video = quality.DashInfo.Video;

result = await Player.PlayerDashUseNative(quality.DashInfo, quality.UserAgent, quality.Referer, positon: _postion);
var realPlayerType = (RealPlayerType)SettingService.GetValue(SettingConstants.Player.USE_REAL_PLAYER_TYPE, (int)SettingConstants.Player.DEFAULT_USE_REAL_PLAYER_TYPE);
if (realPlayerType==RealPlayerType.Native)
{
result = await Player.PlayerDashUseNative(quality.DashInfo, quality.UserAgent, quality.Referer, positon: _postion);

if (!result.result)
if (!result.result)
{
result = await Player.PlayDashUseFFmpegInterop(quality.DashInfo, quality.UserAgent, quality.Referer,
positon: _postion);
}
}
else
{
var mpd_url = new PlayerAPI().GenerateMPD(new Models.GenerateMPDModel()
result = await Player.PlayDashUseFFmpegInterop(quality.DashInfo, quality.UserAgent, quality.Referer,
positon: _postion);

if (!result.result)
{
AudioBandwidth = audio.BandWidth.ToString(),
AudioCodec = audio.Codecs,
AudioID = audio.ID.ToString(),
AudioUrl = audio.Url,
Duration = quality.DashInfo.Duration,
DurationMS = quality.Timelength,
VideoBandwidth = video.BandWidth.ToString(),
VideoCodec = video.Codecs,
VideoID = video.ID.ToString(),
VideoFrameRate = video.FrameRate.ToString(),
VideoHeight = video.Height,
VideoWidth = video.Width,
VideoUrl = video.Url,
});
result = await Player.PlayDashUrlUseFFmpegInterop(mpd_url, quality.UserAgent, quality.Referer, positon: _postion);

result = await Player.PlayerDashUseNative(quality.DashInfo, quality.UserAgent, quality.Referer, positon: _postion);
}
}

}
else if (quality.PlayUrlType == BiliPlayUrlType.SingleFLV)
{
Expand Down
12 changes: 12 additions & 0 deletions src/BiliLite.UWP/Controls/Settings/PlaySettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
DisplayMemberPath="Name"></ComboBox>
</controls:SettingsCard>

<controls:SettingsCard Header="优先播放器类型"
Description="如果遇到加载卡顿、磁盘占用高等问题,请尝试修改优先播放器类型">
<controls:SettingsCard.HeaderIcon>
<font:FontAwesome Icon="Solid_PhotoVideo"></font:FontAwesome>
</controls:SettingsCard.HeaderIcon>
<ComboBox x:Name="ComboBoxUseRealPlayerType" SelectedIndex="0" MinWidth="200"
SelectedValuePath="Value"
DisplayMemberPath="Content"
ItemsSource="{x:Bind m_realPlayerTypes.Options}">
</ComboBox>
</controls:SettingsCard>

<!--<TextBlock Margin="0 16 0 8" FontSize="16" Visibility="Collapsed">优先使用FFmpeg播放器</TextBlock>
<ToggleSwitch x:Name="swPriorityFFmpeg" Visibility="Collapsed"></ToggleSwitch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using BiliLite.Services;
using BiliLite.ViewModels.Settings;
using System.Linq;
using BiliLite.Models.Common.Player;

//https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板

Expand All @@ -16,6 +17,7 @@ public sealed partial class PlaySettingsControl : UserControl
{
private readonly PlaySettingsControlViewModel m_viewModel;
private readonly PlaySpeedMenuService m_playSpeedMenuService;
private readonly RealPlayerTypes m_realPlayerTypes = new RealPlayerTypes();

public PlaySettingsControl()
{
Expand All @@ -34,6 +36,13 @@ private void LoadPlayer()
{
SettingService.SetValue(SettingConstants.Player.DEFAULT_VIDEO_TYPE, (int)cbVideoType.SelectedValue);
};
//优先播放器类型
var realPlayerType = (RealPlayerType)SettingService.GetValue(SettingConstants.Player.USE_REAL_PLAYER_TYPE, (int)SettingConstants.Player.DEFAULT_USE_REAL_PLAYER_TYPE);
ComboBoxUseRealPlayerType.SelectedItem = realPlayerType;
ComboBoxUseRealPlayerType.SelectionChanged += (e, args) =>
{
SettingService.SetValue(SettingConstants.Player.USE_REAL_PLAYER_TYPE, (int)ComboBoxUseRealPlayerType.SelectedValue);
};
//视频倍速
var speeds = m_playSpeedMenuService.MenuItems
.Select(x => x.Value)
Expand Down
26 changes: 26 additions & 0 deletions src/BiliLite.UWP/Models/Common/Player/RealPlayerType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;

namespace BiliLite.Models.Common.Player
{
public enum RealPlayerType
{
Native,
FFmpegInterop,
}

public class RealPlayerTypes
{
public List<RealPlayerTypeOption> Options = new List<RealPlayerTypeOption>()
{
new RealPlayerTypeOption() { Value = RealPlayerType.Native },
new RealPlayerTypeOption() { Value = RealPlayerType.FFmpegInterop },
};
}

public class RealPlayerTypeOption
{
public RealPlayerType Value { get; set; }

public string Content => Value.ToString();
}
}
10 changes: 10 additions & 0 deletions src/BiliLite.UWP/Models/Common/SettingConstants.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using BiliLite.Models.Attributes;
using BiliLite.Models.Common.Player;
using BiliLite.Services;

namespace BiliLite.Models.Common
Expand Down Expand Up @@ -584,6 +585,15 @@ public class Live

public class Player
{
/// <summary>
/// 优先使用播放器类型
/// </summary>
[SettingKey(typeof(int))]
public const string USE_REAL_PLAYER_TYPE = "UseRealPlayerType";

[SettingDefaultValue]
public const RealPlayerType DEFAULT_USE_REAL_PLAYER_TYPE = RealPlayerType.Native;

/// <summary>
/// 使用外站视频替换无法播放的视频 bool
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BiliPlayUrlRequest
/// </summary>
public string Message { get; set; } = "";

public const string WebUserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36";
public const string WebUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36";
public const string WebReferer = "https://www.bilibili.com";
public const string AndroidUserAgent = "Bilibili Freedoooooom/MarkII";

Expand Down

0 comments on commit 56acfcf

Please sign in to comment.