I’m trying to read mp3 files out of the streamingassets folder.
Playing is working, but it seems like it’s not running in FMOD in the same way other audio is, since its not respecting the play/pause state of the editor, or the “mute audio” button.
I can implement this myself, by listening to the state changes, but I’m wondering if there’s a better way to plug it into FMOD runtime in the same way that PlayOneShot or CreateInstance.
Or if there’s another way to dynamically populate an event with an mp3 on the harddrive at runtime.
public class MusicManager : Singleton<MusicManager>
{
RESULT result;
Sound musicSound;
FMOD.System system;
Channel channel;
string[] files;
void Start ()
{
var path = Application.streamingAssetsPath + "/Music/";
files = Directory.GetFiles(path).Where(f => f.EndsWith(".mp3")).ToArray().Shuffle(); // returns absolute paths
SkipTrack();
}
void SkipTrack()
{
var song = files.GetRandom<string>();
var soundResult = RuntimeManager.CoreSystem.createSound(song, MODE._2D, out musicSound);
RuntimeManager.CoreSystem.getMasterChannelGroup(out ChannelGroup channelGroup);
RuntimeManager.CoreSystem.playSound(musicSound, channelGroup, false, out channel);
}
void Update()
{
channel.isPlaying(out bool isplaying);
if (!isplaying)
{
SkipTrack();
}
}
}