2

I'm triyng to play .mp3 file using platformRequest(). I verified the file path and it is correct. And I'm using Nokia 210 for testing. Please help me to fix this issue.

prabhu
  • 1,158
  • 1
  • 12
  • 27

2 Answers2

0
try {
    platformRequest("file:///C:/song.mp3");
} catch (ConnectionNotFoundException ex) {
    ex.printStackTrace();
}

I know you have already verified whether there is file or not. though check my below code once and post comment with results.

Added -

public boolean isFileExisted(String path) {
    boolean isExisted = false;
    FileConnection filecon = null;
    try {
        filecon = (FileConnection) Connector.open(path, Connector.READ);
        isExisted = filecon.exists();
    } catch (java.lang.SecurityException e) {
    } catch (Exception e) {
    } finally {
        try {
            if (filecon != null) {
                filecon.close();
            }
            catch (Exception e) {
            }
        }
        return isExisted;
    }
}

public void playFileFromSDCard() {

    String path1 = "file:///C:/song.mp3";
    String path2 = "file:///E:/song.mp3";

    if (isFileExisted(path1))   {
        try {
            System.out.println("path1 exist -> calling platform request " + path1);
            platformRequest(path1);
        } catch (ConnectionNotFoundException ex) {
            ex.printStackTrace();
        }
    }
    else if (isFileExisted(path2)) {
        try {
            System.out.println("path2 exist -> calling platform request " + path2);
            platformRequest(path2);
        } catch (ConnectionNotFoundException ex) {
            ex.printStackTrace();
        }
    }
    else {
        System.out.println("both path doesnt exists");
    }
}
mr_lou
  • 1,910
  • 2
  • 14
  • 26
prabhu
  • 1,158
  • 1
  • 12
  • 27
  • I tried your code and i got "path1 exist -> calling platform request file:///C:/song.mp3" – prabhu Mar 18 '14 at 09:43
  • Check below links. You need to pass the URI instead of path. 1) http://www.javaproblemstips.com/652361/ 2) http://developer.nokia.com/community/discussion/showthread.php/208349-How-to-play-media-file-in-System-media-player-in-j2me – Vishal Mar 18 '14 at 10:27
  • I followed the sample ways in those links. nothing works. Can you please give me a working example for media files. – prabhu Mar 18 '14 at 13:12
0

After so many searches i found some reasons for the issue. This may help for people in future who is having the same problem. refer the following links.

Open file with MIDlet.platformRequest() , How to play media file in System media player in j2me????

Community
  • 1
  • 1
prabhu
  • 1,158
  • 1
  • 12
  • 27