| Author |
Problem when palying audio
|
Sameera Abeysekara Abeysekara
Greenhorn
Joined: Apr 10, 2007
Posts: 19
|
|
I wrote code for palaying audio but this code give an exception.Exception is java.lang.IllegalArgumentException i cant solve this problem.help me to solve this this is the code void playAudio(){ try{ InputStream is =getClass().getResourceAsStream("/3013.wav"); Player player = Manager.createPlayer(is,"audio/X-wav"); player.addPlayerListener(this); player.setLoopCount(-1); player.prefetch(); player.realize(); player.start(); } catch(Exception e){ System.err.println(e); }
|
 |
Deepan Devadasan
Ranch Hand
Joined: Jan 25, 2007
Posts: 226
|
|
Hi, Welcome to the Ranch.... I think one of the arguments in the Player.createPlayer() whould be audio/x-wav as opposed to audio/X-wav... Watch for the right case in the midi.. Hope this helps...
|
Theepan Thevathasan
SCJP 1.4, SCWCD 1.4, SCMAD 1.0 SCBCD 1.3, MCP(.Net Frm 2.0 App Dev Fdn)
|
 |
nikunj anand
Greenhorn
Joined: Apr 06, 2007
Posts: 13
|
|
hi sameera this is the code that play sound file in midlet. import java.io.*; import javax.microedition.io.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; import javax.microedition.media.*; public class AudioMIDlet extends MIDlet implements CommandListener, Runnable { private Display mDisplay; private List mMainScreen; public void startApp() { mDisplay = Display.getDisplay(this); if (mMainScreen == null) { mMainScreen = new List("AudioMIDlet", List.IMPLICIT); mMainScreen.append("Via HTTP", null); mMainScreen.append("From resource", null); mMainScreen.addCommand(new Command("Exit", Command.EXIT, 0)); mMainScreen.addCommand(new Command("Play", Command.SCREEN, 0)); mMainScreen.setCommandListener(this); } mDisplay.setCurrent(mMainScreen); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void commandAction(Command c, Displayable s) { if (c.getCommandType() == Command.EXIT) notifyDestroyed(); else { Form waitForm = new Form("Loading..."); mDisplay.setCurrent(waitForm); Thread t = new Thread(this); t.start(); } } public void run() { String selection = mMainScreen.getString( mMainScreen.getSelectedIndex()); boolean viaHttp = selection.equals("Via HTTP"); if (viaHttp) playViaHttp(); else playFromResource(); } private void playViaHttp() { try { String url = getAppProperty("AudioMIDlet-URL"); Player player = Manager.createPlayer(url); player.start(); } catch (Exception e) { showException(e); return; } mDisplay.setCurrent(mMainScreen); } private void playFromResource() { try { InputStream in = getClass().getResourceAsStream("/ringin.wav"); Player player = Manager.createPlayer(in, "audio/x-wav"); player.start(); } catch (Exception e) { showException(e); return; } mDisplay.setCurrent(mMainScreen); } private void showException(Exception e) { Alert a = new Alert("Exception", e.toString(), null, null); a.setTimeout(Alert.FOREVER); mDisplay.setCurrent(a, mMainScreen); } } you have to put ringin.wav file to your application and it must be of size less than 200kb. bye for now
|
 |
nikunj anand
Greenhorn
Joined: Apr 06, 2007
Posts: 13
|
|
hi player.addPlayerListener(this); i have just test your code. comment the above line from your code. bye for now
|
 |
Sameera Abeysekara Abeysekara
Greenhorn
Joined: Apr 10, 2007
Posts: 19
|
|
Can you application folder structure? thanks for your code sample sameera
|
 |
Sameera Abeysekara Abeysekara
Greenhorn
Joined: Apr 10, 2007
Posts: 19
|
|
sorry for above reply Can you send application folder structure? thanks for your code sample sameera
|
 |
nikunj anand
Greenhorn
Joined: Apr 06, 2007
Posts: 13
|
|
tell me your id so that i can send you whole application
|
 |
Sameera Abeysekara Abeysekara
Greenhorn
Joined: Apr 10, 2007
Posts: 19
|
|
|
what id do you want?
|
 |
Sameera Abeysekara Abeysekara
Greenhorn
Joined: Apr 10, 2007
Posts: 19
|
|
|
this is my javaranch forum id sameera83_sac
|
 |
Sameera Abeysekara Abeysekara
Greenhorn
Joined: Apr 10, 2007
Posts: 19
|
|
I need to help soon. I want to know, how can we write the url or path of media file in side the createPlayer() and how can i place the media file in side the our application. sameera
|
 |
 |
|
|
subject: Problem when palying audio
|
|
|