android - how to get path of mp3 stored in raw folder

耗尽温柔 提交于 2019-12-12 06:38:39

问题


After searching for solution, I have found from this link that it is possible to retrieve path like:

Using Resource Id

Syntax : android.resource://[package]/[resource_id]

Example : Uri.parse("android.resource://com.my.package/" + R.raw.mp3filename);

Which is exactly what I want. Problem is that, I'm using lolipop, and it does not work. When the package/resource is parsed, path from Uri.parse will be null. Is there other way around to write this, since in my Song class, I have only access to resourceId (R.raw.mp3filename).


回答1:


Is it possible to get file path by using R.raw.mp3file

No, because it is not a file on the device. It is a file on the hard drive of your development machine. On the device, it is merely an entry in an APK file.

Either:

  • Do whatever you are trying to do some other way that does not involve a file path, or

  • Use openInputStream() on a Resources object (you can get one from any Context via getResources()), and use Java I/O to copy the contents of that resource to a local file, such as on internal storage



来源:https://stackoverflow.com/questions/36816944/android-how-to-get-path-of-mp3-stored-in-raw-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!