Fix Android Media server scanner SDcard CPU, Battery drain

What is Mediaserver?

Mediaserver or Media scanner on Android is designed to scan and index every media file: Images, Videos, Music and make the list available to all Android apps, so that they don’t have to do the repetitive tasks. But it isn’t perfect.

Media server can have strange behaviors and tends to be buggy. Very often you can end-up shedding 50% of your battery on Media scans. Not only does media scanner go wrong on custom ROMs but many of the official stock ROMs too. So out of the blue, one day the media scanner would run crazy and drain your battery.

mediaserver-battery

How to Fix Mediaserver / scanner Battery drain

One quick way to get around is to stop Media scanner service altogether (using apps on Play store) but that way your songs, photos, videos would vanish from your gallery, music player.

The situation is more frequent once your sdcard (internal or external) gets old and you’ve lots of files.

mediaserver-battery-drain

I had been digging out how to fix it, and here are my solutions. Perhaps try al of them, it would definitely relieve your cpu and battery usage by large. Solution works on any Android version:

Solution 1. Clear media storage data

The simplest solution is to clear media storage database and let it restart the process from scratch. Chances are this will fix most of the issues with Mediascanner/Mediaserver. Do the following, and it should help ease-out the pain:

Settings > applications > Media Storage > clear data, force stop and reboot.

Solution 2. Remove unwanted media files

Mediaserver really does a hard job while analyzing each media file it encounters, reading metadata, generating thumbnails, inserting into Android mediastore database. You can ease-out its processing by removing unwanted, trash files.

Navigate to /sdcard/DCIM/.thumbnails and delete all files. Repeat for external sd card. On AOSP ROMs, Android gallery creates too many of thumbnails that later becomes problematic for media scanner. Deleting them once in few months is a good idea.

Note: If this is a very slow process, use adb commandline to delete these

adb shell
cd /sdcard/DCIM/.thumbnails
rm *

Solution 3. Analyze and Delete excessive media files

As we discussed in solution 2 that mediaserver can be doing heavy lifting due to excessive media files on sdcards. In this step we find-out what files are causing media scanner to go mad.

You can use any sdcard analyst from Play Store (I use ES file manager > menu > Sd card analyst) to determine which directory has lots of files/subdirectories. Any directory having >1000 files/folders is an alarmingly high number. Get rid of them (if you can). However, do not delete any apps/system files in the process.

Solution 4. Probe and Delete bad/damaged media

If you’re sure you’ve tried above solutions and still encountering battery drain, its time to dig deeper with the help of Android developer tools.

Pre-requisites:

  1. You must be rooted,
  2. Android developer tools setup with ADB being able to detect devices connected to USB (Windows, OS X, or Linux)

With ADB tools installed, enter shell and acquire SuperUser permissions:

adb shell
su

Note: You might be prompted on phone to authorize superuser access. You must Grant it

Then run “top” (linux process manager) to see which process is eating your phone’s CPU. The command below filters top results related with media scanner:

top -grep media

Running the above command would respond something like:

130|root@n7000:/ # top | grep media
1905 0 15% S 7 23080K 6168K bg media /system/bin/mediaserver
2808 0 42% S 3 3524K 740K media_rw /system/bin/sdcard
2825 0 11% S 19 255832K 43936K bg u0_a5 android.process.media

%age cpu shows media server is eating cpu and needs to be fixed. Run the following command to determine which file is it currently reading.

lsof | grep media_rw

root@n7000:/ # lsof | grep media_rw
sdcard 2808 media_rw exe ??? ??? ??? ??? /system/bin/sdcard
sdcard 2808 media_rw 0 ??? ??? ??? ??? /dev/null
sdcard 2808 media_rw 1 ??? ??? ??? ??? /dev/null
sdcard 2808 media_rw 2 ??? ??? ??? ??? /dev/null
sdcard 2808 media_rw 3 ??? ??? ??? ??? /dev/fuse
sdcard 2808 media_rw 4 ??? ??? ??? ??? anon_inode:inotify
sdcard 2808 media_rw 5 ??? ??? ??? ??? /mnt/media_rw/sdcard1
sdcard 2808 media_rw 6 ??? ??? ??? ??? /mnt/media_rw/sdcard1/audiobooks
sdcard 2808 media_rw 7 ??? ??? ??? ??? /mnt/media_rw/sdcard1/audiobooks/2-14 Einstein CD 02- Track 14.mp3

If the media service is stuck at a directory/file for a long time, you know it’s a damaged media file, you should probably get rid of it.

Once you get rid of all such files/directories, its guaranteed media server would finish scanning soon enough.

Solution 5: Format SD cards

If nothing works (or you’re noob enough to try solution 4): Take backup and format Internal, external SD card and copy only selective files/folders that you need. Problems would go away for sure.

Solution 6: Disable Media scanner

If your Droid is against you and it just won’t tame, its time to disable the media scanner. You can do this from adb shell

adb shell
su
pm disable com.android.providers.media/com.android.providers.media.MediaScannerReceiver

