File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem when palying audio

 
Sameera Abeysekara Abeysekara
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
nikunj anand
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
player.addPlayerListener(this);

i have just test your code.
comment the above line from your code.

bye for now
 
Sameera Abeysekara Abeysekara
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you application folder structure?

thanks for your code sample

sameera
 
Sameera Abeysekara Abeysekara
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for above reply

Can you send application folder structure?

thanks for your code sample

sameera
 
nikunj anand
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tell me your id
so that i can send you whole application
 
Sameera Abeysekara Abeysekara
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what id do you want?
 
Sameera Abeysekara Abeysekara
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my javaranch forum id sameera83_sac
 
Sameera Abeysekara Abeysekara
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic