Skip to content

Commit

Permalink
Revert "#903 支持挂载外部ass字幕"
Browse files Browse the repository at this point in the history
This reverts commit 8247156.
  • Loading branch information
ywmoyue committed Nov 22, 2024
1 parent 77f92dd commit 98cd2a9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 89 deletions.
8 changes: 0 additions & 8 deletions src/BiliLite.UWP/Controls/PlayerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,6 @@
<Slider x:Name="SubtitleSettingBottom" Value="20" Minimum="4" Maximum="200" StepFrequency="4"></Slider>
<TextBlock Margin="0 8">繁体字幕转简体</TextBlock>
<ToggleSwitch x:Name="SubtitleSettingToSimplified" OnContent="开启" OffContent="关闭"></ToggleSwitch>
<TextBlock Margin="0 8">外置字幕</TextBlock>
<Button Click="BtnImportSubFile_OnClick">选择文件</Button>
<TextBlock Margin="0 8">外置字幕大小</TextBlock>
<Slider x:Name="OutsideSubtitleSettingSize" Value="3" Minimum="1" Maximum="15" StepFrequency="1"></Slider>
</StackPanel>
</ScrollViewer>
</PivotItem>
Expand All @@ -633,10 +629,6 @@
<Border x:Name="BorderSubtitle" Visibility="Collapsed" Opacity="{Binding ElementName=SubtitleSettingOpacity,Path=Value,Mode=OneWay}" Padding="3 4 8 4" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="0 0 0 24">

</Border>
<!--Ass弹幕-->
<Grid>
<canvas:CanvasAnimatedControl x:Name="SubtitleCanvas"/>
</Grid>
<!--弹幕-->
<Grid>
<danmaku:Danmaku x:Name="DanmuControl"/>
Expand Down
57 changes: 4 additions & 53 deletions src/BiliLite.UWP/Controls/PlayerControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BiliLite.Modules;
using BiliLite.Modules;
using NSDanmaku.Model;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -54,7 +54,6 @@ public sealed partial class PlayerControl : UserControl, IDisposable
private static readonly ILogger _logger = GlobalLogger.FromCurrentType();
private readonly bool m_useNsDanmaku = true;
private readonly IDanmakuController m_danmakuController;
private readonly FrostMasterDanmakuController m_assSubtitleController;
private readonly VideoDanmakuSettingsControlViewModel m_danmakuSettingsControlViewModel;
private readonly PlayControlViewModel m_viewModel;
private readonly PlayerToastService m_playerToastService;
Expand Down Expand Up @@ -174,12 +173,9 @@ public PlayerControl()
}
else
{
m_danmakuController = App.ServiceProvider.GetRequiredService<FrostMasterDanmakuController>();
m_danmakuController = App.ServiceProvider.GetRequiredService<FrostMasterDanmakuController>();
m_danmakuController.Init(DanmakuCanvas);
}

m_assSubtitleController = App.ServiceProvider.GetRequiredService<FrostMasterDanmakuController>();
m_assSubtitleController.Init(SubtitleCanvas);
}