You can re-enable it later with:

pm enable com.android.providers.media/com.android.providers.media.MediaScannerReceiver

Say goodbye to mediascanner problems, forever.

Still got problems? Leave your logs in the comments section, we will get back to you as early as possible.

We write latest and greatest in Tech GuidesAppleiPhoneTabletsAndroid,  Open Source, Latest in Tech, subscribe to us @geeknizer OR on Facebook FanpageGoogle+.

GD Star Rating
loading...
GD Star Rating
loading...
Fix Android Media server scanner SDcard CPU, Battery drain, 7.7 out of 10 based on 44 ratings

21 thoughts on “Fix Android Media server scanner SDcard CPU, Battery drain”

  1. When I put in the “top -grep media” command, I get error invalid argument “-grep”……any ideas?

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
    • @disqus_jIDG9saKEa:disqus
      Try “top | grep media”
      or better “top -n 1 | grep media” (the process information is only shown once and not updated every second)

      GD Star Rating
      loading...
      GD Star Rating
      loading...
      Reply
  2. how can I check which files the media server is scanning or scanned recently? “lsof | grep media_rw” does not return anything at all, and using “media” instead of “media_rw” doesn’t return anything useful.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  3. I have done 1 through 4 above, in the process of formatting SD cards. When I performed top | grep media command, I saw 0% CPU usage but when I refer to the phone battery app, the mediascanner is at 35%. And it did not hang up on any file using the lsof command.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  4. I went and did step 5, worked for about 3 hours, then media scanner rears its head. The thing is, I did not load any pictures, music, movies, nothing. Just formatted the external card and factory reset the phone. Loaded apps, let it sit for 3 hours, came back and theres a battery drain. Guess I’ll have to resort to #6. Most frustrating.
    Geeknizer, thank you so much for the thorough guide.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  5. Excellent summary, even if it does not show a real solution (probably there is none, but for custom ROMS or buying all Google shares and replacing the CEOs).
    Besides wasting battery it also fills up the app storage (it used more than 400 MB of the 2 GB Samsung provided on my device). Therefore I suggest to delete this storage before disabling the media scanner. I think what works is do Step 1, but take out the SD card before reboot, let the scanner do his work on the internal memory, then disable it, and insert the SD card.
    BTW, I had to move my personal ring-tones from the card to system storage to use them.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  6. You’re confusing media server and media scanner. They are two different things, running in two different processes.
    The media server, which shows up as “Mediaserver” in your battery stats screenshot above, is responsible for media decoding and encoding, and playback and recording.
    The media scanner, which shows up as “Media” in battery stats, is the process that scans your sd card. Media scanner makes use of some of the services provided by media server.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  7. I’m facing this issue for several months ever since upgraded to JB.
    The problem is my SD contains a huge directory structure with lots of images. say more then 100K files…
    In the past(android-2xx) a simple “.nomedia” file in each folder was enough. but now it insist of scanning the whole directory structure and keeps a “dummy” meta data which consumes all my internal storage – more then a 1.5G…
    When it happens – i simply clear its memory, reboot, umount the sd and let it update itself, and then disable the scanner and remount the sd.

    How can i prevent the media scanner to run on a certain folder???

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  8. Thanks! Solution 1 worked first time of trying! Went from a full charge lasting just 11 hours to using only 13% in the same time…. Galaxy S5

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  9. I started using my brand new Samsung Galaxy S5 without SD card and nearly immediately media server was draining my battery. I could solve the problem by first adding a freshly formatted SD card and then apply solution 1 above.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  10. Your tips help solve my PERFORMANCE issues, but NOT my battery drain.
    I added “turning OFF background data” & disabling Mediaserver.
    I was having extreme difficulty charging the battery.
    Resetting Mediaserver gave back my performance.
    Then I discovered my streaming app (internet radio streaming) was using high battery & hign wake hours.
    Uninstalling/reinstalling the app solved the battery drain issue.
    Force stop & delete cache did NOT solve the proble.
    In the end it was a misbehaving media streaming app!!!!

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  11. Mediaserver was using 30%+ of my battery and the whole phone was sluggish. Solution #1, just clearing the cache/data and rebooting completely fixed the problem for me, even after a regular reboot did not. I didn’t need to delete/move any photos.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  12. I had the problem of system/bin/mediaserver constantly running and draining a lot of my battery. I analysed the problem and found out that it was constantly scanning the cache files of all applications on my phone. Therefore I placed a .nomedia file in Android/data.
    You do not need root for this, but a good explorer program like 7Zipper or similar.
    Putting this file there instructs the mediaserver not to scan the subfolders. Problem fixed. The process works as it should – i.e. media database is regularly updated, but only when needed. No need to use booster programs or kill any tasks.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply
  13. This article saved me. I was struggling mainly because I didnt undertand what this media server was. Steps 1 and 2 fixed it but… I also lost my audio playlists! Be aware of that.

    GD Star Rating
    loading...
    GD Star Rating
    loading...
    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.