如何使用Android的NDK访问资源(如声音,图像等),直接从本地code? [英] How to access resources (like sound, images etc) directly from native code using Android-NDK?

查看:659
本文介绍了如何使用Android的NDK访问资源(如声音,图像等),直接从本地code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么可以直接访问资源,如图像,声音文件等,从本地code,即C ++文件。其实我在寻找任何实际的例子,可以帮助我使用asset_manager_jni.h方法。

I want to know that how can I directly access the resources like images, sound files etc. from native code i.e. C++ files. Actually I am looking for any example that could help me to use the asset_manager_jni.h methods.

寻找建议。先谢谢了。

与问候,

阿图尔·普拉卡什·辛格

Atul Prakash Singh

推荐答案

那么,你有机会获得stdio.h之外。所以,如果它在一个已知的地方(比如在SD卡上),你可以使用它作为一个路径。还有的教程很多就有关净热水使用标准输入输出(FOPEN,FCLOSE等)。

Well, you have access to stdio.h. So if it's in a known place (say on the SD card), you can just use that as a path. And there's lot's of tutorials on the net about hot to use stdio (fopen, fclose, etc).

问题是,你的资源捆绑到APK本身(无论是在RES /生,或资产),留在里面的apk安装完成后。更糟糕的是,默认情况下,他们将COM pressed这使得阅读这本书并不可行。这是可以避免的,而最简单的方法是重命名该资产有.MP3扩展名(或者还有其他人)。这样做的原因是,因为默认的.mp3不是玉米pressed,不管它是否实际上是一个MP3文件)。还有一些其他的扩展,您可以使用,以及如何告诉并不是工具COM preSS您的数据,如果你不喜欢在年底以.mp3命名您的所有资产。

The issue is that resources you bundle into the apk itself (either in res/raw, or assets), stay inside the apk after install. What's worse is that by default, they will be compressed which makes reading it not feasible. This can be avoided, and the easiest way is to rename the asset to have the .mp3 extension (or there are others). The reason for this is because by default, .mp3 is not compressed, regardless of whether or not it actually is an mp3 file). There are other extensions you can use, and ways to tell the tools not to compress your data if you don't like naming all of your assets with .mp3 at the end.

所以,你有几种选择在这里:

So, you have a few choices here:


  1. 下载从网上的资源,你的第一个跑,把它们放在一个不显眼的地方(这可能是最好的时候,你做的下载来获取路径从SDK),并使用它。

  1. Download your resources from the net on your first run, put them in an unobtrusive place (it's probably best to get that path from the sdk when you do the downloading), and use that.

在APK存储您的资源(记得.MP3扩展,在资产的文件夹)。在你第一次运行,提取的资产,你可以使用一个文件夹(不骚扰用户),并从那里使用的资源。

Store your resources in the apk (remember the .mp3 extension, in the assets folder). On your first run, extract the assets to a folder you have access to (and doesn't annoy the user), and use the resources from there.

(我做什么)的APK(.MP3再次)存储您的资源,并使用JNI直接从APK阅读。是的,JNI是有点慢,但你不应该从文件系统在性能临界点读所有的东西反正,肯定不会。 Nvidea有一些非常有用的code你可以使用,你可以在这里找到: http://developer.nvidia.com/tegra -resources ,它在样品code,如果我还记得。里面的libs文件夹是您可以使用一些很好的通用库匹配标准输入输出,但它也从APK本身读取。

(what I do) Store your resources in the apk (.mp3 again), and use the jni to read directly from the apk. Yes, the jni is a bit slow, but you shouldn't be reading from the file system all that much anyway, and certainly not at a performance critical point. Nvidea has some very helpful code you can use, you can find it here: http://developer.nvidia.com/tegra-resources , it's in the sample code if I remember. Inside the libs folder is some good general purpose libraries you can use that matches stdio, except it also reads from the apk itself.

希望它帮助。

这篇关于如何使用Android的NDK访问资源(如声音,图像等),直接从本地code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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