×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    14

    15 second delay when playing an MP3 file

    Hi,
    I am testing a MIDlet that plays back audio on a Nokia E65. Each time I select and play a file there is at least a 15 second delay before it starts playing. On the N95 there was something like a 12 second delay.

    Anyone have an idea on how to fix this problem? It is as serious as it makes my application un-usable on Nokia phones (surely some mishhtake).

    This delay does not happen on a SonyEricsson - the track starts instantly, and also it has an option in the J2ME permissions for local access "Never Ask", so that it can automatically play each song in a playlist.

    This isn't so on any Nokia I have tested. Suggestions please... thanks.
    Ronan.

    [BTW: my first post].

  2. #2
    Registered User
    Join Date
    Aug 2007
    Posts
    14

    Unhappy Re: 15 second delay when playing an MP3 file

    Actually latest test with a stopwatch and it took 34 seconds for the file to start playing (with no sound). This should be instantaneous.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    14

    Re: 15 second delay when playing an MP3 file

    Just checking the Nokia docs on MMAPI and the demo. It doesn't sound either, so it must be some phone Java setting causing a problem.

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    14

    Re: 15 second delay when playing an MP3 file

    To clarify the problem, some code always helps...


    void createPlayer() {
    try {
    FileConnection file = (FileConnection)Connector.open(fileprefix + fileName, Connector.READ);

    InputStream is = file.openInputStream();
    player = Manager.createPlayer(is,"audio/mpeg");
    player.realize();
    player.prefetch();
    player.setLoopCount(1);

    } catch (Exception ex) {

    Alert alert = new Alert("Warning", "Cannot create player for " + fileName, null, null);
    alert.setTimeout(1000);
    parentDisplay.setCurrent(alert);
    }
    }

    So this code works fine on a SonyEricsson, but on all Nokia phones, there is a large delay (12-36 seconds) to open the file.

    Is there any way to fix this? Because to have nice player app you cannot expect the user to wait 30 seconds to open each mp3 file - it makes the app unusable.

    Surely there is a way to get this to work better.

  5. #5
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: 15 second delay when playing an MP3 file

    Have you tried to use open the file using the file locator and not using InputStream? In the Java ME developer's guide it is stated, that
    "For non-streamable media, the whole content is loaded into a buffer when a player is created using InputStream or using the HTTP or HTTPS protocols. When a player is created using ‘file’ or the RTSP protocol, the whole content is not buffered but played directly from the source."

    [Edit] Here is the link to the online Java ME Developer's Library http://www.forum.nokia.com/document/...rs_Library_v2/

    Hartti

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    2

    Re: 15 second delay when playing an MP3 file

    I've tested both on SonyEricsson and Nokia's phone on creating play with InputStream. SonyEricsson's phone can easily playing with the InputStream of a 6M mp3 file. After the player is created, just call player.start(), not prefetch(), no realize(). On Nokia's phone, both prefetch and realize are needed. From Nokia's knowledge base, Nokia's JVM will firstly read the whole file into memory and then play it, thus if the file is too large, an out-of-memory exception will come out. However, in Sony Ericsson's JVM, it seems to pass the pass the chunk of data read from InputStream directly to the native player so it doesn't need to prefetch and buffering.
    Not sure if this changes for the most updated S40 platform.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    14

    Re: 15 second delay when playing an MP3 file

    Hi, for local file playback I tested the following on Nokia E65, N80, and N95.

    player = Manager.createPlayer("file:///e:/Music/simpleFile.mp3");

    and it starts playing immediately.

    Only problem is on the Nokia E65 there is no sound. I think there must be some kind of error in the JVM on the E65, but there are no updates - I tried Nokia technical support - both by phone and in-store.

    The E65 does not play any sound even testing with the media player demo app downloaded from Nokia docs. (tones, MIDI, WAV, MP3, etc. and video). Can anyone else check a E65 to find out if it only affects my phone ?

    [I posted a message about this previously but now it is not listed...did it get deleted?]

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

    Re: 15 second delay when playing an MP3 file

    Hi ronanocie.

    i have tried a soloution similar to yours but mine does not play sound on a N95 i created a timer to show the duration left of the file being played, which shows that it is playing just that there is no sound.

    my code is listed below.

    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();
    player = Manager.createPlayer(in,"audio/mp3");
    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);
    }
    }

Similar Threads

  1. Problem in playing in an audio file.
    By PankajNeve in forum Symbian
    Replies: 3
    Last Post: 2007-03-09, 13:52
  2. playing mp3 file of size 1mb
    By karanala in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2007-02-21, 11:03
  3. How to turn a amr. file into a mp3
    By bo4590 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-08-06, 13:56
  4. How to playing MP3 file with Series 60 SDK2.1?
    By cindul in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2005-02-06, 05:30

Posting Permissions

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