private void Timer_focus_Tick(object sender, object e)
Expand Down Expand Up @@ -233,7 +229,6 @@ private void PlayerControl_Unloaded(object sender, RoutedEventArgs e)
private async void PlayerControl_Loaded(object sender, RoutedEventArgs e)
{
m_danmakuController.Clear();
m_assSubtitleController.Clear();
BtnFoucs.Focus(FocusState.Programmatic);
_systemMediaTransportControls = SystemMediaTransportControls.GetForCurrentView();
_systemMediaTransportControls.IsPlayEnabled = true;
Expand Down Expand Up @@ -501,7 +496,7 @@ private void LoadPlayerSetting()
{
//音量
Player.Volume = SettingService.GetValue<double>(SettingConstants.Player.PLAYER_VOLUME, SettingConstants.Player.DEFAULT_PLAYER_VOLUME);

var lockPlayerVolume = SettingService.GetValue(SettingConstants.Player.LOCK_PLAYER_VOLUME, SettingConstants.Player.DEFAULT_LOCK_PLAYER_VOLUME);
if (!lockPlayerVolume)
{
Expand Down Expand Up @@ -604,14 +599,6 @@ private void LoadSutitleSetting()
SettingService.SetValue<double>(SettingConstants.Player.SUBTITLE_SIZE, SubtitleSettingSize.Value);
UpdateSubtitle();
});
//外置字幕大小
OutsideSubtitleSettingSize.Value = 3;//SettingService.GetValue<double>(SettingConstants.Player.SUBTITLE_SIZE, 40);
OutsideSubtitleSettingSize.ValueChanged += new RangeBaseValueChangedEventHandler((e, args) =>
{
if (miniWin) return;
//SettingService.SetValue<double>(SettingConstants.Player.SUBTITLE_SIZE, SubtitleSettingSize.Value);
m_assSubtitleController.SetFontZoom((int)OutsideSubtitleSettingSize.Value);
});
//字幕描边颜色
SubtitleSettingBorderColor.SelectedIndex = SettingService.GetValue<int>(SettingConstants.Player.SUBTITLE_BORDER_COLOR, 0);
SubtitleSettingBorderColor.SelectionChanged += new SelectionChangedEventHandler((e, args) =>
Expand Down Expand Up @@ -840,7 +827,6 @@ private async void DanmuTimer_Tick(object sender, object e)
return;
}
m_danmakuController.UpdateTime(position);
m_assSubtitleController.UpdateTime(position);

var needDistinct = DanmuSettingMerge.IsOn;
var level = DanmuSettingShieldLevel.Value;
Expand All @@ -854,7 +840,6 @@ private async void DanmuTimer_Tick(object sender, object e)
if (Player.PlayState == PlayState.Pause)
{
m_danmakuController.Pause();
m_assSubtitleController.Pause();
}
}

Expand Down Expand Up @@ -1024,15 +1009,6 @@ private async void SetSubTitle(string url)
{
try
{
if (url.EndsWith(".ass"))
{
var content = await playerHelper.GetAssFileContent(url);
m_assSubtitleController.SetFontZoom(1);
m_assSubtitleController.SetAssSubtitle(content);

return;
}

subtitles = await playerHelper.GetSubtitle(url);
if (subtitles != null)
{
Expand All @@ -1050,9 +1026,8 @@ private async void SetSubTitle(string url)
subtitleTimer.Start();
}
}
catch (Exception ex)
catch (Exception)
{
_logger.Error(ex.Message, ex);
Notify.ShowMessageToast("加载字幕失败了");
}

Expand Down Expand Up @@ -1166,7 +1141,6 @@ private async Task<Grid> GenerateSubtitleItem(string text)
/// </summary>
private void ClearSubTitle()
{
m_assSubtitleController.Clear();
if (subtitles != null)
{
if (subtitleTimer != null)
Expand Down Expand Up @@ -1701,7 +1675,6 @@ public void FullScreen(bool fullScreen)
FullScreenEvent?.Invoke(this, fullScreen);
MessageCenter.SetFullscreen(fullScreen);
m_danmakuController.SetFullscreen(fullScreen);
m_assSubtitleController.SetFullscreen(fullScreen);
if (fullScreen)
{
BottomBtnExitFull.Visibility = Visibility.Visible;
Expand Down Expand Up @@ -2258,7 +2231,6 @@ private void BottomBtnPlay_Click(object sender, RoutedEventArgs e)
{
Player.Play();
m_danmakuController.Resume();
m_assSubtitleController.Resume();
}
}

Expand Down Expand Up @@ -2320,7 +2292,6 @@ private void Player_PlayStateChanged(object sender, PlayState e)
BottomBtnPlay.Visibility = Visibility.Collapsed;
BottomBtnPause.Visibility = Visibility.Visible;
m_danmakuController.Resume();
m_assSubtitleController.Resume();
break;
case PlayState.Pause:
KeepScreenOn(false);
Expand All @@ -2333,7 +2304,6 @@ private void Player_PlayStateChanged(object sender, PlayState e)
BottomBtnPlay.Visibility = Visibility.Visible;
BottomBtnPause.Visibility = Visibility.Collapsed;
m_danmakuController.Pause();
m_assSubtitleController.Pause();
break;
case PlayState.End:
KeepScreenOn(false);
Expand Down Expand Up @@ -2367,7 +2337,6 @@ private void Player_PlayBufferStart(object sender, EventArgs e)
TxtBuffering.Text = "正在缓冲...";
BufferingProgress = 0;
m_danmakuController.Pause();
m_assSubtitleController.Pause();
}

private void Player_PlayBuffering(object sender, double e)
Expand All @@ -2383,7 +2352,6 @@ private void Player_PlayBufferEnd(object sender, EventArgs e)
GridBuffering.Visibility = Visibility.Collapsed;
Buffering = false;
m_danmakuController.Resume();
m_assSubtitleController.Resume();
}

private async void Player_PlayMediaEnded(object sender, EventArgs e)
Expand All @@ -2396,7 +2364,6 @@ private async void Player_PlayMediaEnded(object sender, EventArgs e)
return;
}
m_danmakuController.Pause();
m_assSubtitleController.Pause();
InteractionChoices.Visibility = Visibility.Visible;
return;
}
Expand Down Expand Up @@ -2450,7 +2417,6 @@ private async void Player_PlayMediaEnded(object sender, EventArgs e)
{
ClearSubTitle();
m_danmakuController.Clear();
m_assSubtitleController.Clear();
Player.Play();
return;
}
Expand All @@ -2467,7 +2433,6 @@ private async void Player_PlayMediaEnded(object sender, EventArgs e)
{
ClearSubTitle();
m_danmakuController.Clear();
m_assSubtitleController.Clear();
Player.Play();
return;
}
Expand Down Expand Up @@ -3014,19 +2979,5 @@ private void ViewPoint_OnTapped(object sender, TappedRoutedEventArgs e)
if (!(element.DataContext is PlayerInfoViewPoint viewPoint)) return;
SetPosition(viewPoint.From);
}

