×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    4

    Red face Playing sound files from Midlet

    Hi all
    I'am having a problem in getting a midlet to play sounds in N95 there cannot be anything wrong with the midlet as it plays pefectly with a sony ericsson.

    The midlet does not even throw an exception so it must be something with the sound part of my code is listed below.

    Any help wound be appreciated.

    try {
    InputStream in = getClass().getResourceAsStream("aud.mp3");
    Player player = Manager.createPlayer(in,"audio/mpeg");
    //player.addPlayerListener(L);


    player.realize();
    player.prefetch();
    player.start();

    }
    catch (Exception e) {
    showException(e);}

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: Playing sound files from Midlet

    Hello ihatejava,

    check if this thread could be of some help (especially the post by Hartti):

    http://discussion.forum.nokia.com/fo...d.php?t=114809

    In addition, it's worth to check whether the problem appears when using other MIME types:

    http://wiki.forum.nokia.com/index.php/MMAPI

    Regards,
    r2j7

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    4

    Re: Playing sound files from Midlet

    Thanks r2j7.
    I tried the soloution that hartti suggested but it plays no sound i created an duration the midlet which shows that the file is playing.

    here is my code could someone test it to see if its just my phone, i will post this on the other thread as well.
    Thanks in advanced.

    import java.io.*;

    import javax.microedition.io.*;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.VolumeControl;


    public class AudioMIDlet
    extends MIDlet
    implements CommandListener, Runnable {
    private Display mDisplay;
    private List mMainScreen;
    private PlayerListener L;
    private Form waitForm;
    private Player player;

    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 {
    waitForm = new Form("Loading...");
    waitForm.addCommand(new Command("Exit", Command.EXIT, 0));
    waitForm.setCommandListener(this);
    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();
    while(player.getState()==player.STARTED)
    {
    String B = Long.toString(player.getMediaTime());
    waitForm.setTitle(B);


    }

    }

    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 {
    FileConnection file = (FileConnection)Connector.open("file:///E:/Music/ringtone_ this_is_why.mp3",Connector.READ);
    InputStream in = file.openInputStream();

    //InputStream in = getClass().getResourceAsStream("/aud.wav");
    player = Manager.createPlayer(in,"audio/mp3");
    //player.addPlayerListener(L);
    player.realize();

    VolumeControl vc = (VolumeControl) player.getControl("VolumeControl");
    if(vc != null)
    {
    vc.setLevel(100);
    }
    player.prefetch();

    player.start();
    String A = Long.toString(player.getDuration());
    waitForm.append(A);


    }
    catch (Exception e) {
    showException(e);
    }
    }

    private void showException(Exception e) {
    Alert a = new Alert("Exception", e.toString(), null, null);
    a.setTimeout(Alert.FOREVER);
    mDisplay.setCurrent(a, mMainScreen);
    }
    }

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    1

    Re: Playing sound files from Midlet

    I have an e50 and had the same probs.
    I could solve it by reducing the quality of my mp3-files.
    I had success with 32.000 bps, so I got mp3-files less then 1 MB.
    I did not further check what else may work.
    The e50 plays them without delay.
    YMMV so give us response
    Good luck Bernhard

  5. #5
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Playing sound files from Midlet

    Hi,
    I had also tried to play mp3 with n95 but it was played absolutely ok. here is the code which i had tried..

    public class PlayMedia extends MIDlet implements Runnable
    {
    Thread thread = new Thread(this);

    protected void startApp() throws MIDletStateChangeException {
    thread.start();
    }

    protected void pauseApp() {

    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

    }

    public void run()
    {
    try {
    // FileConnection fc = (FileConnection)Connector.open("file:///E:/jk");
    // if (!fc.exists())
    // fc.mkdir();
    // fc.close();
    InputStream is = getClass().getResourceAsStream("/Agar Tum Mil Jao.mp3");
    Player player = Manager.createPlayer(is,"audio/mp3");
    player.prefetch();
    player.realize();
    VolumeControl vc = (VolumeControl)player.getControl("VolumeControl");
    player.start();
    } catch (Exception exception) {
    }
    }

    }
    please check and do reply..

    thanks,
    jitu_goldie..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  6. #6
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: Playing sound files from Midlet

    I do not think that there could be quality problem. One significant thing about which we need to care is that our phone should not be in silent mode if it will be in silent mode if it will be then the sound will not be played.

  7. #7
    Registered User
    Join Date
    Sep 2010
    Posts
    6

    Re: Playing sound files from Midlet

    hi i have some probleme to stop music player.
    in your code you are play from rms. i wont to know that r u able to stop your player?

Similar Threads

  1. Nokia Communicator playing Default Sound
    By pmramprasath in forum Mobile Java General
    Replies: 0
    Last Post: 2007-10-25, 04:45
  2. Trojan installation onto previous trusted Midlet suite?
    By guillermoTell in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2007-05-07, 08:40
  3. Playing more audio files ? ......
    By senthilkumar05 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2006-03-03, 11:04
  4. Problem with Sound class getState()
    By creepymo in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-06-20, 18:43
  5. help with sound recording and playing
    By walterzcm in forum Mobile Java General
    Replies: 1
    Last Post: 2002-11-06, 11:42

Posting Permissions

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