使用 javax.microedition.media.Player 时应用程序崩溃并出现异常
我有一个应用程序可以处理来自蓝牙的数据并将其发送到网络服务。最近有人请求向应用程序添加声音。现在,当应用程序处理批量数据并且播放器在几秒钟后不断播放时,我收到“应用程序没有响应”异常。然后进程终止。在日志中,我可以看到在此异常之后记录了许多 ForcedStackTrace 异常。
声音在单独的线程中播放。如果应用程序不播放声音或播放短声音 - 一切正常。有什么办法可以避免这种异常的发生吗?为什么会发生这种情况?
InputStream mediaStream = null;
try {
mediaStream = getClass().getResourceAsStream(relativePath);
getLogger().log("setting player _ " + _audioType);
setPlayer(Manager.createPlayer(mediaStream, _audioType));
_currentPlayer.addPlayerListener(this);
_currentPlayer.setLoopCount(1);
_currentPlayer.realize();
VolumeControl vc = (VolumeControl) _currentPlayer
.getControl("VolumeControl");
if (vc != null) {
vc.setLevel(_voumeLevel);
}
_currentPlayer.prefetch();
_currentPlayer.start();
} catch (Exception e) {
}
(从 BB 论坛交叉发布)
I have an application that processes data from bluetooth and send it to the web service. Recently there was a request to add sounds to the application. Now when the application processes batches of data and the player is playing constantly after a few secs I get "Application is not responding" exception. And then the process is terminated. In the logs I can see lots of ForcedStackTrace exception logged after this exception.
The sounds are played in the separate thread. If app doesn't play sounds or plays short sounds - everything works fine. Is there any way to avoid this exception happening? Why is it happening?
InputStream mediaStream = null;
try {
mediaStream = getClass().getResourceAsStream(relativePath);
getLogger().log("setting player _ " + _audioType);
setPlayer(Manager.createPlayer(mediaStream, _audioType));
_currentPlayer.addPlayerListener(this);
_currentPlayer.setLoopCount(1);
_currentPlayer.realize();
VolumeControl vc = (VolumeControl) _currentPlayer
.getControl("VolumeControl");
if (vc != null) {
vc.setLevel(_voumeLevel);
}
_currentPlayer.prefetch();
_currentPlayer.start();
} catch (Exception e) {
}
(crossposted from BB forums)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过实现我自己的 PlayerManager 来解决,它在单独的线程中运行将以队列方式播放项目,而不是使用内部 Player 实现有许多线程。
Resolved by implementing my own PlayerManager, which, running in a separate thread would play the item in the queue manner rather then having many threads using the inner Player implementation.