Android的MediaPlayer的错误(1,-2147483648)播放MP3时,当地 [英] Android MediaPlayer Error(1, -2147483648) when playing an mp3 locally

查看:3165
本文介绍了Android的MediaPlayer的错误(1,-2147483648)播放MP3时,当地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

后不久的Andr​​oid 4.4出来了我的code已正常工作,因为2.2突然灭车。

Shortly after Android 4.4 came out my code which has been working correctly since 2.2 suddenly went buggy.

我的code将查询音乐数据库对于给定的音乐文件。路径返回的查询,然后这条路径被传递到的MediaPlayer

My code will query the music database for a given music file. The path is returned in the query and this path is then passed onto the MediaPlayer.

code:

String uri = "content://media/internal/audio/media";
String[] columns = [audio_id as _id, title, album, artist, album_id, _data];
String where = "album = 'XX'";
Cursor c = this.getContentResolver().query(uri, columns, where, null, MediaColumns.TITLE);
String musicPath = c.getString(5);
// musicPath is "/storage/emulated/0/Music/The XX/Islands.mp3"

player.reset();
player.setDataSource(musicPath);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.prepareAsync();

我结束了无用的错误(1,-2147483648)消息在我的LogCat中。

I end up with the useless Error(1, -2147483648) message in my LogCat.

我也尝试更换

player.setDataSource(musicPath);

FileInputStream fileInputStream = new FileInputStream(musicPath);
player.setDataSource(fileInputStream.getFD());
fileInputStream.close();

但是,这产生的新的FileInputStream(...)出现FileNotFoundException:

But this produces a FileNotFoundException on the new FileInputStream(...):

java.io.FileNotFoundException:/存储/模拟/ 0 /音乐/的xx / Islands.mp3:打开失败:EACCES(拒绝)

这是有趣的,因为由查询返回的路径开头/存储/模拟/ ...但如果我看在Eclipse中的DDMS视图中的实际路径是到/ mnt /壳/模拟/ ... 。这正常吗?

This is interesting because the path returned by the query begins with "/storage/emulated/..." but if I look in the DDMS view in Eclipse the actual path is "/mnt/shell/emulated/...". Is this normal?

尽管如此,如果我改变路径preFIX手动我在文件浏览器看,我仍然可以在新的FileInputStream(...)出现FileNotFoundException:

Despite that, if I change the path prefix manually to what I see in the file explorer, I still get a FileNotFoundException on the new FileInputStream(...):

java.io.FileNotFoundException:到/ mnt /壳/模拟/ 0 /音乐/的xx / Islands.mp3:打开失败:EACCES(拒绝)

同样的异常。这有什么权限被拒绝的公司吗?直到奇巧这是工作的罚款。我还因为添加了权限:

Same exception. What is with this Permission denied business? Up until KitKat it was working fine. I've also since added the permission :

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

我的应用程序在清单这一行:

My app has this line in the manifest:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />

有没有人看起来类似的东西,并找到了解决这个未知的错误?我试图在播放音乐和其他音乐播放器应用程序来播放做工精细的MP3音乐,因此导致我相信这个问题是不是缺少codeC。

Has anybody seem something similar and found a solution to this unknown error? The mp3s that I am trying to play work fine in Play Music and another music player app, thus leading me to believe the problem is not a missing codec.

谢谢
肖恩

编辑:
我如果文件存在内容查询后立即检查和返回的路径没有。

I've checked immediately after the content query if the file exists and the path returned does not.

File f = new File(musicPath);
boolean exists = f.exists();  // false

这怎么可能?我试着查询内部媒体代替,但返回任何结果(如预期)

How is this possible? I've tried querying internal media instead but that returns no results (as expected)

推荐答案

我解决这个得到了与添加写权限的应用程序的(不幸的)解决方案。

I got around this with the (unfortunate) solution of adding a write permission to the app.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

显然,这是从4.4起必要的。任何人都可以证实或否认这一点?

Apparently this is necessary from 4.4 onward. Can anybody confirm or deny this?

肖恩

这篇关于Android的MediaPlayer的错误(1,-2147483648)播放MP3时,当地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