Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #20 from Bililive/dev
Browse files Browse the repository at this point in the history
Release 3.0.2
  • Loading branch information
Genteure committed Dec 1, 2018
2 parents fdd088b + 4e6def2 commit 7e09782
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 64 deletions.
34 changes: 17 additions & 17 deletions DGJv3/DGJWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.deeporange.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.DeepOrange.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Expand Down Expand Up @@ -68,9 +68,9 @@
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn Header="状态" DisplayMemberBinding="{Binding Status,Converter={StaticResource SongStatusStringConverter}}"/>
<GridViewColumn Header="歌名" DisplayMemberBinding="{Binding SongName}"/>
<GridViewColumn Header="点歌人" DisplayMemberBinding="{Binding UserName}"/>
<GridViewColumn Header="歌手" DisplayMemberBinding="{Binding SingersText}"/>
<GridViewColumn Header="歌名" DisplayMemberBinding="{Binding SongName, Mode=OneTime}"/>
<GridViewColumn Header="点歌人" DisplayMemberBinding="{Binding UserName, Mode=OneTime}"/>
<GridViewColumn Header="歌手" DisplayMemberBinding="{Binding SingersText, Mode=OneTime}"/>
</GridView>
</ListView.View>
</ListView>
Expand Down Expand Up @@ -115,8 +115,8 @@
</ListView.ContextMenu>
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn Header="歌名" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="歌手" DisplayMemberBinding="{Binding SingersText}"/>
<GridViewColumn Header="歌名" DisplayMemberBinding="{Binding Name, Mode=OneTime}"/>
<GridViewColumn Header="歌手" DisplayMemberBinding="{Binding SingersText, Mode=OneTime}"/>
</GridView>
</ListView.View>
</ListView>
Expand Down Expand Up @@ -242,18 +242,18 @@

<TextBlock Grid.Column="1" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"
Visibility="{Binding DownloadPercentage,Converter={StaticResource NotEqualsVisibilityConverter},ConverterParameter={StaticResource Zero}}">
缓存歌曲中
<LineBreak/>
<TextBlock Text="{Binding DownloadSpeed,StringFormat=0.## KiB/s}"/>
</TextBlock>
缓存歌曲中
<LineBreak/>
<TextBlock Text="{Binding DownloadSpeed,StringFormat=0.## KiB/s}"/>
</TextBlock>
<materialDesign:Card Grid.Column="2" Margin="10,0" UniformCornerRadius="14" Padding="4" VerticalAlignment="Center" HorizontalAlignment="Center"
Visibility="{Binding DownloadPercentage,Converter={StaticResource NotEqualsVisibilityConverter},ConverterParameter={StaticResource Zero}}">
<ProgressBar Style="{StaticResource MaterialDesignCircularProgressBar}" Value="50" IsIndeterminate="True"/>
</materialDesign:Card>

