Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Cmoche · Apr 29, 2016 at 07:34 PM · androidunity 5mobile

Trouble getting to DIRECTORY_MUSIC in Android

Greetings all, I'm looking for the right method to access an Android devices Music folder (for read access only)
I've read numerous posts on how this can be done through Java, but as a novice coder I'm having a tough time integrating that into a C script.

Unity 5.3.4 personal (free)

Android (presuming 5.0 Lollipop)

Ideally I'd like to get Environment.DIRECTORY_MUSIC returned as a string for processing since that unmarries me from doing it manually but it looks like I need to use a Java class to get to it?

Example below works for Windows using Application.datapath, but even set manually (Note 3, checked the file structure manully) it fails. The end goal is to have this on Android, an d a simple pull of the "Music" folder directory list to an array, and the location stored as a string (androidPath).

 using UnityEngine;
 using System.IO;
 using System.Collections;
 using System.Collections.Generic;
 
 public class MusicManager : MonoBehaviour {
 
     public static string[] fileinfo;
     public static int Clipcount;
     public static string androidPath = "/storage/extSdCard/Audio/";
     public string = AndroidJavaObject Environment.DIRECTORY_MUSIC;
     // Use this for initialization
     void Start()
     {
         SetGetFiles();
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
     public static void SetGetFiles()
     {
         // pc version on top works
         // var info = Application.dataPath + "/Audio/";
         var info = "file:///" + androidPath;
         var ftype = "*.mp3";
         fileinfo = Directory.GetFiles(@info, ftype);
         Clipcount = fileinfo.Length;
     }
 }
Comment
Add comment · Show 2
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 skullthug · Aug 31, 2016 at 05:13 AM 0
Share

I don't suppose you ever found a solution to this?

avatar image Cmoche skullthug · Sep 06, 2016 at 06:12 PM 0
Share

Best answers all seem to be making a Javascript wrapper to use for querying this element. So far nobody has been able to point me to a C# or Unity based solution. In the meantime, direct access to that folder is available, in 1 of 2 "Android default" locations, one for devices with internal storage only at "/storage/emulated/0/$$anonymous$$usic" and one for devices with an 'external' SD Card at "/storage/extSdCard/$$anonymous$$usic" This seems to be valid for multiple generations of Samsung devices, and each of the Nexus' I have tested with. Hope it helps!

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Smooth edges on android 1 Answer

Unity 5 mobile single stick control 6 Answers

Dynamically changing a mesh doesn't work on mobile? 0 Answers

Cam texture stopped working in Unity 5/Android Lollipop 0 Answers

FPS Controller from unmodified Standard Assets (U5) not working 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