Skip to content

Commit

Permalink
给播放窗口增加清晰度修改右键菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKZL committed Jul 5, 2024
1 parent a17f697 commit bce7fb5
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Core/Network/Methods/room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Room
/// <param name="RoomId"></param>
/// <param name="Definition">清晰度</param>
/// <returns></returns>
internal static PlayInfo_Class GetPlayInfo(long RoomId,int Definition)
internal static PlayInfo_Class GetPlayInfo(long RoomId,long Definition)
{
return _PlayInfo(RoomId,Definition);
}
Expand Down Expand Up @@ -54,7 +54,7 @@ internal static RoomInfo_Class GetRoomInfo(long RoomId)

#region Private Method

private static PlayInfo_Class _PlayInfo(long RoomId,int Definition)
private static PlayInfo_Class _PlayInfo(long RoomId,long Definition)
{
string WebText = Get.GetBody($"{Config.Core_RunConfig._LiveDomainName}/xlive/web-room/v2/index/getRoomPlayInfo?room_id={RoomId}&protocol=0,1&format=0,1,2&codec=0,1&qn={Definition}&platform=web&ptype=8", true);
PlayInfo_Class hLSHostClass = new();
Expand Down
37 changes: 31 additions & 6 deletions Core/RuntimeObject/Download/Basics.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ConsoleTableExt;
using AngleSharp.Io;
using ConsoleTableExt;
using Core.LiveChat;
using Core.LogModule;
using Core.Network.Methods;
Expand Down Expand Up @@ -342,7 +343,7 @@ internal static DlwnloadTaskState CheckAndHandleFile(string File, ref RoomCardCl
/// <param name="codec_name">编码(目前固定avc)</param>
/// <param name="Definition">清晰度等级</param>
/// <returns></returns>
public static HostClass _GetHost(long RoomId, string protocol_name, string format_name, string codec_name, int Definition = 10000)
public static HostClass _GetHost(long RoomId, string protocol_name, string format_name, string codec_name, long Definition = 10000)
{
HostClass hostClass = new();
PlayInfo_Class playInfo = GetPlayInfo(RoomId, Definition);
Expand Down Expand Up @@ -373,10 +374,34 @@ public static HostClass _GetHost(long RoomId, string protocol_name, string forma
return hostClass;
}

//public static string[] GetOptionalClarity(long RoomId)
//{

//}
/// <summary>
/// 获取可选清晰度列表
/// </summary>
/// <param name="RoomId">房间号</param>
/// <param name="protocol_name">类型(http_hls/http_stream)</param>
/// <param name="format_name">封装(flv/fmp4)</param>
/// <param name="codec_name">编码(目前固定avc)</param>
/// <returns></returns>
public static List<long> GetOptionalClarity(long RoomId, string protocol_name, string format_name, string codec_name)
{
List<long> Definition = new();
HostClass hostClass = new();
PlayInfo_Class playInfo = GetPlayInfo(RoomId, 10000);
if (playInfo == null || playInfo.data.playurl_info == null || playInfo.data.playurl_info.playurl == null)
return Definition;
hostClass.all_special_types = playInfo.data.all_special_types;
PlayInfo_Class.Stream? stream = playInfo.data.playurl_info.playurl.stream.FirstOrDefault(x => x.protocol_name == protocol_name);
if (stream == null)
return Definition;
PlayInfo_Class.Format? format = stream.format.FirstOrDefault(x => x.format_name == format_name);
if (format == null)
return Definition;
PlayInfo_Class.Codec? codec = format.codec.FirstOrDefault(x => x.codec_name == codec_name);
if (codec == null)
return Definition;
Definition = codec.accept_qn;
return Definition;
}



Expand Down
2 changes: 1 addition & 1 deletion Core/RuntimeObject/Download/HLS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private static DlwnloadTaskState HandleHlsError(RoomCardClass card, HostClass ho
/// <param name="Url"></param>
/// <returns></returns>

public static bool GetHlsAvcUrl(RoomCardClass roomCard,int Definition, out string Url)
public static bool GetHlsAvcUrl(RoomCardClass roomCard,long Definition, out string Url)
{
Url = "";
if (!RoomInfo.GetLiveStatus(roomCard.RoomId))
Expand Down
1 change: 0 additions & 1 deletion Desktop/Views/Pages/DataPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public void Init()
/// </summary>
public void Add_ImportFromFollowList_Menu()
{

Task.Run(() =>
{
try
Expand Down
70 changes: 60 additions & 10 deletions Desktop/Views/Windows/VlcPlayWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
using Key = System.Windows.Input.Key;
using MenuItem = Wpf.Ui.Controls.MenuItem;

namespace Desktop.Views.Windows
{
Expand Down Expand Up @@ -73,7 +74,7 @@ public partial class VlcPlayWindow : FluentWindow
/// <summary>
/// 当前窗口的清晰度
/// </summary>
public int CurrentWindowClarity = Core_RunConfig._DefaultPlayResolution;
public long CurrentWindowClarity = 10000;
public class DanMuOrbitInfo
{
public string Text { get; set; }
Expand All @@ -84,7 +85,7 @@ public VlcPlayWindow(long uid)
{
InitializeComponent();
vlcPlayModels = new();
CurrentWindowClarity =
CurrentWindowClarity = Core_RunConfig._DefaultPlayResolution;
this.DataContext = vlcPlayModels;
_Room.GetCardForUID(uid, ref roomCard);

Expand Down Expand Up @@ -112,11 +113,11 @@ public VlcPlayWindow(long uid)
videoView.MediaPlayer.Volume = 30;

Task.Run(() => InitVlcPlay(uid));

Task.Run(() => SetClarityMenu());
}
public void InitVlcPlay(long uid)
{
PlaySteam(null, CurrentWindowClarity);
PlaySteam(null);
Dispatcher.Invoke(() =>
{
barrageConfig = new BarrageConfig(DanmaCanvas, this.Width);
Expand All @@ -131,6 +132,55 @@ public void InitVlcPlay(long uid)
});
}

private void SetClarityMenu()
{
List<long> DefinitionList = Core.RuntimeObject.Download.Basics.GetOptionalClarity(roomCard.RoomId, "http_hls", "fmp4", "avc");

Dictionary<long, string> clarityMap = new Dictionary<long, string>
{
{30000, "杜比"},
{20000, "4K"},
{10000, "原画"},
{400, "蓝光"},
{250, "超清"},
{150, "高清"},
{80, "流畅"}
};

foreach (var clarity in clarityMap)
{
if (DefinitionList.Contains(clarity.Key))
{
Dispatcher.Invoke(() =>
{
MenuItem childMenuItem = new MenuItem
{
Header = clarity.Value,
Tag = clarity.Key
};
childMenuItem.Click += ModifyResolutionRightClickMenuEvent_Click;
SwitchPlaybackClarity_Menu.Items.Add(childMenuItem);
});
}
}
}


private void ModifyResolutionRightClickMenuEvent_Click(object sender, RoutedEventArgs e)
{
MenuItem clickedMenuItem = sender as MenuItem;

Dispatcher.Invoke(() =>
{
CurrentWindowClarity = (long)clickedMenuItem.Tag; // 获取被点击的菜单项的索引
});

vlcPlayModels.LoadingVisibility = Visibility.Visible;
vlcPlayModels.OnPropertyChanged("LoadingVisibility");

PlaySteam(null);
}

private void MediaPlayer_Playing(object? sender, EventArgs e)
{
Task.Run(() =>
Expand All @@ -145,7 +195,7 @@ private void MediaPlayer_EndReached(object? sender, EventArgs e)
{
vlcPlayModels.LoadingVisibility = Visibility.Visible;
vlcPlayModels.OnPropertyChanged("LoadingVisibility");
PlaySteam(null, CurrentWindowClarity);
PlaySteam(null);
}

private async void SetDanma()
Expand Down Expand Up @@ -211,7 +261,7 @@ private void LiveChatListener_MessageReceived(object? sender, Core.LiveChat.Mess
/// 播放网络路径直播流
/// </summary>
/// <param name="Url"></param>
public async void PlaySteam(string Url = null, int Definition = 10000)
public async void PlaySteam(string Url = null)
{
Log.Info(nameof(PlaySteam), $"房间号:[{roomCard.RoomId}],播放网络路径直播流");
await Task.Run(() =>
Expand All @@ -235,7 +285,7 @@ await Task.Run(() =>
}
if (string.IsNullOrEmpty(Url))
{
Url = GeUrl(Core_RunConfig._DefaultPlayResolution);
Url = GeUrl(CurrentWindowClarity);
}
try
{
Expand Down Expand Up @@ -293,7 +343,7 @@ await Task.Run(() =>
/// </summary>
/// <param name="uid"></param>
/// <returns></returns>
public string GeUrl(int Definition)
public string GeUrl(long Definition)
{
string url = "";
if (roomCard != null && (Core.RuntimeObject.Download.HLS.GetHlsAvcUrl(roomCard, Definition, out url)))
Expand Down Expand Up @@ -488,7 +538,7 @@ private void FluentWindow_KeyDown(object sender, System.Windows.Input.KeyEventAr
{
vlcPlayModels.LoadingVisibility = Visibility.Visible;
vlcPlayModels.OnPropertyChanged("LoadingVisibility");
PlaySteam(null, CurrentWindowClarity);
PlaySteam(null);
}
}

Expand Down Expand Up @@ -518,7 +568,7 @@ private void F5_MenuItem_Click(object sender, RoutedEventArgs e)
{
vlcPlayModels.LoadingVisibility = Visibility.Visible;
vlcPlayModels.OnPropertyChanged("LoadingVisibility");
PlaySteam(null, CurrentWindowClarity);
PlaySteam(null);
}

private void MenuItem_Switch_Danma_Send_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit bce7fb5

Please sign in to comment.