Hiding media files from Music Player

by clark » Tue, 28 Apr 2009 07:36:44 GMT

Sponsored Links
 I'm torn between which group to post this too, but since it is for an
application I am working on, I guess I'll stick it here.

So here we go.  I have an application which downloads data onto the
sdcard to be used by the application.  Some of these files are sound
or music files and the music player in android seems to parse these
directories and add these files to the list.  I'd like to somehow
block or hide these files from the music player.  Is there is a way to
do this?

I was thinking it may be possible to name my folder with a period at
the beginning, since linux hides such files.  I'm just not sure if
that is going to hide it from the music player or if there is another
way to handle this.


Hiding media files from Music Player

by Marco Nelissen » Tue, 28 Apr 2009 07:51:52 GMT


You could have just tried it, and you would have found that that does indeed
have the effect you're looking for.
Alternatively, you can put a file called ".nomedia" in a directory to
prevent the media scanner from scanning that directory.


Sponsored Links

Hiding media files from Music Player

by clark » Tue, 28 Apr 2009 10:06:48 GMT


Could have, assuming I was at my development machine at the time.
Either way, thanks for the info.


Hiding media files from Music Player

by clark » Tue, 28 Apr 2009 13:08:59 GMT

 Just tried it and the sounds are showing up in the music player.  So
much for that idea.  Anyone else  have experience with this?

I guess I can try changing the extension since I pass it the Uri, and
hopefully MediaPlayer and SoundPool don't choke.  I just have quite a
few files and would hate to have to check them and rename them from
within the app or have the users re-download the new data.

Suggestions welcomed.



Hiding media files from Music Player

by nEx.Software » Tue, 28 Apr 2009 14:33:13 GMT

 A quick look shows at the source indicates the MediaScanner omits
files that begin like "._" or are like "Folder.jpg",
"AlbumArtSmall.jpg", "AlbumArt_{...}_Large.jpg" or "AlbumArt_{...}
_Small.jpg". But it all seems to be based on filename. Of course
there's a native method in there "processDirectory" that I don't
understand because I don't understand c++. Maybe that's supposed to
weed out certain folders/files? Of course, I don't know if this helps
at all but I'll let you decide if it does. Almost looks like changing
the extension will be the answer as that appears to be very important
in determining whether the MediaScanner picks up the file.
Good luck, will be interested to see the final answer on this one.


Hiding media files from Music Player

by Marco Nelissen » Tue, 28 Apr 2009 23:32:16 GMT


The native method will skip any folders whose name starts with a period.


Hiding media files from Music Player

by Marco Nelissen » Tue, 28 Apr 2009 23:34:11 GMT

 You put the files in a folder whose name starts with a period, and they
still show up in the music app?
Are you sure it's not the old files in the old location that are still
showing? Can you check that there are actually entries in the media database
whose path (the _data column) includes a folder that starts with a period?


Hiding media files from Music Player

by clark » Tue, 28 Apr 2009 23:52:18 GMT


I actually renamed the folder programmatically and verified that it
was indeed renamed.  Files in media player still show up and play.

I can check the DB once I get home and I am at my development machine,
unless there is an easy way to check that information directly within
the phone.  Music player does not provide file details, unfortunately.


Hiding media files from Music Player

by clark » Wed, 29 Apr 2009 10:20:46 GMT


Actually that did help.  I'm a C++ guy so taking a look at
MediaScanner.cpp in thre OpenCORE git provided some insight.

Based on the code the scanner 'should' omit folders that begin with a
period or folders which contain a file named .nomedia.

A little digging revealed sounds on my sdcard that were similar to the
ones I was using in my app.  Between that and users still complaining
about sounds showing up in their music player I assumed the folder
renaming did not work but indeed it did.

Placing a file named .nomedia in the folder works great as well.


Other Threads

1. Where do I get an Android Phone?

Hello All,

I am new to Android, and have a few questions.

Where do I get an Android Phone?
Ok, I understand there are no phones for sale with Android Preloaded.
But I see all these video's on You Tube with phones running Android
live !!??
So....were do I get a phone that is Android compatable, and I will
load it myself?

Once I recieved said phone.

Can someone out there give me instructions on how to load an OS on a
mobile phone?
I am open to any source for help.

Kind Regards,

2. LifeCycleDemo - android.app.Activity


I have a produced a "tutorial" screencast; the title is LifeCycleDemo.
The screencast covers the Activity life cycle and also introduces the
watcher to logcat and gsm. To view LifeCycleDemo go to


I intend to make more screencasts over the next few months so your
feedback on this topic is very welcome.

Further screencasts will be released on blip.tv and blogged about here


Please email your comments / criticisms to



3. MediaPlayer aborts abruptly - m5-rc15

4. 3 new Android tutorials on how to build a service enabled Android app

5. ADT 0.4.0 for Linux

6. hi... regarding call options...

7. Build A Website For Free