1

J2ME で音楽プレーヤー アプリを作成しようとしています。メモリカードと携帯電話のメモリに保存されている mp3 ファイルを再生する方法を知りたいです。以下は、実行しようとしているコードです( else部分)。エラーなしで準拠しますが、サウンドは再生されません。

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

1 に答える 1

3

文字列パラメータとしてメモリカードに直接アクセスすることはできません。どのタイプのメモリ アクセスでも、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 を使用してこれを見つけることができます。デバイスにインストールし、正しいフォルダ名を見つけます。その後、再生できます。メモリ カードからメディア ファイルを削除します。

于 2011-11-17T13:13:57.553 に答える