-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoad_External_AudioFile.cs
More file actions
38 lines (31 loc) · 1.01 KB
/
Load_External_AudioFile.cs
File metadata and controls
38 lines (31 loc) · 1.01 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
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class Load_External_AudioFile : MonoBehaviour
{
private string _Path = "";
[Header("Audio")]
[SerializeField] private List<AudioClip> _AudioFiles = new List<AudioClip>();
private string[] _Files_Audio_MP3;
private string pathPreFix = @"file://";
void Start()
{
_Files_Audio_MP3 = System.IO.Directory.GetFiles(_Path, "*.mp3");
StartCoroutine(LoadAudio());
}
private IEnumerator LoadAudio()
{
//Load mp3
foreach (string tstring in _Files_Audio_MP3)
{
string temppath = pathPreFix + tstring;
WWW www = new WWW(temppath);
yield return www;
AudioClip audioclip = www.GetAudioClip(false, false);
audioclip.LoadAudioData();
audioclip.name = Path.GetFileNameWithoutExtension(temppath);
_AudioFiles.Add(audioclip);
}
}
}