【问题标题】:How to play .mp3 songs from files in memory card in J2ME如何在 J2ME 中播放存储卡中文件中的 .mp3 歌曲
【发布时间】:2011-08-21 03:44:05
【问题描述】:

我正在尝试在 J2ME 中创建音乐播放器应用程序。我想知道我们如何播放存储在存储卡和手机内存中的 mp3 文件。下面是我试图执行的代码(在其他部分)。它没有任何错误,但不播放任何声音。

playButton.addClickListener(new ClickListener() {
     public void onClick(Component arg0) {
        try{
            if(player.getState() == player.STARTED){
               player.stop();
               player_GUI.playButton.setText("play");
            }
            else{
            player = Manager.createPlayer("file:///E/song1.mp3");
        player_GUI.playButton.setText("pause");
                player.realize();
        player.prefetch();
        player.start();
            }
        }
        catch(Exception e){
           CatchError.showError("click play ", e.getMessage());
        }
 }
        });

【问题讨论】:

  • 你在真机上测试过吗?
  • 我使用了第 3 方 GUI 库。 (Garcer J2ME GUI)

标签: java java-me audio-player


【解决方案1】:

您不能直接作为字符串参数访问 Memorycard。对于任何类型的内存访问,您需要创建一个 FileConnection。我给出下面的代码。

Player p ;
  FileConnection connection = (FileConnection) Connector.open("file:///M:/sampleVideo/file1.mpg");
        // If you run on the simulator then it is memorycard and if it device then it is specific to that device
       // FileConnection connection = (FileConnection) Connector.open("file:///memorycard/sampleVideo/6.mp4");
                                InputStream inStream = null;
                                inStream = connection.openInputStream();
                                try {
                                    p = Manager.createPlayer(inStream, "video/mpg");
                                    p.addPlayerListener(this);
                                   p.realize();

首先您必须找出该设备的存储卡文件夹名称,然后将其硬编码为 E:。您可以使用 Sun 的无线工具包示例 PDAPDemo 找到它,将其安装在设备上并找到正确的文件夹名称。然后您就可以播放存储卡中的媒体文件了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 2013-11-30
    • 1970-01-01
    相关资源
    最近更新 更多