使用 javax.microedition.media.Player 时应用程序崩溃并出现异常

发布于 2024-08-05 15:19:46 字数 853 浏览 4 评论 0原文

我有一个应用程序可以处理来自蓝牙的数据并将其发送到网络服务。最近有人请求向应用程序添加声音。现在,当应用程序处理批量数据并且播放器在几秒钟后不断播放时,我收到“应用程序没有响应”异常。然后进程终止。在日志中,我可以看到在此异常之后记录了许多 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2024-08-12 15:19:46

通过实现我自己的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文