1. I dont know why, but playTone doestn work. I'm looking on specs (UAProfile) and I can see that this device understands x-tone-seq. (Device specifications : 5320 XpressMusic)
2. Trying to learn more about sounds in j2me and when app tryes to play sound, I see this error: java.lang.NullPointerException: 0
Code:/* * soundtest.java */ package soundtest; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.media.*; import javax.microedition.media.control.*; //import java.lang.*; import java.io.*; public class soundtest extends MIDlet implements CommandListener { private Command exitCmd = new Command("Exit", Command.EXIT, 1); private Command beepCmd = new Command("Beep", Command.ITEM, 1); private Command soundCmd = new Command("Sound", Command.ITEM, 2); private InputStream is; private Player player; private Display display; private Form mainForm; public soundtest(){ } protected void destroyApp(boolean unconditional){ } protected void pauseApp(){ } protected void startApp()throws MIDletStateChangeException{ display = Display.getDisplay(this); try { // ===================================================== I use standart WTK20 so path for file should be like this? InputStream is = getClass().getResourceAsStream("/audio.wav"); Player player = Manager.createPlayer(is, "audio/x-wav"); } catch (Exception e){ System.out.println("Error in def section: "+ e.toString()); } mainForm = new Form("soundtest"); mainForm.addCommand(exitCmd); mainForm.addCommand(beepCmd); mainForm.addCommand(soundCmd); mainForm.setCommandListener(this); display.setCurrent(mainForm); } public void commandAction(Command c, Displayable d) { if (c == exitCmd) { destroyApp(false); notifyDestroyed(); } if (c == beepCmd) { try { Manager.playTone(ToneControl.C4, 250, 100); } catch (MediaException e) { // System.out.println("Unable to execute "); } } if (c == soundCmd) { try { player.prefetch(); player.start(); } catch(Exception e) { System.out.println("Error in play section: "+ e.toString()); } } }

Reply With Quote



