我正在尝试从服务器流式传输音频内容(AAC)。播放器启动没有任何问题,一段时间后抛出 OutOfMemoryError。我想我需要缓冲音频。任何人请指导我实现(或摆脱此错误)缓冲。
这是我的代码。
`HttpConnection c = null;
InputStream is = null;
try {
c = (HttpConnection) Connector.open(streamURL,
Connector.READ_WRITE);
int rc = c.getResponseCode();
System.out.println("Response Code " + rc);
if (rc != HttpConnection.HTTP_OK) {
showAlert("Server error returned");
} else {
playerForm.append("openInputStream");
is = c.openInputStream();
player = Manager.createPlayer(is, "audio/aac");
player.realize();
// get volume control for player and set volume to max
VolumeControl vc = (VolumeControl) player.getControl("VolumeControl");
if(vc != null)
{
vc.setLevel(100);
}
player.prefetch();
player.start();
}
} catch (Exception f) {
playerForm.append("Exception in player " + f.getMessage() + "n");
} finally { // Aufräumarbeiten ausführen
if (is != null)
try {
is.close();
} catch (IOException e) {
}
if (c != null)
try {
c.close();
} catch (IOException e) {
}
}`
提前谢谢。
问候阿尼什。
而不是 catch 中的异常,只需使用 Throwable 类,它将处理 OutOfMemoryError