简体   繁体   English

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

[英]How to play .mp3 songs from files in memory card in J2ME

I am trying to create a Music Player App in J2ME. 我正在尝试在J2ME中创建一个Music Player应用程序。 I want to know how can we play the mp3 files stored in memory card and phone memory. 我想知道如何播放存储卡和手机内存中的mp3文件。 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());
        }
 }
        });

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. 您不能直接作为字符串参数访问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();

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM