亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述Android MediaScannerJNI源代码具体解释相关的知识,希望能为你提供帮助。
1.简单介绍MediaScannerJNI的在MediaScanner中的地位可參考
Android MediaScanner 总纲
MediaScanner JNI文件名称:
android_media_MediaScanner.cpp
位置:
frameworks\base\media\jni\android_media_MediaScanner.cpp
android_media_MediaScanner是java层和server层沟通的一个桥梁
文章图片
android_media_MediaScanner中有一个MyMediaScannerClient是一个调用JAVA层android/media/MediaScannerClient的入口是Native层想java层通信的桥梁。
static {
System.loadLibrary("media_jni");
native_init();
}
public MediaScanner(Context c) {
native_setup();
......
}
native_init 相应 android_media_MediaScanner_native_init
native_setup相应android_media_MediaScanner_native_setup
static void
android_media_MediaScanner_native_setup(JNIEnv *env, jobject thiz)
{
ALOGV("native_setup");
MediaScanner *mp = new StagefrightMediaScanner;
......
env->
SetLongField(thiz, fields.context, (jlong)mp);
}
3. android_media_MediaScanner_processDirectory调用MediaScanner.cpp实现processDirectory完毕工作
在MediaScanner.java中调用scanDirectories。详见Android MediaScanner源码解析 第6节
其功能还是通过MediaScanner.cpp的processDirectory实现对
static void
android_media_MediaScanner_processDirectory(
JNIEnv *env, jobject thiz, jstring path, jobject client)
{
MediaScanner *mp = getNativeScanner_l(env, thiz);
.......
const char *pathStr = env->
GetStringUTFChars(path, NULL);
MyMediaScannerClient myClient(env, client);
MediaScanResult result = mp->
processDirectory(pathStr, myClient);
env->
ReleaseStringUTFChars(path, pathStr);
}
4. android_media_MediaScanner_processFile调用StageFrightMediaScanner.cpp实现processFile完毕工作
static void
android_media_MediaScanner_processFile(
JNIEnv *env, jobject thiz, jstring path,
jstring mimeType, jobject client)
{
// Lock already hold by processDirectory
MediaScanner *mp = getNativeScanner_l(env, thiz);
const char *pathStr = env->
GetStringUTFChars(path, NULL);
const char *mimeTypeStr =
(mimeType ?
【Android MediaScannerJNI源代码具体解释】 env->
GetStringUTFChars(mimeType, NULL) : NULL);
........
MyMediaScannerClient myClient(env, client);
MediaScanResult result = mp->
processFile(pathStr, mimeTypeStr, myClient);
}
5. MyMediaScannerClient引用android/media/MediaScannerClient中scanFile。handleStringTag。 setMimeType三个接口
jclass mediaScannerClientInterface =
env->
FindClass(kClassMediaScannerClient);
if (mediaScannerClientInterface == NULL) {
ALOGE("Class %s not found", kClassMediaScannerClient);
} else {
mScanFileMethodID = env->
GetMethodID(
mediaScannerClientInterface,
"scanFile",
"(Ljava/lang/String;
JJZZ)V");
mHandleStringTagMethodID = env->
GetMethodID(
mediaScannerClientInterface,
"handleStringTag",
"(Ljava/lang/String;
Ljava/lang/String;
)V");
mSetMimeTypeMethodID = env->
GetMethodID(
mediaScannerClientInterface,
"setMimeType",
"(Ljava/lang/String;
)V");
}
推荐阅读
- swiper实现臭美app滑动效果
- Android玩转百度地图Sha1获取正确姿势()
- android studio adb.exe已停止工作
- 从零開始学android<AnalogClock与DigitalClock时钟组件.三十一.>
- Ionic App 启动时报Application Error - The connection to the server was unsuccessful
- 一步步配置cordova android开发环境
- android打开 res raw目录 中 数据库文件
- android 单位什么是屏幕密度()
- Android自动化测试-UiAutomator环境搭建