×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    how to get all .mp3 files(from both media card and device memory) in j2me ?

    Hi,

    Is there anyway to get all .mp3 file listing in j2me like android.
    and if not what is the best way to get all mp3 files.


    thankx

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,569

    Re: how to get all .mp3 files(from both media card and device memory) in j2me ?


  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: how to get all .mp3 files(from both media card and device memory) in j2me ?

    Quote Originally Posted by hitendrasinh.gohil View Post
    Hi,

    Is there anyway to get all .mp3 file listing in j2me like android.
    and if not what is the best way to get all mp3 files.


    thankx
    You can find the PDAP demo inside the WTK app folder , you read the code and you will come to know what to do for this kind of operation.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    Re: how to get all .mp3 files(from both media card and device memory) in j2me ?

    thankx petrib it helps me.

  5. #5
    Registered User
    Join Date
    Mar 2014
    Posts
    2

    Re: how to get all .mp3 files(from both media card and device memory) in j2me ?

    Tested this code on an e72 with 8GB mem-card and it worked fine.

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    import java.io.IOException;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.util.Enumeration;
    import java.util.Hashtable;
    import javax.microedition.io.Connector;
    import javax.microedition.io.file.*;

    /**
    * @author crazywizard
    */
    public class RootMIDlet extends MIDlet implements CommandListener{
    private List list;
    private Command exitCommand;
    private Hashtable allowed_types;

    public RootMIDlet(){
    /* Construct MIDlet */
    //Define the file types of interest here
    allowed_types = new Hashtable();
    allowed_types.put("mp3", "audio/mp3");
    }

    public void startApp() {
    list = new List("My Files", List.IMPLICIT);
    exitCommand = new Command("Exit", Command.EXIT, 0);
    list.addCommand(exitCommand);
    list.setCommandListener(this);
    Display.getDisplay(this).setCurrent(list);
    getRootList();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void getRootList(){
    //Get ALL available filesystem mounts
    Enumeration drives = FileSystemRegistry.listRoots();
    while(drives.hasMoreElements()){
    //Iterate through the drives
    String driveString = drives.nextElement().toString();
    list.append("Searching "+driveString, null);
    getFileList("file:///"+driveString);
    }
    }//--End of getRootList()

    public void getFileList(String path){
    try {
    //Open path
    FileConnection fc = (FileConnection)Connector.open(path, Connector.READ);
    //Get list of ALL files and dirs
    Enumeration filelist = fc.list(); //Get Hidden files as well --fc.list("*", true);
    while(filelist.hasMoreElements()){
    String filename = (String)filelist.nextElement();
    FileConnection fc1 = (FileConnection)Connector.open(path+filename, Connector.READ);
    //Check for dirs
    if(fc1.isDirectory()){
    //Apply recursion here
    getFileList("file://"+fc1.getPath()+filename); //Note use of *double // instead of triple ///. Adjust accordingly according to phone platform
    }else{
    //Filter for only allowed types == .mp3
    String file_type = getFileType(filename).toLowerCase();
    if(!allowed_types.containsKey(file_type)){
    //Do Nothing and Pass
    continue;
    }
    list.append(fc1.getPath()+filename, null);
    }
    }
    //Clean resources
    fc.close();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    Display.getDisplay(this).setCurrent(new Alert("Error", ioe.toString(), null, AlertType.ERROR));
    } catch (Exception ex) {
    ex.printStackTrace();
    Display.getDisplay(this).setCurrent(new Alert("Error", ex.toString(), null, AlertType.ERROR));
    }
    }

    /* Helper Method */
    private String getFileType(String fileName){
    //Get file extension from fileName
    char ch = '.';
    int index = fileName.lastIndexOf((int)ch);
    return fileName.substring(index+1);
    }//--End of getFileType(String)

    public void commandAction(Command c, Displayable d) {
    if(c == exitCommand){
    notifyDestroyed();
    }
    }
    }

Similar Threads

  1. Creating a folder on the device memory card, J2ME, MIDP
    By eretief in forum Mobile Java General
    Replies: 2
    Last Post: 2010-10-21, 13:28
  2. Playing mp3 files on memory card using Player class in MMAPI
    By ZeeZuLander in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2010-08-16, 07:08
  3. protect downloaded mp3(in memory card)
    By kuddy_abc in forum Symbian
    Replies: 1
    Last Post: 2010-05-29, 06:46
  4. Can J2ME read files from memory card?
    By baihaoping in forum Mobile Java General
    Replies: 3
    Last Post: 2006-03-12, 02:48
  5. Replies: 1
    Last Post: 2004-01-13, 23:16

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×