Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by georevilo · Apr 11, 2012 at 07:56 PM · androidmusiclibrary

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by WoozyBytes · Apr 13, 2015 at 05:03 PM

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.

Check the Directory Class , all you need is there.

Start with Directory.GetCurrentDirectory() 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 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 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() 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.

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

To Use Generic Lists 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.

alt text

filebrowser-example.png (32.8 kB)
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Colin2015 · May 10, 2015 at 06:08 PM 0
Share

Thanks to Woozybites for your answer and detailed code eventhough I'm a newbie your code sample looks like Javascript and I'm learning C# so I will study the Unity Docs for the Directory Class in C#.

avatar image WoozyBytes · May 12, 2015 at 03:08 PM 0
Share

Hi Colin2015 Im Happy to help.

The Directory class is not in the Unity Docs it's .NET and you can find the documentation in the $$anonymous$$SDN WebSite, there will be C# examples as well as JS.

Just follow the links on my answer ,change the .Net framework to 2.0 on the msdn site and look for the C# examples.

Hope it Helps, but if you get stuck , give me a buzz :)

avatar image QuDi · Aug 01, 2018 at 05:17 PM 0
Share

This code can browse only current directive. Is there is any option to find .mp3 on device(mobile)?

avatar image
0

Answer by captaincrunch80 · Apr 12, 2012 at 12:26 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image georevilo · Apr 12, 2012 at 10:08 PM 0
Share

What permission(s) would i need to set for that?

avatar image
0

Answer by captaincrunch80 · Apr 12, 2012 at 10:36 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i create an AudioClip from byte array? 0 Answers

How do I store music on the web and access it from an app? 2 Answers

How to embed multiple external plugins (ads, tracking) on android without libraries overlapping 0 Answers

Is there any way to make the headphone pause/unpause controls work when the Unity app is running, to pause/unpause background app(apple music/google music) music? Android app. 0 Answers

Mono.Cairo On Android 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges