簡體   English   中英

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

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

我正在嘗試在J2ME中創建一個Music Player應用程序。 我想知道如何播放存儲卡和手機內存中的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());
        }
 }
        });

您不能直接作為字符串參數訪問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找到此文件,然后將其安裝在設備上並找到正確的文件夾名稱。然后您就可以播放了存儲卡中的媒體文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM