Reputation:
i am developing one j2me application to play wav & mp3 file.
problems are:
few lines of my code is here.
Code to play Wav file
InputStream is = getClass().getResourceAsStream("/Child.wav");
player = Manager.createPlayer(is, "audio/x-wav");
player.realize(); player.start();
Code to play MP3 file
InputStream is = getClass().getResourceAsStream("/Child.mp3");<br/>
player = Manager.createPlayer(is, "audio/mpeg");
player.realize(); player.start();
Please let me know what is the problem in my code.
Upvotes: 2
Views: 1165
Reputation: 1
The most accurate source for Nokia Series 40 without throwing an exception (Out of Memory error) by launching directly from the SD mp3 files and other such files to allow the phone is:
import java.io.IOException;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.midlet.MIDlet;
public class pro extends MIDlet {
public pro() throws IOException, MediaException {
Player player = Manager.createPlayer("file:///E:/03.mp3");
player.realize();
player.start();
}
public void startApp() { }
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}
Upvotes: 0
Reputation: 5110
According to me, your code is correct.
I was getting "Sounds not allowed" error because the phone was in silent mode and i was trying to play it. Are u sure tht ur phone is not in silent mode while running your code?
Upvotes: 0
Reputation: 6826
You might want to try "audio/wav" instead of "audio/x-wav".
I would also suggest using a FileConnection URL (Manager.createPlayer("file://localhost/E:/MyFolder/Child.mp3");
for example) as that typically works better than Players created with an InputStream on Series40 phones.
Upvotes: 1
Reputation: 7406
Does it make any difference if you call player.prefetch();
before player.start();
? All the examples I have seen previously are done this way.
Also try using the mime type audio/mp3
instead if audio/mpeg
doesn't work.
Upvotes: 0