我正在尝试在 J2ME 中为诺基亚 SDK(S60 设备)编写代码,并且正在使用 Eclipse。
该代码尝试播放放置在项目“res”目录中的一些 wav 文件。代码如下:
InputStream in1 = null;
System.out.println("ABout to play voice:" + i);
try {
System.out.println("Getting the resource as stream.");
in1 = getClass().getResourceAsStream(getsound(i));
System.out.println("Got the resouce. Moving to get a player");
}
catch(Exception e) {
e.printStackTrace();
}
try {
player = Manager.createPlayer(in1, "audio/x-wav");
System.out.println("Created player.");
//player.realize();
//System.out.println("Realized the player.");
if(player.getState() != player.REALIZED) {
System.out.println("The player has been realized.");
player.realize();
}
player.prefetch();
System.out.println("Fetched player. Now starting to play sound.");
player.start();
in1.close();
int i1 = player.getState();
System.out.println("Player opened. Playing requested sound.");
//player.deallocate();
//System.out.println("Deallocated the player.");
}
catch(Exception e) {
e.printStackTrace();
}
}
其中 getSound 函数返回一个字符串,其中包含要播放的文件的名称。如下:
private String getSound(int i) {
switch(i) {
case 1: return "/x1.wav";
case 2: return "/x2.wav";
}
}
我的问题是这样的: 1. 当我尝试添加超过 10 个声音时,整个应用程序在调用 prefetch() 函数之前挂起。整个系统在一段时间内显着减慢。然后我必须重新启动应用程序。
我试图调试这个,但到目前为止还没有得到任何解决方案。如果我能在这方面得到一些帮助,那就太好了。