1

It seems that when I put an SD card in my phone with some music, Google Play music suddenly knows about it. Or if I copy more music to the card, Google play hears about it.

I've now purchased a device (Nexus 5) without an SD card slot, but with OTG capability. It seems that just plugging in a USB drive, does not get the built in music app to index it, so I'm trying to write my own.

Where should I start to write a listener, that hears when the USB OTG drive is connected, so I can index the content in my music playing app ? How can I determine the location of the OTG drive (e.g.: /mnt/usbdisk0 etc?) Is there an API to determine this for all devices ?

EDIT: To further clarify, I build AOSP from source (6.0) and installed it on my nexus 5, so the built-in music player is NOT Google Play music, but just the android open source music app. This app does not detect or index the music from the OTG, and I am trying to modify it so that it sees it. If I go to Android's settings app, I can see that it has detected the OTG drive, and I can "explore" it, and play individual files by navigating to the directory where I have stored the music files. But the music app does not index this.

Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190
  • Music index is managed by android itself, it is usually done when it scans the internal sd at boot for example, maybe it does not scan usb storage, but all i can tell you is that you should use the Android music contentProvider so any other app will know about the music on the usb otg. – Nanoc Nov 11 '15 at 10:49
  • About the listener, you should wait for Intent.ACTION_MEDIA_MOUNTED, take a look at this: http://stackoverflow.com/questions/3300137/how-can-i-refresh-mediastore-on-android – Nanoc Nov 11 '15 at 10:51
  • I think the problem with the music app, is that it probably does not refresh the index when the OTG drive is connected, and probably isn't even aware of the OTG drive. I'm trying to look for code where it "listens" for an event indicating that the storage drive is connected but I can't find it. – Rahul Iyer Nov 14 '15 at 02:44
  • just told you the intent you want to listen, have you seen it? – Nanoc Nov 16 '15 at 08:45
  • The problem is actually that in marshmallow they have disabled indexing of otg drives, so you have to scan the otg drive yourself. So listening may not help. i haven't tried it yet though. – Rahul Iyer Nov 17 '15 at 04:16
  • I dont know if it was enabled in previous versions, but of course, i told you how to listen to it, now you will need to perform your logic. – Nanoc Nov 17 '15 at 08:45
  • ok. I will try that. But I think a better solution would be to just edit the android source code at the place where the source detects the media being mounted and then get media store to index it. – Rahul Iyer Nov 20 '15 at 10:09
  • @Nanoc But where will you listen ? Also, since an external USB drive is considered "portable" you have to access it through the storage api's, so I think using Media store is out of the question. Am I right ? – Rahul Iyer Dec 05 '15 at 04:03

0 Answers0