Skip to content

Commit

Permalink
支持设置默认最大音质,未找到指定音质时默认音质改为192K
Browse files Browse the repository at this point in the history
  • Loading branch information
ywmoyue committed Aug 26, 2024
1 parent 0926456 commit 0b17a80
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/BiliLite.UWP/Controls/Settings/PlaySettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
<ToggleSwitch x:Name="swPlayerSettingAutoFullWindows" ></ToggleSwitch>
</controls:SettingsCard>

<controls:SettingsCard Header="默认最大音质"
Description="不指定音质或找不到指定音质时,默认使用最大音质">
<controls:SettingsCard.HeaderIcon>
<font:FontAwesome Icon="Solid_Music"></font:FontAwesome>
</controls:SettingsCard.HeaderIcon>
<ToggleSwitch x:Name="SwitchEnableDefaultMaxSoundQuality" ></ToggleSwitch>
</controls:SettingsCard>

<controls:SettingsCard Header="双击播放器全屏"
Description="默认双击暂停">
<controls:SettingsCard.HeaderIcon>
Expand Down
10 changes: 10 additions & 0 deletions src/BiliLite.UWP/Controls/Settings/PlaySettingsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ private void LoadPlayer()
SettingService.SetValue(SettingConstants.Player.AUTO_FULL_WINDOW, swPlayerSettingAutoFullWindows.IsOn);
});
});
//默认最大音质
SwitchEnableDefaultMaxSoundQuality.IsOn = SettingService.GetValue(SettingConstants.Player.ENABLE_DEFAULT_MAX_SOUND_QUALITY,
SettingConstants.Player.DEFAULT_ENABLE_DEFAULT_MAX_SOUND_QUALITY);
SwitchEnableDefaultMaxSoundQuality.Loaded += (sender, e) =>
{
SwitchEnableDefaultMaxSoundQuality.Toggled += (obj, args) =>
{
SettingService.SetValue(SettingConstants.Player.ENABLE_DEFAULT_MAX_SOUND_QUALITY, SwitchEnableDefaultMaxSoundQuality.IsOn);
};
};
//自动全屏
swPlayerSettingAutoFullScreen.IsOn = SettingService.GetValue<bool>(SettingConstants.Player.AUTO_FULL_SCREEN, false);
swPlayerSettingAutoFullScreen.Loaded += new RoutedEventHandler((sender, e) =>
Expand Down
12 changes: 12 additions & 0 deletions src/BiliLite.UWP/Models/Common/SettingConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,18 @@ public class Player
[SettingKey(typeof(int))]
public const string DEFAULT_SOUND_QUALITY = "PlayerDefaultSoundQuality";

/// <summary>
/// 启用默认最大音质
/// </summary>
[SettingKey(typeof(bool))]
public const string ENABLE_DEFAULT_MAX_SOUND_QUALITY = "PlayerEnableDefaultMaxSoundQuality";

/// <summary>
/// 默认不启用默认最大音质
/// </summary>
[SettingDefaultValue]
public const bool DEFAULT_ENABLE_DEFAULT_MAX_SOUND_QUALITY = false;

/// <summary>
/// 比例 int
/// </summary>
Expand Down
28 changes: 28 additions & 0 deletions src/BiliLite.UWP/Models/Common/Video/SoundQualityDictionary.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using BiliLite.Models.Common.Video.PlayUrlInfos;
using BiliLite.Services;

namespace BiliLite.Models.Common.Video
{
public static class SoundQualityConstants
{
/// <summary>
/// 音质Id,音质名称
/// 根据音质大小从低到高排序
/// </summary>
private static Dictionary<int, string> m_dictionary = new Dictionary<int, string>()
{
{30216,"64K" },
Expand All @@ -20,5 +27,26 @@ public static Dictionary<int, string> Dictionary
return m_dictionary;
}
}

public static BiliDashAudioPlayUrlInfo GetDefaultAudio(List<BiliDashAudioPlayUrlInfo> audios)
{
var enableMaxQuality = SettingService.GetValue(
SettingConstants.Player.ENABLE_DEFAULT_MAX_SOUND_QUALITY,
SettingConstants.Player.DEFAULT_ENABLE_DEFAULT_MAX_SOUND_QUALITY
);

var preferredQualityIds = enableMaxQuality
? new[] { 30251, 30250, 30280, 30232, 30216 }
: new[] { 30280, 30232, 30216, 30251, 30250 };

foreach (var qualityId in preferredQualityIds)
{
var audio = audios.FirstOrDefault(x => x.QualityID == qualityId);
if (audio != null)
return audio;
}

return audios.FirstOrDefault();
}
}
}
4 changes: 2 additions & 2 deletions src/BiliLite.UWP/Modules/Player/Playurl/BiliPlayUrlRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ private async Task<BiliDashItem> ParseBiliPlayUrlInfoAudioDash(BiliPlayUrlQualit
if (audios.Any())
{
var audioQuality = info.AudioQualites.FirstOrDefault(x => x.QualityID == soundQualityId);
var defaultAudio = qn > 64 ? audios.LastOrDefault() : audios.FirstOrDefault();
info.CurrentAudioQuality = audioQuality ?? info.AudioQualites.FirstOrDefault(x => x.QualityID == defaultAudio.id);
var defaultAudio = SoundQualityConstants.GetDefaultAudio(info.AudioQualites);
info.CurrentAudioQuality = audioQuality ?? defaultAudio;
currentAudio = info.CurrentAudioQuality.Audio;
}
return currentAudio;
Expand Down

0 comments on commit 0b17a80

Please sign in to comment.