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());
}

Reply With Quote

