2

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

4

2 回答 2

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");
    }
}
于 2014-03-18T07:05:42.197 回答
0

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

使用 MIDlet.platformRequest() 打开文件如何在 j2me 的系统媒体播放器中播放媒体文件????

于 2014-03-25T11:36:01.253 回答