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

发布于 2024-11-30 18:24:12 字数 747 浏览 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());
        }
 }
        });

I am trying to create a Music Player App in J2ME. I want to know how can we play the mp3 files stored in memory card and phone memory. below is the code i am trying to execute(in else part). It complies without any error but doesn't play any sound.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞笑我太脆弱 2024-12-07 18:24:12

您不能直接作为字符串参数访问 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 找到它,将其安装在设备上并找到正确的文件夹名称.然后您就可以播放存储卡中的媒体文件。

You can not access Memorycard directly as a string parameter.for any type of memory access you need to make a FileConnection.i give the code below.

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();

first you have to find out memory card folder name of that device then only you hard code this as E:.you can find this using Sun's wireless toolkit example PDAPDemo install it on device and find the correct folder name.then you can able to play media file from the memory card.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文