Allow the player to use a custom music library?

I found a GUI file browser that would do what I need if I could figure out how to implement it, but it was awfully complicated to do something that should be fairly simple. Windows already has a file browser, can’t I use that? I’ve seen it done in games before. Just press browse, navigate through windows to the folder you want, select it, and then the game will cycle through the songs in the folder…Or perhaps there’s a way I can have a folder that will be present in the install folder of my stand alone that the game will access, and players can add music to that folder? While searching for an answer, I came across something that seemed promising. “Add Using System.IO to the top of your script.” I understand what that means, but I don’t know what it allows me to do or how.

Ideally, once the user selected his music folder, the first one in the folder would be played through an audio source in the scene, and when it was over, it would access the next file…

System.IO is used for actions with folders like System.IO.File.ReadAllBytes

In your case I would rather dig in StreamingAssets Unity - Manual: Streaming Assets

StreamingAssets is content that is locally placed in a folder close to the executable. But you’ll have to import the files, and do some stuff by yourself by code.


using System.IO;

will let you use it’s class’ methods, which is what you need. Just after a quick search I found out that if you use System.IO, there’s a method called

Directory.GetFiles(string,string) - where 1st string is the path, and the next one is the search pattern.

If I were you, I’d make a list consisting of strings, and then pass all these files (names) to it, then implement it in my custom music player system. I won’t write the whole script for you, but you should be starting with something like this:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;

public class SearchMusic : MonoBehaviour {
    private List<string> Songs = new List<string>();

	// Use this for initialization
	void Start () {
        Songs = Directory.GetFiles("path/to/my/music", ".mp3");

I didn’t test it, but it should give you a list consisting of the names of the songs.