Android Music selection

I am in the process of making an application for android using unity and I would like to be able to get a user selected song from their own library of music on their android into my unity application. I was wondering what would be the best way to go about this.

Is there an android specific script call that can bring up a song picker or return to me a list of the music stored on the device?

If there isn’t, is there a simple way to bring up a file viewer like finder or explorer so that the user can look for the songs themselves and I can just use the path to load the song.

Or do I have to write a small song picking application in java that gets called from Unity?

Or have I overlooked a really simple way to do this?

Hi there i know this is an old thread and you probably already found a solution for your problem but just in case someone is still interested, the way i approached this was to create my own file browser using [.Net System.IO][1].

Check the [Directory Class][2] , all you need is there.

Start with [Directory.GetCurrentDirectory()][3] to get the **current Directory** path, on **Android** this will give you "/" on **Windows when running in Editor** will give you the path of where your project is.

Store the current Path in a **string** variable like this `var _curPath : String = Directory.GetCurrentDirectory()` then feed that path variable into [Directory.GetDirectories][4] which will return you a list of the paths of all the folders (if any otherwise the length of the list will be **zero** ) in the path you just gave it. Store those paths in an **string** array i recommend using [Generic Lists][5] instead of unity's built in arrays simply because its easier to manage.

A simplistic example of how to get the folders in the current directory would look something like this

import System.IO ;
import System.Collections.Generic ;
private var _curPath :String ;
private var _curDirectoryFolderPaths : List.<String> = new List.<String>() ;

function GetCurDirFolders () {
    _curPath = Directory.GetCurrentDirectory();
    for ( folderPath in Directory.GetDirectories( _curPath )) {
        try {
            _curDirectoryFolderPaths.Add( folderPath );

        }catch ( error ) {
            Debug.Log( error);
        }
    }
    Debug.Log("Found "+_curDirectoryFolderPaths.Count.ToString() + " Folder(s) in this Directory " );
} 

Do the same for [Directory.GetFiles()][6] which will return the paths of the files in that Directory, you can filter files if you need and search only specific file types

All this can be done in UNITY FREE.

Once you got the path for lets say a mp3 audio track for example you can load using Unity's [WWW Class][7].

To access directories and files this way you need to put this on top of you script `import System.IO ;`

To Use [Generic Lists][8] put this at the top of your Script `import System.Collections.Generic ;`

To create a list do this

var _curDirFilePaths : List.<String> = new List.<String>(); 

Hope this Helps but if you're stuck let me know.

Here's a rough prototype of my DIY File Browser for an Android App im creating.

![44457-filebrowser-example.png|480x321](upload://gjPfmOpR4mCTr3jpm9SWCW3WvXO.png)

AFAIK for this kind of stuff you need the PRO version of unity. A custom Manifest file will be neccessary (you need full Memory access on the phone) and a java native plugin for unity to handle the file loading and stuff via Android Framework functions.

If you have Pro this is the way to go.

Hi again,

ok I have taken a deeper look, it can be managed by Intend instead of scanning the USB storage yourself.

You can handle it with Intend ACTION GET CONTENT. Take a look here http://stackoverflow.com/questions/9577576/how-to-call-in-built-android-music-menu-in-my-development (The second answer looks good)

Check out this too http://unity3d.com/support/documentation/Manual/Android-Launch%20an%20Android%20Application%20from%20a%20Unity%20Application.html and set up your unity project in Eclipse.

Maybe you can do this without pro and I was wrong (I thought native java integration requires Pro, but if the AndroidJavaObject works it should be possible.). Give it a try!

Best of luck! Maybe you can report back if it works. Would be nice to know.