我试过这段代码,但它不适用于ClamshellCldcPhone1(MIDP 2.1,CLDC 1.1)
使用“pattern.mid”文件它可以工作,但是使用“s.mp3”文件它没有
我知道,播放器加载数据(s.mp3)但不播放,
我把 s.mp3 int package“audio”,s.mp3的大小小于1MB。
谁能帮我?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VolumeControl;
import javax.microedition.midlet.*;
/**
* @author tqwer
*/
public class PlayMp3 extends MIDlet {
Display display = null;
InputStream inputStream = null;
Player player = null;
VolumeControl volumeControl = null;
public PlayMp3() throws IOException, MediaException {
display = Display.getDisplay(this);
display.setCurrent(new Form("form"));
if(1==1) {
inputStream = getClass().getResourceAsStream("/audio/s.mp3");
player = Manager.createPlayer(inputStream, "audio/mpeg");
}else{ inputStream = getClass().getResourceAsStream("/audio/pattern.mid");
player = Manager.createPlayer(inputStream, "audio/midi");
}
player.realize();
player.prefetch();
volumeControl = (VolumeControl)player.getControl("VolumeControl");
volumeControl.setLevel(100);
player.start();
volumeControl = (VolumeControl)player.getControl("VolumeControl");
volumeControl.setLevel(100);
try {
inputStream.close();
} catch (IOException ex) {
ex.printStackTrace();
}
inputStream = null;
}
public void startApp() {
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}