×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    10

    Playing an MP3 twice error

    Hello all .. let me start by saying that I am brand new to Java so the code may not be the tightest, its a bit crude, but it was the quickest way I could write the code to reporoduce the problem.

    The code represents playing a clip in Java ME twice (I know that i can use the loop functionality to play 1 file twice .. but this illistrates the problem that I need to fix) its the same clip .. but this this problem is duplicated when playing trying to play any clip a second time .. even if 3 clips where played straight after it and then we try to play the first clip again...

    for some reason the code works perfectly on a Sony Ericsson m600i .. but running it in the N95 Emulator and on an actual device produce the same result ...

    Expected Result when running this code : An mp3 placed on the phone will play itself to the end and then play itself again ..

    Current Result : The mp3 plays once .. then generates a "File is used by other application " IOException

    Current Efforts to correct : have tried setting the player and fileconnection to null have tried to load a different clip and then revert back. have tried combinations of preverify,prefetch,stop,close but still NO JOY..

    below is the code .. perhaps somebody can tell me how to correct this ....

    HEADERS :

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.io.file.*;
    import javax.microedition.media.*;


    CODE:
    try{
    FileConnection fc = (FileConnection)Connector.open("path to file");
    Player p = Manager.createPlayer
    (fc.openInputStream),"audio/mpeg");
    p.start();

    while (p.getMediaTime() < p.getDuration()){
    }

    p.close();

    fc = (FileConnection)Connector.open("path to file");
    p = Manager.createPlayer(fc.openInputStream(),"audio/mpeg");
    p.start();

    while (p.getMediaTime() < p.getDuration()){
    }
    fc.close();
    p.close();
    }

    catch (IOException ioe) {
    System.out.println(ioe.getMessage());
    }
    catch (MediaException ME){
    System.out.println(ME.getMessage());
    }

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    9

    Re: Playing an MP3 twice error

    Try to add "fc.close();" before the first "p.close();"

  3. #3
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: Playing an MP3 twice error

    Hi,
    If(p.getMediaTime() == p.getDuration()){

    p.setMediaTime(0);
    }

    check whether this works.....

    Thanks
    Soku

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    10

    Re: Playing an MP3 twice error

    Thanks for the help guys.. have managed to fix the problem .. but it doesnt seem to get to the root cause. The problem seems to stem from the fileconnection class and not from the player.. if instead of using the fileconnection we just use the path to the file in the createplayer statement, it works perfectly.

    Will implement the fixes you suggested so that perhaps we can isolate the problem and in so doing help someone else who actually has to do it with a fileconnection.

    Thanks again

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    10

    Re: Playing an MP3 twice error

    Finally understand why this was happening ... when the player is instantiated i use a fc.openInputStream() ... what needs to happen is the inputstream needs to close to release all file resources .. so a better practice would be like this

    InputStream is = fc.openInputStream();

    and then when finished

    fc.close();
    is.close();

    Thanks for the input guys ... much appreciated

Similar Threads

  1. please help cell id
    By perthachy in forum Symbian
    Replies: 12
    Last Post: 2007-07-10, 13:14
  2. Carbide.vs 2.01 Registration Problem
    By baykal in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2006-12-22, 16:55
  3. problem with the XML Parser SyExpat
    By Vitaly_iva in forum Symbian
    Replies: 2
    Last Post: 2006-06-05, 11:09
  4. User break point error in Grid
    By ag24master in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-08-07, 08:20
  5. Building
    By pacman2000z in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2003-07-17, 10:44

Posting Permissions

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