Why will repeatedly play music when no sound it? There is the code.

Category: J2ME
 
xuli0812
2012-03-24 08:25:07

Sponsored Links
Even if only PlayMusic should have cleared before play ah.

public class SoundTool {

private static Player PLAYER = null;

public static synchronized String PlayMusic (InputStream IS)
{
if (IS == null) return "Null InputStream";
String sRet = "";
if (PLAYER! = null) sRet = StopMusic ();
try {
if (PLAYER! = null) sRet + = "<br> Still not null" ;;
PLAYER = Manager.createPlayer (IS, "audio / midi");
PLAYER.realize ();
; PLAYER.prefetch ();
PLAYER.start ();
} catch (Exception e)
; {
StopMusic ();
PLAYER = null;
System.out.println ("1:" + e.getMessage ());
sRet + = "<br> 1:" + e.getMessage ();
}
return sRet;

}

public static synchronized String PlayMusic (String URL)
{
String sRet = "";
try {
NetWorkTool.getViaHttpConnection (URL, NetWorkTool.IP);
InputStream IS = new ByteArrayInputStream (NetWorkTool.baBuffer);
sRet = PlayMusic (IS);
} catch (Exception e)
{
StopMusic ();
PLAYER = null;
System.out.println ("2: "+ e.getMessage ());
sRet + =" <br> 2: "+ e.getMessage ();
}
return sRet;
}

public static synchronized String StopMusic ()
{
if (PLAYER == null) return "" ;;
try {
if (PLAYER.getState () == Player.STARTED) PLAYER.stop ();
if (PLAYER.getState () == Player . PREFETCHED | | PLAYER.getState () == Player.REALIZED) PLAYER.deallocate ();
PLAYER.close ();
PLAYER = null;
System. gc ();
return "";
} catch (Exception e) {
/ / TODO Auto-generated catch block
System.out.println ("3:" + e.getMessage ());
PLAYER.close ();
PLAYER = null;
System.gc () ;
return "<br> 3:" + e.getMessage ();
}

}

}

Sponsored Links

yxstone
2012-03-24 08:35:35
your import statement it?
fewer classes. I can not debug ah. . .
cpjboy
2012-03-24 08:44:20
NetWorkTool.getViaHttpConnection (URL, NetWorkTool.IP);
InputStream IS = new ByteArrayInputStream (NetWorkTool.baBuffer);
Which replaced by the following, try:
InputStream is = this.getClass (). getResourceAsStream (". / res / nhd.mid");
huhufam
2012-03-24 08:53:13
have write some phones you can use CLOSE To use these two functions to stop you shield a try it?
ddfveihi
2012-03-24 09:12:08
Many models do not support multiple voice, to put a voice to the other voices stopped, and release the resources occupied by him. So as to lay down a sound.

----------------
""
-------- --------
java, j2me, delphi, asp.net, C #
hahaha_2010
2012-03-24 09:50:47
jmf people recently with a lot of ah, up about
asdffgh
2012-03-24 10:28:29
jmf what ?
andgn
2012-03-24 10:43:49
code read, but do not understand. Oh.
zgw217
2012-03-24 11:14:31
jmf what?
mymymymy0006
2012-03-24 11:34:38
I am also a novice, learning ...
marvin_s414
2012-03-25 12:10:22
Halo also import
import javax.microedition.media. *;

import java.io. *;
import java.io.ByteArrayInputStream;
ly1976427
2012-03-25 12:38:29
because resources are not local, are obtained on the Internet
You mean change Cost of land resources to try?
hezhoujing001
2012-03-25 01:12:56
If an error occurs, then null is not abnormal capture settings you should have no problem?
mkinju
2012-03-25 01:38:23
mark + xuexi
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.