错误创建资产的MediaPlayer与URI或文件资产、错误、文件、MediaPlayer

由网友(欲罢不能 °)分享简介:我复制Song.mp3的到我的项目的资产目录,并写了code:I copied song.mp3 to my project's assets directory and wrote this code:private MediaPlayer mp;Uri uri = Uri.parse("file:///andr...

我复制Song.mp3的到我的项目的资产目录,并写了code:

I copied song.mp3 to my project's assets directory and wrote this code:

private MediaPlayer mp;

Uri uri = Uri.parse("file:///android_asset/song.mp3");

mp=MediaPlayer.create(this, uri);

运行create语句后,变量熔点为空。什么是错的?

After running the create statement, the variable mp is null. What is wrong?

感谢。

推荐答案

试试这个,看看是否有异常被捕获:

Try this and see if any exceptions are caught:

try {
    MediaPlayer mp = new MediaPlayer();
    mp.setDataSource(this, uri);
}
catch (NullReferenceArgument e) {
    Log.d(TAG, "NullReferenceException: " + e.getMessage());
}
catch (IllegalStateException e) {
    Log.d(TAG, "IllegalStateException: " + e.getMessage());
}
catch (IOException e) {
    Log.d(TAG, "IOException: " + e.getMessage());
}
catch (IllegalArgumentException e) {
    Log.d(TAG, "IllegalArgumentException: " + e.getMessage());
}
catch (SecurityException e) {
    Log.d(TAG, "SecurityException: " + e.getMessage());
}

者将解释该异常是怎么回事错在你的创作。据在该文档中,静态create方法就是简写是什么在try块以上。我可以看到的主要区别是,静态方法来创建,而确实的setDataSource不会抛出。

The exception caught will explain what is going wrong in your create. According the the docs, the static create method is just shorthand for what is in the try block above. The major difference that I can see is that the static method create doesn't throw while setDataSource does.

阅读全文

相关推荐

最新文章