<TextBlock Grid.Column="1" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"
Visibility="{Binding IsModuleDownloading,Converter={StaticResource EqualsVisibilityConverter},ConverterParameter={StaticResource True}}">
缓存歌曲中
缓存歌曲中
</TextBlock>
<materialDesign:Card Grid.Column="2" Margin="10,0" UniformCornerRadius="14" Padding="4" VerticalAlignment="Center" HorizontalAlignment="Center"
Visibility="{Binding IsModuleDownloading,Converter={StaticResource EqualsVisibilityConverter},ConverterParameter={StaticResource True}}">
Expand All @@ -272,18 +272,18 @@
<Button Style="{StaticResource MaterialDesignFloatingActionMiniButton}" Command="{Binding PlayPauseCommand}">
<Grid>
<materialDesign:PackIcon Width="24" Height="24" Kind="Play"
Visibility="{Binding IsPlaying,Converter={StaticResource EqualsVisibilityConverter},ConverterParameter={StaticResource False}}"/>
Visibility="{Binding IsPlaying,Mode=OneWay,Converter={StaticResource EqualsVisibilityConverter},ConverterParameter={StaticResource False}}"/>
<materialDesign:PackIcon Width="24" Height="24" Kind="Pause"
Visibility="{Binding IsPlaying,Converter={StaticResource EqualsVisibilityConverter},ConverterParameter={StaticResource True}}"/>
Visibility="{Binding IsPlaying,Mode=OneWay,Converter={StaticResource EqualsVisibilityConverter},ConverterParameter={StaticResource True}}"/>
</Grid>
</Button>
<Button Margin="8 0" Style="{StaticResource MaterialDesignFloatingActionMiniButton}" Command="{Binding NextCommand}">
<materialDesign:PackIcon Width="24" Height="24" Kind="SkipNext"/>
</Button>
<TextBlock FontSize="24" TextAlignment="Center" VerticalAlignment="Center">
<TextBlock Width="80" Text="{Binding CurrentTime,StringFormat=mm\\:ss}" TextAlignment="Right"/>
<TextBlock Width="80" Text="{Binding CurrentTimeString, Mode=OneWay}" TextAlignment="Right"/>
/
<TextBlock Width="80" Text="{Binding TotalTime,StringFormat=mm\\:ss}" TextAlignment="Left"/>
<TextBlock Width="80" Text="{Binding TotalTimeString, Mode=OneWay}" TextAlignment="Left"/>
</TextBlock>
<materialDesign:PackIcon x:Name="PackIconVolumeHigh" Width="24" Height="24" Kind="VolumeHigh" VerticalAlignment="Center" Margin="15,10,0,0"/>
<Slider Style="{StaticResource MaterialDesignDiscreteSlider}" Value="{Binding Volume,Converter={StaticResource PlayerVolumeConverter}}"
Expand Down Expand Up @@ -433,7 +433,7 @@
TextAlignment="Left" VerticalAlignment="Stretch" Grid.Row="1" Grid.Column="0" ContextMenu="{x:Null}"
Style="{StaticResource MaterialDesignTextAreaTextBox}" materialDesign:HintAssist.Hint="模板 不会改请保持默认"
TextWrapping="Wrap" AcceptsReturn="True" AcceptsTab="True" SpellCheck.IsEnabled="False"/>
<TextBox Text="{Binding Writer.Result}" IsEnabled="False" TextAlignment="Left"
<TextBox Text="{Binding Writer.Result,Mode=OneWay}" IsEnabled="False" TextAlignment="Left"
VerticalAlignment="Stretch" Grid.Row="1" Grid.Column="1"
Style="{StaticResource MaterialDesignTextAreaTextBox}" materialDesign:HintAssist.Hint="输出预览"
TextWrapping="Wrap" AcceptsReturn="True" AcceptsTab="True" SpellCheck.IsEnabled="False"/>
Expand Down
58 changes: 40 additions & 18 deletions DGJv3/DGJWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,58 @@ public void Log(string text)
{
PluginMain.Log(text);

Task.Run(() =>
if (IsLogRedirectDanmaku)
{
try
Task.Run(() =>
{
if (!PluginMain.RoomId.HasValue) { return; }
string finalText = text.Substring(0, Math.Min(text.Length, LogDanmakuLengthLimit));
string result = LoginCenterAPIWarpper.Send(PluginMain.RoomId.Value, finalText);
if (result == null)
try
{
PluginMain.Log("发送弹幕时网络错误");
if (!PluginMain.RoomId.HasValue) { return; }
string finalText = text.Substring(0, Math.Min(text.Length, LogDanmakuLengthLimit));
string result = LoginCenterAPIWarpper.Send(PluginMain.RoomId.Value, finalText);
if (result == null)
{
PluginMain.Log("发送弹幕时网络错误");
}
else
{
var j = JObject.Parse(result);
if (j["msg"].ToString() != string.Empty)
{
PluginMain.Log("发送弹幕时服务器返回:" + j["msg"].ToString());
}
}
}
else
catch (Exception ex)
{
var j = JObject.Parse(result);
if (j["msg"].ToString() != string.Empty)
if (ex.GetType().FullName.Equals("LoginCenter.API.PluginNotAuthorizedException"))
{
IsLogRedirectDanmaku = false;
}
else
{
PluginMain.Log("发送弹幕时服务器返回:" + j["msg"].ToString());
PluginMain.Log("弹幕发送错误 " + ex.ToString());
}
}
}
catch (Exception ex)
{
PluginMain.Log("弹幕发送错误 " + ex.ToString());
}
});
});
}
}

public DGJWindow(DGJMain dGJMain)
{
void addResource(string uri)
{
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
Source = new Uri(uri)
});
}
addResource("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml");
addResource("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml");
addResource("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.DeepOrange.xaml");
addResource("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ProgressBar.xaml");

