5

How can I make mediascanner scan phone memory, i.e. the /data directory? I want to test playing MP3s from this directory.

When I try to hack it by replacing the "pathStr" from /mnt/sdcard to /data before MediaScanner::doProcessDirectory(), it fails saying

W/MediaScanner( 1713): Error opening directory '/data/', skipping: Permission denied.

And also crashed (probably in free).

I just want to play MP3s stored in phone memory and avoid reading the SD card for some experiments.

Bill the Lizard
  • 281
  • 4
  • 14
dls
  • 51
  • 1
  • 2
  • Without root one program can't access /data of another program. – roxan Jul 20 '12 at 08:25
  • Roxan, I understand that but how can I play mp3 from /data folder? – dls Jul 20 '12 at 08:33
  • I mean, Can I change root permission for this process somewhere? – dls Jul 20 '12 at 08:34
  • Have you tried browsing using a root file explorer such as FX, and playing through that? Having said that, you'll probably need to run the media player as root too. – Jeeva Jul 20 '12 at 09:21
  • How do you use FX? I see one app called MusicFX in my /packages/apps, will this be able to do that?? – dls Jul 20 '12 at 11:04

3 Answers3

2

EDIT: This is rendered obsolete with Jelly Bean. Android 4.1+ has a unified /data/ and /sdcard section (the sdcard partition is emulated and really resides in /data/media, it's exposed via a special fuse layer to emulate FAT32 behaviour)

My thoughts on this:

  • The media scanner scans everything below /mnt
  • /data/* is protected, only individual apps can access their folder (/data/data/[app's package name])

To get it working the way you like:

  • You need root (obviously)
  • symlink /mnt/music to /data/data/your-music-location
  • you can also do a bind-mount instead of a symlink:
    mount --bind /data/your-music-location /mnt/sdcard/your-music-location
  • Lift access rights accordingly (chmod -R ugo+rw /data/data/your-music-location)

Hope this works (the scanner should scan the whole /mnt as there's also /mnt/emmc and such). If not, you can also bind-mount a /data/data/* folder to /mnt/sdcard/your-music (as done with /mnt/sdcard/.android_secure (see the answer))

ce4
  • 14,446
  • 10
  • 60
  • 106
  • I realize that /system folder has permissions and does not require root permissions. – dls Jul 20 '12 at 11:37
  • Don't use system. It's mounted read-only and must only be used for firmware (or root-related) stuff. I'd also suggest not to use data, except for testing and learning. Does it offer so much more space than your sd card that it's worth it? – ce4 Jul 20 '12 at 11:39
  • How can I list music also from /system/media/audio into music player? This will help me to play the mp3 from system memory rather than SD Card. I want to make minimal change to do this. By hacking at some place in mediaScanner I think it is possible but is there a better method where I can list music from SD Card as well as from /system/media/audio ??? Thanks in advance. – dls Jul 20 '12 at 11:39
  • I am using only for some experimental setup. So I am fine with using /system also for mp3 playback. – dls Jul 20 '12 at 11:42
  • Be warned, editing /system will survive a wipe (or reset), FYI. maybe do a 'ln -s /your/music/location /mnt/music' and have the rights set appropriate. You need to remount /system read-write before you can write to /music. AGAIN: I suggest you don't do this. (Asking such question here implies you should be more aware of the risks involved. At least IMHO) – ce4 Jul 20 '12 at 11:48
  • Thanks, I understand. As far as it plays mp3 correctly I am fine to play from /system as this is just for some experiment in development board and not in a costly working phone. I am doing a study and for that I need to do this experiment. I want to know how can I easily list files from any system directory. I can see that some hack n mediascanner does it. Please suggest a better method. Thanks. – dls Jul 20 '12 at 11:52
  • I cannot think of more ways than stated in my answer: 1st: Symlink from /mnt/music to /my/music/library (ln -s /real-path /mnt/my-music-library) or bind-mount /my/music/library to /mnt/sdcard/my-music-library (mount -o bind /real-path /mnt/sdcard/my-music-library) – ce4 Jul 20 '12 at 12:01
0

To furnish my thoughts, hacking on just the in-built media-scanner will not just suffice, as that requires rolling your own ROM! The reason being is that media-scanner is signed with a system certificate that is shared with the ROM in question.

And thus, that requires having the signed keys from the original ROM in order to replace the in-built media-scanner.

As to attempting to put MP3s in the /system/media/audio folder - why? Are we talking about album mp3s which can creep up to between 5-8Mb in size? Or are we talking about Ogg Vorbis for ringtones/notifications?

The /system partition is limited in size depending on the manufacturer's handset setup in terms of partition layouts.

If the audio media is stored on the SDCard under the respective directory /sdcard/media/audio/Ringtones and /sdcard/media/audio/notifications, along with a URI (Uniform Resource Identifier) pointing to the appropriate media declared as "external storage media" as in "MediaStore.Audio.Media.EXTERNAL_CONTENT_URI" (see the Developer Documentation on this), it will get picked up by Android itself and will show under the Settings > Sounds, as 'Phone ringtone' or in 'Notification ringtone'.

Depending on the ROM in itself, there may be a Development tools called 'Dev Tools', in there, there is an activity which can trigger the invocation of the in-build Media-Scanner, this is in stock/vanilla AOSP Android.

t0mm13b
  • 13,436
  • 1
  • 48
  • 58
-1

If you have a standard Linux file system (i.e., not FAT32) on your SD card, you could create Soft Link of /data in /mnt/sdcard.

ce4
  • 14,446
  • 10
  • 60
  • 106
iOS
  • 12,381
  • 13
  • 63
  • 103