platformRequest无法在J2ME中运行

时间:2014-03-17 10:29:43

标签: java-me media-player nokia nativeapplication

我正在尝试使用平台Request()播放.mp3文件。我验证了文件路径,它是正确的。我正在使用诺基亚210进行测试。请帮我解决这个问题。

2 个答案:

答案 0 :(得分:0)

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

我知道您已经验证了是否存在文件。虽然检查我的下面的代码一次并发表评论与结果。

已添加 -

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");
    }
}

答案 1 :(得分:0)

经过这么多搜索,我发现了一些问题的原因。这可能对将来遇到同样问题的人有所帮助。请参阅以下链接。

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

相关问题