又写了一堆屎山
This commit is contained in:
@@ -30,8 +30,12 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
|
||||
sound = new MemoryStream(source_obj);
|
||||
ms = new MemoryStream(StreamToBytes(sound));
|
||||
ws = new Mp3FileReader(ms);
|
||||
|
||||
|
||||
blockAlignReductionStream = new BlockAlignReductionStream(ws);
|
||||
|
||||
wave16ToFloatProvider = new Wave16ToFloatProvider(blockAlignReductionStream);
|
||||
|
||||
wave16ToFloatProvider.Volume = volume / 100f;
|
||||
waveOutEvent = new WaveOutEvent();
|
||||
waveOutEvent.Init(wave16ToFloatProvider);
|
||||
@@ -73,7 +77,11 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
|
||||
waveOutEvent.Stop();
|
||||
sound.Dispose();
|
||||
ms.Dispose();
|
||||
ws.Dispose();
|
||||
try
|
||||
{
|
||||
ws.Dispose();
|
||||
}catch(Exception)
|
||||
{ }
|
||||
blockAlignReductionStream.Dispose();
|
||||
waveOutEvent.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
@@ -14,31 +14,31 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
|
||||
string last_break_soundScape = "";
|
||||
Random random = new Random();
|
||||
internal void set_SoundScape_version(Etcs.break_music version) => soundScape_version = version;
|
||||
internal void play_random_break_soundScape()
|
||||
internal void play_random_break_soundScape(int volume = -1, Action<string, AudioPlayer>? finished = null)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
void finished(string s,AudioPlayer audioPlayer)
|
||||
{
|
||||
audioPlayer.Dispose();
|
||||
}
|
||||
AudioPlayer audioPlayer = new AudioPlayer(get_random_break_soundScape(), Etcs.Info_Volume,finished);
|
||||
if (volume == -1)
|
||||
volume = Etcs.Info_Volume;
|
||||
if (finished == null)
|
||||
finished = (s, player) => player.Dispose();
|
||||
AudioPlayer audioPlayer = new AudioPlayer(get_random_break_soundScape(), volume, finished);
|
||||
audioPlayer.resume_song();
|
||||
//object obj = Settings.res_Manager.GetObject(get_random_break_soundScape(), Settings.res_Culture)!;
|
||||
//var infoOutputDevice = new WaveOutEvent();
|
||||
//using (var sound = new MemoryStream((byte[])obj))
|
||||
//using (var ms = new MemoryStream(StreamToBytes(sound)))
|
||||
//using (var ws = new Mp3FileReader(ms))
|
||||
//using (var blockAlignReductionStream = new BlockAlignReductionStream(ws))
|
||||
//{
|
||||
// var wave16ToFloatProvider = new Wave16ToFloatProvider(blockAlignReductionStream);
|
||||
// wave16ToFloatProvider.Volume = soundScape_volume / 100f;
|
||||
// infoOutputDevice.Init(wave16ToFloatProvider);
|
||||
// infoOutputDevice.PlaybackStopped += InfoOutputDevice_PlaybackStopped;
|
||||
// infoOutputDevice.Play();
|
||||
//}
|
||||
});
|
||||
}
|
||||
internal void playMusicClip(string s,int volume = -1,Action<string ,AudioPlayer>?finished = null)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (volume == -1)
|
||||
volume = Etcs.Info_Volume;
|
||||
if (finished == null)
|
||||
finished = (s, player) => player.Dispose();
|
||||
AudioPlayer audioPlayer = new AudioPlayer(s, volume, finished);
|
||||
audioPlayer.resume_song();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private string get_random_break_soundScape()
|
||||
{
|
||||
|
||||
@@ -10,13 +10,22 @@ using CDSAE3_Lian_Lian_Kan.Properties;
|
||||
using NAudio.Wave.SampleProviders;
|
||||
namespace CDSAE3_Lian_Lian_Kan.Sound
|
||||
{
|
||||
public class SongFinishedEventArgs : EventArgs
|
||||
{
|
||||
public string SongName { get; set; }
|
||||
public SongFinishedEventArgs(string songName) => SongName = songName;
|
||||
}
|
||||
|
||||
public delegate void SongFinishedEventHandler(Song_Audio_processer s, SongFinishedEventArgs e);
|
||||
public class Song_Audio_processer:IDisposable
|
||||
{
|
||||
AudioPlayer? audioPlayer;
|
||||
private List<string> audioFiles = new List<string>();
|
||||
public event SongFinishedEventHandler? SongFinished;
|
||||
int next_song = 1;
|
||||
private void OnPlaybackStopped(string s,object? obj)
|
||||
{
|
||||
SongFinished?.Invoke(this, new SongFinishedEventArgs(s));
|
||||
set_song(get_next_song());
|
||||
}
|
||||
public void pause_song()=> audioPlayer?.pause_song();
|
||||
@@ -44,19 +53,20 @@ namespace CDSAE3_Lian_Lian_Kan.Sound
|
||||
public void volume_change(int val)=> audioPlayer?.volume_change(val);
|
||||
public void set_albums(string s)
|
||||
{
|
||||
next_song = 0;
|
||||
var result = Etcs.musics.Where(x => x.Key == s).ToList();
|
||||
if (result.Count == 0)
|
||||
throw new Exception("no such album");
|
||||
audioFiles = result.First().Value;
|
||||
Etcs.setting.SetAlbum(result.First().Key);
|
||||
}
|
||||
public void set_song(string s)
|
||||
internal void set_song(string s,int volume = -1,Action<string,AudioPlayer>? finished = null)
|
||||
{
|
||||
Etcs.setting.SetSongInfo(s);
|
||||
audioPlayer?.Dispose();
|
||||
try
|
||||
{
|
||||
audioPlayer = new AudioPlayer(s, Etcs.Song_Volume, OnPlaybackStopped);
|
||||
audioPlayer = new AudioPlayer(s, volume == -1 ? Etcs.Song_Volume : volume, finished ?? OnPlaybackStopped);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user