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+.

VN:F [1.9.22_1171]
Rating: 7.7/10 (41 votes cast)
VN:F [1.9.22_1171]
Rating: +15 (from 15 votes)
Fix Android Media server scanner SDcard CPU, Battery drain, 7.7 out of 10 based on 41 ratings

Filed in: Android Tags: 

Related Posts

Bookmark and Promote!

  • Justyn

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

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
    • Johan

      @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)

      VA:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  • guest

    How to use the adb shell? Other solutions no working for me. Thanks

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
    • Install Android SDK, then use commandline.

      VA:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  • bragat

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • Ty

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • Ty

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: -1 (from 1 vote)
  • justextreme

    Thanks for this page. Helped me sort out a Media drain issue 🙂

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
    • I’m glad.

      VA:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  • Peter Steier

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • Marco

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • shahav

    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???

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • Todd Morrow

    Step 6 did not work for me

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • TheFeenee

    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

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • LaKits

    If I clear media storage database will that clear all my photos and videos?

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • Johan

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • U!

    Check this app form google play
    “Quick media scan.Kitkat ready.”

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • camanokid

    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!!!!

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • Adam Ellsworth

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • Mihail Kachov

    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.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
© 2016 Geeknizer. All rights reserved. XHTML / CSS Valid.
Designed by taranfx.