Android list music by folders and play them -


i'm developing music player android on market. users asking add folder view list folders has music in smartphone , want develop it.

mediastore know correct paths follow (because needs know them re-scan every times sdcard) wondering if there way paths , use them show music user.

another options (but don't it) paths query mediastore music in library , loop on them common base paths. if user have more 1/2k music huge , not optimized way.

do know how can solve it?

i thingking listing folders , files in sdcard i'm encountering in recursive problem because want not show:

  • not audio file (already done filefilter)
  • not show empty folders (already done has recursive problem)
  • not show folders .nomedia file (that tells me there aren't media files, has recursive problem). many folders created others application don't put .nomedia file, i've show them

what think this?

update: want this: https://play.google.com/store/apps/details?id=cyberniko.musicfolderplayer want show folders there music , allow user start playing music in selected folders.

one possible solution said start scanning directories sdcard filefilter wrote:

this audiofilter applied directory returns files song (checking extensions) , directories contains song , not contains .nomedia

this solution, anyway, need skipped because takes long load dir list (because of recursive alg)

package com.designfuture.music.util;  import java.io.file; import java.io.filefilter; import java.io.filenamefilter; import java.util.arraylist;  import com.designfuture.framework.util.loghelper;  public class audiofilefilter implements filefilter {      protected static final string tag = "audiofilefilter";     /**      * allows directories      */     private final boolean allowdirectories;      public audiofilefilter( boolean allowdirectories) {         this.allowdirectories = allowdirectories;     }      public audiofilefilter() {         this(true);     }      @override     public boolean accept(file f) {         if ( f.ishidden() || !f.canread() ) {             return false;         }          if ( f.isdirectory() ) {             return checkdirectory( f );         }         return checkfileextension( f );     }      private boolean checkfileextension( file f ) {         string ext = getfileextension(f);         if ( ext == null) return false;         try {             if ( supportedfileformat.valueof(ext.touppercase()) != null ) {                 return true;             }         } catch(illegalargumentexception e) {             //not known enum value             return false;             }         return false;      }      private boolean checkdirectory( file dir ) {         if ( !allowdirectories ) {             return false;         } else {             final arraylist<file> subdirs = new arraylist<file>();             int songnumb = dir.listfiles( new filefilter() {                  @override                 public boolean accept(file file) {                     if ( file.isfile() ) {                         if ( file.getname().equals( ".nomedia" ) )                             return false;                          return checkfileextension( file );                     } else if ( file.isdirectory() ){                         subdirs.add( file );                         return false;                     } else                         return false;                 }             } ).length;              if ( songnumb > 0 ) {                 loghelper.i(tag, "checkdirectory: dir " + dir.tostring() + " return true con songnumb -> " + songnumb );                 return true;             }              for( file subdir: subdirs ) {                 if ( checkdirectory( subdir ) ) {                     loghelper.i(tag, "checkdirectory [for]: subdir " + subdir.tostring() + " return true" );                     return true;                 }             }             return false;         }            }      private boolean checkfileextension( string filename ) {         string ext = getfileextension(filename);         if ( ext == null) return false;         try {             if ( supportedfileformat.valueof(ext.touppercase()) != null ) {                 return true;             }         } catch(illegalargumentexception e) {             //not known enum value             return false;             }         return false;      }      public string getfileextension( file f ) {         return getfileextension( f.getname() );     }      public string getfileextension( string filename ) {         int = filename.lastindexof('.');         if (i > 0) {             return filename.substring(i+1);         } else              return null;     }      /**      * files formats supported library      */     public enum supportedfileformat     {         _3gp("3gp"),         mp4("mp4"),         m4a("m4a"),         aac("aac"),         ts("ts"),         flac("flac"),         mp3("mp3"),         mid("mid"),         xmf("xmf"),         mxmf("mxmf"),         rtttl("rtttl"),         rtx("rtx"),         ota("ota"),         imy("imy"),         ogg("ogg"),         mkv("mkv"),         wav("wav");          private string filesuffix;          supportedfileformat( string filesuffix ) {             this.filesuffix = filesuffix;         }          public string getfilesuffix() {             return filesuffix;         }     }  } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -