-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioLoader.cs
More file actions
74 lines (70 loc) · 2.54 KB
/
AudioLoader.cs
File metadata and controls
74 lines (70 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using System.IO;
namespace BookmarksModNS
{
public class PlayList
{
public List<AudioClip> ClipList = new();
public List<string> NameList = new();
public int Start(string path)
{
if (Directory.Exists(path))
{
DirectoryInfo info = new DirectoryInfo(path);
List<string> filelist = new List<string>();
foreach (FileInfo item in info.GetFiles("*.wav"))
{
filelist.Add(item.Name);
}
path = path.Replace("\\","/");
if (!path.EndsWith("/")) path += "/";
ClipList = LoadAudioFile(path, filelist);
NameList = filelist;
}
else
{
BookmarksMod.Log($"PlayList.Start: Invalid path: {path}");
}
return ClipList.Count;
}
List<AudioClip> LoadAudioFile(string path, List<string> filelist)
{
BookmarksMod.Log($"LoadAudioFiles count {filelist.Count}");
List<AudioClip> clips = new List<AudioClip>();
foreach (string file in filelist)
{
string filepath = path + string.Format("{0}", file);
BookmarksMod.Log("Loading " + filepath);
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(filepath, AudioType.WAV))
{
var result = www.SendWebRequest();
while (!result.isDone) { Task.Delay(50); }
if (www.result == UnityWebRequest.Result.ConnectionError)
{
BookmarksMod.Log(www.error);
filelist.Remove(file);
}
else
{
try
{
AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
clip.name = file;
clips.Add(clip);
}
catch (Exception e)
{
filelist.Remove(file);
BookmarksMod.Log($"Exception {e.Message} while load {file}");
BookmarksMod.Log(e.StackTrace);
}
}
}
}
return clips;
}
}
}