×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Sep 2010
    Location
    India
    Posts
    61

    Exclamation Getting Error in Playing Mp3 File

    Hello,

    i am trying to Play MP3 and getting unexpected errors.
    I have tested my app before 3 days which was working perfect on my device
    but now even that same jar file is giving me following error.

    javax.microedition.midlet.MediaException:Sounds not allowed

    error is coming when it executes this line
    player.prefetch();

    i am testing this app on Nokia 5200 and Nokia 5130

    what could be problem?
    Please guide me.
    Following is my code.





    public class PlayAudioMidlet extends MIDlet {

    private Display display;
    AudioPlayer ap;

    public void startApp() {

    display = Display.getDisplay(this);
    ap = new AudioPlayer(this, display);
    display.setCurrent(ap); // display a subclass of Form named as AudioPlayer
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }
    }

    class AudioPlayer extends Form
    implements CommandListener, PlayerListener {

    PlayAudioMidlet midlet;
    private Display display;
    private Command play, stop, exit, forward, backward;
    private Player player;

    public AudioPlayer(PlayAudioMidlet midlet, Display display) {

    super("");
    this.midlet = midlet;
    this.display = Display.getDisplay(midlet);

    play = new Command("Play", Command.OK, 0);
    stop = new Command("Stop", Command.STOP, 0);
    exit = new Command("Exit", Command.EXIT, 0);

    addCommand(play);
    addCommand(stop);
    addCommand(forward);
    addCommand(backward);
    addCommand(exit);

    setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {

    if (c == play) {
    try {
    //System.out.println(System.currentTimeMillis());
    playAudio();
    } catch (Exception e) {
    e.printStackTrace();
    }
    } else if (c == stop) {
    player.close();
    }
    }

    public void playerUpdate(Player player, String event, Object eventData) {
    }

    public void playAudio() {
    int i = 0;
    try {
    //Even this commented line doesn't work
    //player = Manager.createPlayer(getClass().getResourceAsStream("/res/alert.mp3"), "audio/mpeg");
    player = Manager.createPlayer("file:///E:/Sound/alert1.mp3");

    player.addPlayerListener(this);
    // player.setLoopCount(-1);
    player.prefetch();
    player.realize();
    player.start();
    } catch (Exception e) {
    Alert a = new Alert("");
    a.setString("Error "+e.toString());
    a.setTimeout(Alert.FOREVER);
    display.setCurrent(a);

    }
    }
    }

  2. #2
    Regular Contributor
    Join Date
    Mar 2011
    Location
    Pune,Maharashtra,India
    Posts
    92

    Re: Getting Error in Playing Mp3 File

    Quote Originally Posted by mihirp View Post
    Hello,

    i am trying to Play MP3 and getting unexpected errors.
    I have tested my app before 3 days which was working perfect on my device
    but now even that same jar file is giving me following error.

    javax.microedition.midlet.MediaException:Sounds not allowed

    error is coming when it executes this line
    player.prefetch();

    i am testing this app on Nokia 5200 and Nokia 5130

    what could be problem?
    Please guide me.
    Following is my code.





    public class PlayAudioMidlet extends MIDlet {

    private Display display;
    AudioPlayer ap;

    public void startApp() {

    display = Display.getDisplay(this);
    ap = new AudioPlayer(this, display);
    display.setCurrent(ap); // display a subclass of Form named as AudioPlayer
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    notifyDestroyed();
    }
    }

    class AudioPlayer extends Form
    implements CommandListener, PlayerListener {

    PlayAudioMidlet midlet;
    private Display display;
    private Command play, stop, exit, forward, backward;
    private Player player;

    public AudioPlayer(PlayAudioMidlet midlet, Display display) {

    super("");
    this.midlet = midlet;
    this.display = Display.getDisplay(midlet);

    play = new Command("Play", Command.OK, 0);
    stop = new Command("Stop", Command.STOP, 0);
    exit = new Command("Exit", Command.EXIT, 0);

    addCommand(play);
    addCommand(stop);
    addCommand(forward);
    addCommand(backward);
    addCommand(exit);

    setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {

    if (c == play) {
    try {
    //System.out.println(System.currentTimeMillis());
    playAudio();
    } catch (Exception e) {
    e.printStackTrace();
    }
    } else if (c == stop) {
    player.close();
    }
    }

    public void playerUpdate(Player player, String event, Object eventData) {
    }

    public void playAudio() {
    int i = 0;
    try {
    //Even this commented line doesn't work
    //player = Manager.createPlayer(getClass().getResourceAsStream("/res/alert.mp3"), "audio/mpeg");
    player = Manager.createPlayer("file:///E:/Sound/alert1.mp3");

    player.addPlayerListener(this);
    // player.setLoopCount(-1);
    player.prefetch();
    player.realize();
    player.start();
    } catch (Exception e) {
    Alert a = new Alert("");
    a.setString("Error "+e.toString());
    a.setTimeout(Alert.FOREVER);
    display.setCurrent(a);

    }
    }
    }
    Have you putted your phone on silent mode and trying to play audio files?
    Regards,
    Pradip

Similar Threads

  1. RTSP Streaming error: error preparing video for playing
    By elshorbagy76 in forum Streaming and Video
    Replies: 0
    Last Post: 2010-09-14, 23:30
  2. RTSP Streaming error: error preparing video for playing
    By elshorbagy76 in forum [Archived] Flash Lite on Nokia Devices
    Replies: 0
    Last Post: 2010-09-13, 21:30
  3. Problem playing tones after playing a sound file
    By mattbrenner in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2010-08-18, 05:35
  4. Replies: 1
    Last Post: 2009-08-06, 05:12
  5. Playing 3GP video file in local file system.
    By media999 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2006-09-14, 07:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×