Skip to content

Commit

Permalink
Merge pull request #535 from ywmoyue/dev
Browse files Browse the repository at this point in the history
4.6.28
  • Loading branch information
ywmoyue authored Mar 23, 2024
2 parents 2d62df5 + 693dd5e commit e43b25d
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 27 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 @@ -144,6 +144,7 @@
</Compile>
<Compile Include="Extensions\QrCodeExtensions.cs" />
<Compile Include="Models\Common\Anime\ISeasonItem.cs" />
<Compile Include="Models\Common\Danmaku\BiliDanmakuItem.cs" />
<Compile Include="Models\Common\Dynamic\DynamicUgcSeasonCardModel.cs" />
<Compile Include="Models\Common\Home\DefaultHomeNavItems.cs" />
<Compile Include="Models\Common\Live\DefaultPlayUrlSourceOptions.cs" />
Expand Down
11 changes: 10 additions & 1 deletion src/BiliLite.UWP/Controls/AttentionButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ public AttentionButton()
public int Attention
{
get => m_viewModel.Attention;
set => m_viewModel.Attention = value;
set
{
if (value < 0)
{
m_viewModel.Attention = 0;
return;
}

m_viewModel.Attention = value;
}
}

public static readonly DependencyProperty UserIdProperty =
Expand Down
67 changes: 50 additions & 17 deletions src/BiliLite.UWP/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using BiliLite.Models.Common.Video.PlayUrlInfos;
using BiliLite.Services.Interfaces;
using BiliLite.ViewModels;
using Microsoft.Extensions.DependencyInjection;

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

Expand Down Expand Up @@ -148,12 +149,12 @@ public PlayerControl()
(int)SettingConstants.VideoDanmaku.DEFAULT_DANMAKU_ENGINE) == DanmakuEngineType.NSDanmaku;
if (m_useNsDanmaku)
{
m_danmakuController = new NsDanmakuController();
m_danmakuController = App.ServiceProvider.GetRequiredService<NsDanmakuController>();
m_danmakuController.Init(DanmuControl);
}
else
{
m_danmakuController = new FrostMasterDanmakuController();
m_danmakuController = App.ServiceProvider.GetRequiredService<FrostMasterDanmakuController>();
m_danmakuController.Init(DanmakuCanvas);
}
}
Expand Down Expand Up @@ -207,7 +208,8 @@ private void PlayerControl_Unloaded(object sender, RoutedEventArgs e)
}
timer_focus.Stop();
}
private void PlayerControl_Loaded(object sender, RoutedEventArgs e)

private async void PlayerControl_Loaded(object sender, RoutedEventArgs e)
{
m_danmakuController.Clear();
Window.Current.CoreWindow.KeyDown += PlayerControl_KeyDown;
Expand All @@ -223,6 +225,7 @@ private void PlayerControl_Loaded(object sender, RoutedEventArgs e)
updater.VideoProperties.Title = CurrentPlayItem.title;
updater.Update();
}

_systemMediaTransportControls.ButtonPressed += _systemMediaTransportControls_ButtonPressed;

LoadPlayerSetting();
Expand All @@ -231,6 +234,25 @@ private void PlayerControl_Loaded(object sender, RoutedEventArgs e)

danmuTimer.Start();
timer_focus.Start();

// 检查音量是否偏低
if (Player.Volume > 0.95) return;
var toolTipText = "";
if (Player.Volume == 0)
{
toolTipText = "静音";
}
else
{
toolTipText = "音量:" + Player.Volume.ToString("P");
}

TxtToolTip.Text = toolTipText;
ToolTip.Background = new SolidColorBrush(Color.FromArgb(90, 240, 240, 240));
ToolTip.Visibility = Visibility.Visible;
await Task.Delay(2000);
ToolTip.Visibility = Visibility.Collapsed;
ToolTip.Background = new SolidColorBrush(Color.FromArgb(204, 255, 255, 255));
}

private async void _systemMediaTransportControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
Expand Down Expand Up @@ -841,6 +863,9 @@ private List<DanmakuItem> FilterFrostDanmaku(IEnumerable<DanmakuItem> danmakus)
.SelectMany(x => x.Value.Take(max));
}

// 移除当前播放时间之前的弹幕,避免弹幕堆叠
danmakus = danmakus.Where(x => x.StartMs > Player.Position * 1000);

return danmakus.ToList();
}

Expand Down Expand Up @@ -916,6 +941,11 @@ private async void DanmuTimer_Tick(object sender, object e)
{
await LoadDanmaku(segIndex);
}
else if (position < m_danmakuController.Position && !m_useNsDanmaku)
{
await LoadDanmaku(segIndex);
}