private async void BtnImportSubFile_OnClick(object sender, RoutedEventArgs e)
{
var path = await playerHelper.GetOutsideSubtitle();

if (path == null) return;

(BottomBtnSelctSubtitle.Flyout as MenuFlyout).Items.Add(new ToggleMenuFlyoutItem()
{
Tag = path,
Name = "外置字幕"
});
SetSubTitle(path);
}
}
}
22 changes: 0 additions & 22 deletions src/BiliLite.UWP/Modules/Player/PlayerVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using BiliLite.Services;
using BiliLite.Models.Common.Video;
using BiliLite.Models.Common.Video.PlayUrlInfos;
using Windows.Storage.Pickers;

namespace BiliLite.Modules
{
Expand Down Expand Up @@ -273,27 +272,6 @@ public async Task<string> GetOnline(string aid, string cid)
}
return "";
}

public async Task<string> GetOutsideSubtitle()
{
var filePicker = new FileOpenPicker();
filePicker.FileTypeFilter.Add(".ass");
var file = await filePicker.PickSingleFileAsync();
if (file == null) return null;

var fileContent = await FileIO.ReadTextAsync(file);
var tempFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
var tempFile = await tempFolder.CreateFileAsync($"{Guid.NewGuid().ToString()}.ass", Windows.Storage.CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(tempFile, fileContent);
return tempFile.Path;
}

public async Task<string> GetAssFileContent(string path)
{
var jsonFile = await StorageFile.GetFileFromPathAsync(path);
var content = await FileIO.ReadTextAsync(jsonFile);
return content;
}
}


Expand Down
6 changes: 0 additions & 6 deletions src/BiliLite.UWP/Services/FrostMasterDanmakuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,5 @@ public override void UpdateTime(long position)
base.UpdateTime(position);
m_danmakuMaster.UpdateTime((uint)position * 1000);
}

public void SetAssSubtitle(string assContent)
{
var subItems = AssParser.GetDanmakuList(assContent);
m_danmakuMaster.SetSubtitleList(subItems);
}
}
}

0 comments on commit 98cd2a9

Please sign in to comment.