2024-04-02 21:57:04 +08:00
|
|
|
|
using NAudio.Wave;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Resources;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using CDSAE3_Lian_Lian_Kan.Properties;
|
|
|
|
|
using NAudio.Wave.SampleProviders;
|
|
|
|
|
namespace CDSAE3_Lian_Lian_Kan.Sound
|
|
|
|
|
{
|
|
|
|
|
public class Song_Audio_processer:IDisposable
|
|
|
|
|
{
|
|
|
|
|
AudioPlayer? audioPlayer;
|
|
|
|
|
private List<string> audioFiles = new List<string>();
|
|
|
|
|
int next_song = 1;
|
|
|
|
|
private void OnPlaybackStopped(string s,object? obj)
|
|
|
|
|
{
|
|
|
|
|
set_song(get_next_song());
|
|
|
|
|
}
|
|
|
|
|
public void pause_song()=> audioPlayer?.pause_song();
|
|
|
|
|
public void resume_song()=> audioPlayer?.resume_song();
|
2024-04-18 08:38:59 +08:00
|
|
|
|
public string get_last_song()
|
|
|
|
|
{
|
|
|
|
|
next_song+=audioFiles.Count-2;
|
|
|
|
|
next_song %= audioFiles.Count;
|
|
|
|
|
string name = audioFiles[next_song];
|
|
|
|
|
next_song++;
|
|
|
|
|
return name;
|
|
|
|
|
}
|
2024-04-02 21:57:04 +08:00
|
|
|
|
public string get_next_song()
|
|
|
|
|
{
|
|
|
|
|
string name = audioFiles[next_song];
|
|
|
|
|
next_song++;
|
|
|
|
|
next_song %= audioFiles.Count;
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 调整音乐音量
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="val">音量大小 1-100</param>
|
|
|
|
|
public void volume_change(int val)=> audioPlayer?.volume_change(val);
|
|
|
|
|
public void set_albums(string s)
|
|
|
|
|
{
|
|
|
|
|
var result = Etcs.musics.Where(x => x.Key == s).ToList();
|
|
|
|
|
if (result.Count == 0)
|
|
|
|
|
throw new Exception("no such album");
|
|
|
|
|
audioFiles = result.First().Value;
|
2024-04-18 08:38:59 +08:00
|
|
|
|
Etcs.setting.SetAlbum(result.First().Key);
|
2024-04-02 21:57:04 +08:00
|
|
|
|
}
|
|
|
|
|
public void set_song(string s)
|
|
|
|
|
{
|
2024-04-18 08:38:59 +08:00
|
|
|
|
Etcs.setting.SetSongInfo(s);
|
2024-04-02 21:57:04 +08:00
|
|
|
|
audioPlayer?.Dispose();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
audioPlayer = new AudioPlayer(s, Etcs.Song_Volume, OnPlaybackStopped);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show($"failed to play {s}\n{e.Message}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
audioPlayer.resume_song();
|
|
|
|
|
}
|
2024-04-08 21:04:47 +08:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
audioPlayer?.Dispose();
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
2024-04-02 21:57:04 +08:00
|
|
|
|
~Song_Audio_processer() => Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|