android.media.MediaPlayer 无异常崩溃
当我传递损坏的音频时, MediaPlayer 使我的应用程序冻结而不会引发异常文件到它。这是我的代码:
try
{
if (this.mediaPlayer.isPlaying())
{
this.mediaPlayer.reset();
}
this.mediaPlayer.setDataSource(this.currentSong.getFile() /* path string */);
this.mediaPlayer.prepare();
this.mediaPlayer.start();
}
catch (Exception e)
{
Log.v("Oh snap", "MediaPlayer exception: " + e.toString());
}
对此我能做什么?我需要一个例外来正确处理损坏的文件。测试设备是运行 Android 2.3.6 的 Samsung Galaxy S2,我的目标是 API 级别 8。
我不确定传递给 MediaPlayer 的损坏的 flac 文件有什么问题。我所知道的是他们也使我的应用程序和库存音乐播放器崩溃,这是不应该发生的。
The MediaPlayer makes my app freeze without throwing an exception when I pass corrupted audio files to it. Here's my code:
try
{
if (this.mediaPlayer.isPlaying())
{
this.mediaPlayer.reset();
}
this.mediaPlayer.setDataSource(this.currentSong.getFile() /* path string */);
this.mediaPlayer.prepare();
this.mediaPlayer.start();
}
catch (Exception e)
{
Log.v("Oh snap", "MediaPlayer exception: " + e.toString());
}
What can I do about this? I need an exception to handle corrupted files properly. The test device is a Samsung Galaxy S2 running Android 2.3.6 and I'm targeting API level 8.
I'm not sure what's wrong with the corrupted flac files that I'm passing to the MediaPlayer. All I know is that they crash my app and the stock music player too, which shouldn't happen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果是本机崩溃,那么仅从 Java 层您无能为力。检查这个回答,获取有关您需要进行的可怕黑客攻击的有点可怕的指南。
If it's a native crash there's very little you can do just from the Java layer. Check this answer for a slightly scary guide to the frightful hacking you'd need to do.