DataContext = this;
PluginMain = dGJMain;
Songs = new ObservableCollection<SongItem>();
Expand Down
2 changes: 1 addition & 1 deletion DGJv3/DanmuHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ internal void ProcessDanmu(DanmakuModel danmakuModel)
{
dispatcher.Invoke(() =>
{
SongItem songItem = Songs.Last(x => x.UserName == danmakuModel.UserName && x.Status != SongStatus.Playing);
SongItem songItem = Songs.LastOrDefault(x => x.UserName == danmakuModel.UserName && x.Status != SongStatus.Playing);
if (songItem != null)
{
songItem.Remove(Songs, Downloader, Player);
Expand Down
40 changes: 25 additions & 15 deletions DGJv3/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace DGJv3
{
class Downloader : INotifyPropertyChanged
internal class Downloader : INotifyPropertyChanged
{
private Dispatcher dispatcher;

Expand Down Expand Up @@ -85,7 +85,9 @@ private void NewSongTimer_Tick(object sender, EventArgs e)
if (currentSong == null)
{
if (IsModuleDownloading)
{
IsModuleDownloading = false;
}

foreach (var songItem in Songs)
{
Expand Down Expand Up @@ -135,27 +137,31 @@ private void Download()
{
try
{
webClient = new WebClient();
string url = currentSong.GetDownloadUrl();
if (url != null)
{
webClient = new WebClient();

webClient.DownloadProgressChanged += OnDownloadProgressChanged;
webClient.DownloadFileCompleted += OnDownloadFileCompleted;
webClient.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.450 Safari/537.35");
webClient.DownloadProgressChanged += OnDownloadProgressChanged;
webClient.DownloadFileCompleted += OnDownloadFileCompleted;
webClient.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.450 Safari/537.35");

webClient.DownloadFileAsync(new Uri(currentSong.GetDownloadUrl()), currentSong.FilePath);
webClient.DownloadFileAsync(new Uri(url), currentSong.FilePath);
}
else
{
dispatcher.Invoke(() => Songs.Remove(currentSong));
currentSong = null;
}
}
catch (Exception ex)
{
try
{
webClient.Dispose();
webClient = null;
}
catch (Exception)
{ }
webClient?.Dispose();
webClient = null;

dispatcher.Invoke(() => Songs.Remove(currentSong));
currentSong = null;
Log("启动下载错误 " + currentSong.SongName, ex);
currentSong = null;
}
}
}
Expand Down Expand Up @@ -222,7 +228,11 @@ private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEve
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
if (EqualityComparer<T>.Default.Equals(field, value))
{
return false;
}

field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
return true;
Expand Down
29 changes: 20 additions & 9 deletions DGJv3/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public TimeSpan CurrentTime
}
}

public string CurrentTimeString { get => Math.Floor(CurrentTime.TotalMinutes) + ":" + CurrentTime.Seconds; }

/// <summary>
/// 当前播放时间秒数
/// </summary>
Expand All @@ -90,6 +92,8 @@ public double CurrentTimeDouble
/// </summary>
public TimeSpan TotalTime { get => mp3FileReader == null ? TimeSpan.Zero : mp3FileReader.TotalTime; }

public string TotalTimeString { get => Math.Floor(TotalTime.TotalMinutes) + ":" + TotalTime.Seconds; }

/// <summary>
/// 当前是否正在播放歌曲
/// </summary>
Expand Down Expand Up @@ -204,6 +208,11 @@ private void This_PropertyChanged(object sender, PropertyChangedEventArgs e)
else if (e.PropertyName == nameof(CurrentTime))
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentTimeDouble)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentTimeString)));
}
else if (e.PropertyName == nameof(TotalTime))
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TotalTimeString)));
}
}

Expand Down Expand Up @@ -310,17 +319,19 @@ private void UnloadSong()
{
try
{
wavePlayer.Stop();
wavePlayer.Dispose();
mp3FileReader.Close();
mp3FileReader.Dispose();
wavePlayer = null;
sampleChannel = null;
mp3FileReader = null;
wavePlayer?.Dispose();
}
catch (Exception)
catch (Exception) { }

try
{
mp3FileReader?.Dispose();
}
catch (Exception) { }

wavePlayer = null;
sampleChannel = null;
mp3FileReader = null;

try
{
Expand Down Expand Up @@ -413,7 +424,7 @@ public void Next()
{
if (wavePlayer != null)
{
UnloadSong();
wavePlayer.Stop();
}
}

Expand Down
5 changes: 4 additions & 1 deletion DGJv3/SongInfo.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Newtonsoft.Json;
using System.ComponentModel;

namespace DGJv3
{
public class SongInfo
public class SongInfo : INotifyPropertyChanged
{
[JsonIgnore]
public SearchModule Module;

public event PropertyChangedEventHandler PropertyChanged;

[JsonProperty("smid")]
public string ModuleId { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions DGJv3/Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
播放列表 = localsongs,
空闲歌单 = localplaylist,
歌曲数量 = Songs.Count,
当前播放时间 = Player.CurrentTime.ToString("mm\\:ss"),
当前总时间 = Player.TotalTime.ToString("mm\\:ss"),
当前播放时间 = Player.CurrentTimeString,
当前总时间 = Player.TotalTimeString,
总共最大点歌数量 = DanmuHandler.MaxTotalSongNum,
单人最大点歌数量 = DanmuHandler.MaxPersonSongNum,
}) ?? string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1
3.0.2

0 comments on commit 7e09782

Please sign in to comment.