You Are Here:

Community: Developer Discussion Boards

#1 Old Playing an MP3 twice error - 2007-10-05, 12:39

Join Date: Oct 2007
Posts: 10
jet-lee
Offline
Registered User
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

#2 Old Re: Playing an MP3 twice error - 2007-10-09, 13:09

Join Date: Oct 2007
Posts: 9
borje.granberg
Offline
Registered User
Try to add "fc.close();" before the first "p.close();"
Reply With Quote

#3 Old Re: Playing an MP3 twice error - 2007-10-10, 05:57

Join Date: Feb 2006
Posts: 689
soku123
Offline
Super Contributor
Hi,
If(p.getMediaTime() == p.getDuration()){

p.setMediaTime(0);
}

check whether this works.....

Thanks
Soku
Reply With Quote

#4 Old Re: Playing an MP3 twice error - 2007-10-10, 08:27

Join Date: Oct 2007
Posts: 10
jet-lee
Offline
Registered User
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
Reply With Quote

#5 Old Re: Playing an MP3 twice error - 2007-10-11, 16:49

Join Date: Oct 2007
Posts: 10
jet-lee
Offline
Registered User
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
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
please help cell id perthachy General Symbian C++ 12 2007-07-10 14:14
Carbide.vs 2.01 Registration Problem baykal Symbian Tools & SDKs 5 2006-12-22 17:55
problem with the XML Parser SyExpat Vitaly_iva General Symbian C++ 2 2006-06-05 12:09
User break point error in Grid ag24master Symbian User Interface 0 2003-08-07 09:20
Building pacman2000z Symbian Tools & SDKs 0 2003-07-17 11:44

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