if (Buffering)
{
return;
Expand Down Expand Up @@ -1330,13 +1360,16 @@ private async Task SetDanmaku(bool update = false)
}
else
{
var segIndex = Math.Ceiling(Player.Position / (60 * 6d));
if (update)
{
var segIndex = Math.Ceiling(Player.Position / (60 * 6d));
await LoadDanmaku(segIndex.ToInt32());
Notify.ShowMessageToast($"已更新弹幕");
}
await LoadDanmaku(1);
else
{
await LoadDanmaku(1);
}
//var danmuList = (await danmakuParse.ParseBiliBili(Convert.ToInt64(CurrentPlayItem.cid)));
////await playerHelper.GetDanmaku(CurrentPlayItem.cid, 1) ;
//danmakuPool = danmuList.GroupBy(x=>x.time_s).ToDictionary(x => x.Key, x => x.ToList());
Expand Down Expand Up @@ -2591,13 +2624,13 @@ private async void BottomBtnSendDanmakuWide_Click(object sender, RoutedEventArgs
SendDanmakuDialog sendDanmakuDialog = new SendDanmakuDialog(CurrentPlayItem.avid, CurrentPlayItem.cid, Player.Position);
sendDanmakuDialog.DanmakuSended += new EventHandler<SendDanmakuModel>((obj, arg) =>
{
m_danmakuController.Add(new DanmakuModel()
m_danmakuController.Add(new BiliDanmakuItem()
{
color = NSDanmaku.Utils.ToColor(arg.color),
text = arg.text,
location = (DanmakuLocation)arg.location,
size = 25,
time = Player.Position
Color = NSDanmaku.Utils.ToColor(arg.color),
Text = arg.text,
Location = (DanmakuLocation)arg.location,
Size = 25,
Time = Player.Position
}, true);
});
await sendDanmakuDialog.ShowAsync();
Expand Down Expand Up @@ -2698,13 +2731,13 @@ private async void SendDanmaku()
var result = await playerHelper.SendDanmaku(CurrentPlayItem.avid, CurrentPlayItem.cid, SendDanmakuTextBox.Text, Convert.ToInt32(Player.Position), modeInt, color);
if (result)
{
m_danmakuController.Add(new DanmakuModel()
m_danmakuController.Add(new BiliDanmakuItem()
{
color = NSDanmaku.Utils.ToColor(color),
text = SendDanmakuTextBox.Text,
location = location,
size = 25,
time = Player.Position
Color = NSDanmaku.Utils.ToColor(color),
Text = SendDanmakuTextBox.Text,
Location = location,
Size = 25,
Time = Player.Position
}, true);
SendDanmakuTextBox.Text = "";
}
Expand Down
9 changes: 9 additions & 0 deletions src/BiliLite.UWP/Extensions/DanmakuExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
using Atelier39;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Linq;
using System;
using System.Net;
using BiliLite.Services;

namespace BiliLite.Extensions
{
public static class DanmakuExtensions
{
public static IServiceCollection AddDanmakuController(this IServiceCollection services)
{
services.AddTransient<NsDanmakuController>();
services.AddTransient<FrostMasterDanmakuController>();
return services;
}

public static void ParseAdvanceDanmaku(this DanmakuItem danmakuItem)
{
var content = danmakuItem.Text;
Expand Down
18 changes: 18 additions & 0 deletions src/BiliLite.UWP/Extensions/MapperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BiliLite.Models.Common;
using BiliLite.Models.Common.Anime;
using BiliLite.Models.Common.Comment;
using BiliLite.Models.Common.Danmaku;
using BiliLite.Models.Common.Download;
using BiliLite.Models.Common.Dynamic;
using BiliLite.Models.Common.Home;
Expand All @@ -28,6 +29,8 @@
using BiliLite.ViewModels.UserDynamic;
using BiliLite.ViewModels.Video;
using Microsoft.Extensions.DependencyInjection;
using NSDanmaku.Model;
using DanmakuMode = Atelier39.DanmakuMode;
using DynamicType = Bilibili.App.Dynamic.V2.DynamicType;

namespace BiliLite.Extensions
Expand Down Expand Up @@ -55,6 +58,21 @@ public static IServiceCollection AddMapper(this IServiceCollection services)
expression.CreateMap<UserCenterInfoModel, UserCenterInfoViewModel>();
expression.CreateMap<FollowTlistItemModel, UserRelationFollowingTagViewModel>();

var danmakuModeConvertDic = new Dictionary<DanmakuLocation, DanmakuMode>()
{
{ DanmakuLocation.Scroll, DanmakuMode.Rolling },
{ DanmakuLocation.Top, DanmakuMode.Top },
{ DanmakuLocation.Bottom, DanmakuMode.Bottom },
{ DanmakuLocation.Position, DanmakuMode.Unknown },
{ DanmakuLocation.Other, DanmakuMode.Unknown },
};
expression.CreateMap<BiliDanmakuItem, DanmakuModel>();
expression.CreateMap<BiliDanmakuItem, DanmakuItem>()
.ForMember(dest => dest.BaseFontSize, opt => opt.MapFrom(src => src.Size))
.ForMember(dest => dest.TextColor, opt => opt.MapFrom(src => src.Color))
.ForMember(dest => dest.StartMs, opt => opt.MapFrom(src => src.Time))
.ForMember(dest => dest.Mode, opt => opt.MapFrom(src => danmakuModeConvertDic.GetValueOrDefault(src.Location)));

expression.CreateMap<DownloadSaveEpisodeInfo, DownloadedSubItem>()
.ForMember(dest => dest.Paths, opt => opt.MapFrom(src => new List<string>()))
.ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.EpisodeTitle))
Expand Down
1 change: 1 addition & 0 deletions src/BiliLite.UWP/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
VerticalContentAlignment="Stretch"
Loaded="tabView_Loaded"
IsAddTabButtonVisible="True"
PreviewKeyDown="TabView_OnPreviewKeyDown"
TabCloseRequested="TabView_TabCloseRequested"
AddTabButtonClick="TabView_AddTabButtonClick">
<winui:TabView.KeyboardAccelerators>
Expand Down
7 changes: 7 additions & 0 deletions src/BiliLite.UWP/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Collections;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
Expand Down Expand Up @@ -265,5 +266,11 @@ private void tabView_TabItemsChanged(TabView sender, IVectorChangedEventArgs arg
{

}

private void TabView_OnPreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
if(e.Key == VirtualKey.Space)
e.Handled = true;
}
}
}
18 changes: 18 additions & 0 deletions src/BiliLite.UWP/Models/Common/Danmaku/BiliDanmakuItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Windows.UI;
using NSDanmaku.Model;

namespace BiliLite.Models.Common.Danmaku
{
public class BiliDanmakuItem
{
public string Text { get; set; }

public double Size { get; set; }

public Color Color { get; set; }

public double Time { get; set; }

public DanmakuLocation Location { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/BiliLite.UWP/Models/Requests/Api/User/DynamicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public ApiModel SpaceHistory(string mid, string dynamic_id = "")
};
if (SettingService.Account.Logined)
{
api.parameter += $"&access_key={SettingService.Account.AccessKey}";
api.parameter += ApiHelper.MustParameter(AppKey, true);
api.parameter += ApiHelper.GetSign(api.parameter, AppKey);
}

return api;
Expand Down
11 changes: 8 additions & 3 deletions src/BiliLite.UWP/Services/FrostMasterDanmakuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Atelier39;
using AutoMapper;
using BiliLite.Models.Common.Danmaku;
using BiliLite.Services.Interfaces;
using BiliLite.ViewModels.Video;
using Microsoft.Graphics.Canvas.UI.Xaml;
Expand All @@ -13,11 +15,13 @@ namespace BiliLite.Services
{
public class FrostMasterDanmakuController : IDanmakuController
{
private readonly IMapper m_mapper;
private CanvasAnimatedControl m_danmakuCanvas;
private DanmakuFrostMaster m_danmakuMaster;

public FrostMasterDanmakuController()
public FrostMasterDanmakuController(IMapper mapper)
{
m_mapper = mapper;
DanmakuViewModel = new DanmakuViewModel()
{
ShowAreaControl = true,
Expand Down Expand Up @@ -136,9 +140,9 @@ public override void Load(IEnumerable danmakuList)
m_danmakuMaster.SetDanmakuList(realDanmakuList);
}

public override void Add(object danmakuItem, bool owner)
public override void Add(BiliDanmakuItem danmakuItem, bool owner)
{
var realDanmakuItem = danmakuItem as DanmakuItem;
var realDanmakuItem = m_mapper.Map<DanmakuItem>(danmakuItem);
m_danmakuMaster.AddRealtimeDanmaku(realDanmakuItem, false);
}

Expand All @@ -154,6 +158,7 @@ public override void Resume()

public override void UpdateTime(long position)
{
base.UpdateTime(position);
m_danmakuMaster.UpdateTime((uint)position * 1000);
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/BiliLite.UWP/Services/Interfaces/IDanmakuController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections;
using Windows.UI.Xaml.Controls;
using BiliLite.Models.Common.Danmaku;
using BiliLite.ViewModels.Video;

namespace BiliLite.Services.Interfaces
Expand All @@ -8,6 +9,8 @@ public abstract class IDanmakuController
{
public DanmakuViewModel DanmakuViewModel { get; protected set; }

public long Position { get; private set; }

public IDanmakuController()
{
DanmakuViewModel = new DanmakuViewModel();
Expand Down Expand Up @@ -142,7 +145,7 @@ public virtual void SetBolderStyle(int bolderStyle)
/// <summary>
/// 添加弹幕
/// </summary>
public abstract void Add(object danmakuItem, bool owner);
public abstract void Add(BiliDanmakuItem danmakuItem, bool owner);

/// <summary>
/// 暂停
Expand All @@ -165,6 +168,9 @@ public virtual void UpdateSize(double width, double height){}
/// 更新时间
/// </summary>
/// <param name="position"></param>
public virtual void UpdateTime(long position){}
public virtual void UpdateTime(long position)
{
Position = position;
}
}
}
Loading

0 comments on commit e43b25d

Please sign in to comment.