j2me播放多个声音文件的问题
我在 Eclipse 中的 j2me MIDP2 中开发的游戏中播放超过 2 个声音文件时遇到问题。 请告诉我播放多个“wav”声音文件的最佳方法。 我创建了以下方法,该方法在程序启动时调用一次
public void setSound()
{
System.out.println("Sound on");
try {
p1=Manager.createPlayer(is1, "audio/X-wav");
p2=Manager.createPlayer(is2, "audio/X-wav");
p3=Manager.createPlayer(is3, "audio/X-wav");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
,每次我需要播放其中一种声音时,我都会停止其他两个播放器(以确保它们中没有一个正在运行 p2.stop(); p3 .stop();
)并启动第三个(p1.start();
),每次我有两个播放器停止(处于 PREFETCHED 状态)时,第三个播放器就不会运行并抛出异常。
I have a problem with playing more than 2 sound files in a game I'm developing now in j2me MIDP2 in eclipse.
Please advice me the best way for playing multiple "wav" sound files.
I created the following method that is called once when the program starts
public void setSound()
{
System.out.println("Sound on");
try {
p1=Manager.createPlayer(is1, "audio/X-wav");
p2=Manager.createPlayer(is2, "audio/X-wav");
p3=Manager.createPlayer(is3, "audio/X-wav");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
and every time I need to play one of the sounds I stop the two other players (to insure that no one of them is running p2.stop(); p3.stop();
) and start the third one (p1.start();
) and every time I have two players stopped (being in PREFETCHED State) the third one is not running and exceptions are thrown.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java ME 规范对此没有具体说明,但在实际设备上,您通常一次只能分配一个玩家,因此仅停止一个玩家是不够的。另请参阅此论坛帖子。我发现即使在玩新玩家之前正确地重新分配玩家也是一项挑战,因此 在我自己的代码中,我诉诸于等待一种声音结束,然后再尝试播放新的声音。
The Java ME spec is not specific about this, but on actual devices you can usually have only one allocated player at a time, so just stopping a player is not enough. See also this forum post. I found it is a challenge even to deallocate a player properly before playing a new one, so in my own code I resorted to waiting for one sound to end before trying to play a new one.
在j2me中只有一个播放器。不支持超过1个播放器。如何执行一个接一个或任何其他声音的声音。如果你想播放多个声音意味着那么你遵循下面的编码
in j2me there is only one player.More than 1 players are not supported.How execute the sound one sound after another or any other.If u want playing multiple sounds means then u follow the below coding