Archived

This topic is now archived and is closed to further replies.

rizwanahmed24

[java] how to replay sound after stopping it in MIDP2.0

Recommended Posts

INputStream object can be made/initialize and use in a same function. However if I initialize it in constructor and use it in any other function , then pause it and play some other sound file in same way. Now when I want to play 1st audio file which was initialized in costructor, it gives exceptions. Can you tell me what could be the problem? From programing point of view it is as: ----- This will work perfectly: class AudioTest extends MIDlet implements runnable { AudioTest(){ } PlaySound(){ InputSTream is1, is2; Player p; is1 = Initialize it with sound file which we will play is2 = Initialize it with sound file which we will play p.play(is1); //will play sound 1 p.pause(); //pause sound file p.play(is2); //will play sound 2 p.pause(); //pause sound is1 = Initialize it with sound file which we will play is2 = Initialize it with sound file which we will play p.play(is1); //will play sound 1 p.pause(); //pause sound file p.play(is2); //will play sound 2 p.pause(); //pause sound file } } ----- This code donot work as stated in probblem statement class AudioTest extends MIDlet implements runnable { public InputSTream is1, is2; public Player p; AudioTest(){ is1 = Initialize it with sound file which we will play is2 = Initialize it with sound file which we will play } PlaySound(){ p.play(is1); //will play sound 1 p.pause(); //pause sound file p.play(is2); //will play sound 2 p.pause(); //pause sound p.play(is1); //will not play sound 1, but generate exceptions p.pause(); //pause sound file p.play(is2); //will not play sound 2, but generate exceptions p.pause(); //pause sound file } } //----------------------------------------------------------------------------------------------------------- Detailed problem in form of code can be obtained from http://geocities.com/umer_jawaid/myApplication.zip //----------------------------------------------------------------------------------------------------------- I think problem is that InputSTream object is1 is set to null automatically after Player object is paused or any other sound is played. PLease tell me what could be the problem from your point of view?

Share this post


Link to post
Share on other sites
The InputStream isn''t set to null when the player is paused.
What''s happening is that after you use it once, the "pointer" of the InputStream is at the end of the stream.
In theory you could use mark() and reset() to "rewind" the InputStream. But those methods are flaky to say the least, and I haven''t tried this out, so I can''t guarantee that it''ll work. If it doesn''t, then you''ll have to recreate the InputStream every time.

shmoove

Share this post


Link to post
Share on other sites
Thank you very much for your reply and answer. The problem was the same one, i.e. I wasnt resetting InputStream after once played. Now its working very fine.

Share this post


Link to post
Share on other sites