Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 935995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:14:38+00:00 2026-05-15T21:14:38+00:00

First off – I haven’t had much experience with Java yet, and I’m a

  • 0

First off – I haven’t had much experience with Java yet, and I’m a beginner when it comes to the Android SDK.

I’m trying to write a music player app, which when started scans the entire SD card for mp3 files.

Currently this is how I’m doing that:

// Recursively add songs in a directory
public void addSongsInDirectory(File dir, String filter) {
    File[] files = dir.listFiles();
    if (files != null) {
        for  (File f : files) {
            if (f.isDirectory()) {
                addSongsInDirectory(f, filter);
            } else {
                // Create new MimetypesFileTypeMap
                MimetypesFileTypeMap mtfm = new MimetypesFileTypeMap();
                // Add the mp3 mimetype
                mtfm.addMimeTypes("audio/mpeg mp3");

                // If current song is audio/mpeg, add it to the list
                if (mtfm.getContentType(f).equals(filter)) {
                    songs.add(f.getName());
                }
            }
        }
    }
}

Unfortunately, on my handset with many songs on it, this process takes about 30 seconds. How can I optimize this function so that it works faster (and possibly in the background)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:14:38+00:00Added an answer on May 15, 2026 at 9:14 pm

    An Android specific optimisation is to look for a file called .nomedia in a directory. This is an indication that there are no media files in a directory in any of its subdirectories. The idea is that applications can create a .nomedia file in their data directories to tell media applications that there’s no need to scan them because there’s no media in there (or possibly there are media files which are only used internally by the application, such as music from a game).

    Alternatively, you could skip writing your own scanner and use the Media Scanner built in to Android. It’s simply a matter of querying the appropriate ContentProvider.

    Your code will look something like this:

    String[] projection = new String[] {
        MediaStore.Audio.Media.ALBUM,
        MediaStore.Audio.Media.ARTIST,
        MediaStore.Audio.Media.TITLE
    };
    
    Cursor cursor = managedQuery(
        MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, //URI
        projection, //columns to return
        null, //rows to return -  all
        null, //selection arguments - none
        null // sort order - default
    );
    
    cursor.moveToFirst();
    
    while(! cursor.isLast()) {
        Log.d("MediaTest","Found track:");
        Log.d("MediaTest","Album " + cursor.getString(0));
        Log.d("MediaTest","Artist " + cursor.getString(1));
        Log.d("MediaTest","Track " + cursor.getString(2));
        cursor.moveToNext();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 498k
  • Answers 498k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What tool chain are you using? (Visual Studio, Qt Creator/g++)… May 16, 2026 at 12:09 pm
  • Editorial Team
    Editorial Team added an answer Personally I haven't stored files in MongoDB yet, but according… May 16, 2026 at 12:09 pm
  • Editorial Team
    Editorial Team added an answer You can validate xml files against XSD. First you have… May 16, 2026 at 12:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

First off, I'm not really sure how much information is necessary to include because
First off, I am using Windows XP. I have multiple hard drives and it
First off, I understand the reasons why an interface or abstract class (in the
First off if you're unaware, samba or smb == Windows file sharing, \\computer\share etc.
First off, there's a bit of background to this issue available on my blog:
First off: I'm using a rather obscure implementation of javascript embedded as a scripting
First off, I'm working on an app that's written such that some of your
First off, let me start off that I am not a .net developer. The
First off, this question is ripped out from this question. I did it because
First off, I know next to nothing about language theory, and I barely know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.