began working on audio system; added Naudio;
This commit is contained in:
26
RhythmBullet/Zer01HD/Audio/MusicController.cs
Normal file
26
RhythmBullet/Zer01HD/Audio/MusicController.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Audio
|
||||
{
|
||||
internal class MusicController
|
||||
{
|
||||
MusicList musicList;
|
||||
|
||||
public MusicController(MusicList musicList)
|
||||
{
|
||||
this.musicList = musicList;
|
||||
}
|
||||
|
||||
public void LoadMusic(string path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
93
RhythmBullet/Zer01HD/Audio/MusicList.cs
Normal file
93
RhythmBullet/Zer01HD/Audio/MusicList.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Audio
|
||||
{
|
||||
internal class MusicList
|
||||
{
|
||||
private volatile bool work;
|
||||
private List<string> list = new List<string>();
|
||||
public List<string> List
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!thread.IsAlive)
|
||||
{
|
||||
lock (list)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
private string path;
|
||||
private Thread thread;
|
||||
|
||||
public MusicList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (thread == null || !thread.IsAlive)
|
||||
{
|
||||
work = true;
|
||||
thread = new Thread(Search);
|
||||
thread.Name = "Music Search Thread";
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
work = false;
|
||||
}
|
||||
|
||||
private void Search()
|
||||
{
|
||||
lock (list)
|
||||
{
|
||||
list.AddRange(recursiveMusicSearch(path));
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> recursiveMusicSearch(string path)
|
||||
{
|
||||
List<string> musicFiles = new List<string>();
|
||||
string[] files = Directory.GetFiles(path);
|
||||
for (int i = 0; i < files.Length && work; i++)
|
||||
{
|
||||
if (Directory.Exists(files[i]))
|
||||
{
|
||||
musicFiles.AddRange(recursiveMusicSearch(files[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
SupportedFormats format;
|
||||
Enum.TryParse<SupportedFormats>(Path.GetExtension(files[i]).ToUpper(), out format);
|
||||
musicFiles.Add(files[i]);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
Console.WriteLine("MusicList", "Unsupported file format: " + Path.GetFileName(files[i]));
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return musicFiles;
|
||||
}
|
||||
}
|
||||
}
|
13
RhythmBullet/Zer01HD/Audio/SupportedFormats.cs
Normal file
13
RhythmBullet/Zer01HD/Audio/SupportedFormats.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Audio
|
||||
{
|
||||
public enum SupportedFormats
|
||||
{
|
||||
WAV, MP3
|
||||
}
|
||||
}
|
@@ -74,8 +74,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
||||
{
|
||||
if (queue.Count > 0 && (thread == null || !thread.IsAlive))
|
||||
{
|
||||
ThreadStart threadStart = new ThreadStart(LoadBatch);
|
||||
thread = new Thread(threadStart);
|
||||
thread = new Thread(LoadBatch);
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user