首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在J2ME中从存储卡中的文件播放.mp3歌曲

如何在J2ME中从存储卡中的文件播放.mp3歌曲
EN

Stack Overflow用户
提问于 2019-04-11 23:19:41
回答 1查看 0关注 0票数 0

我正在尝试在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());
        }
 }
        });
EN

Stack Overflow用户

发布于 2019-04-12 08:25:53

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

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将它安装在设备上并找到正确的文件夹名称。然后你就可以玩了来自存储卡的媒体文件。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100009008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档