1. Introduction
The position of Mediascannerjni in Mediascanner can be referenced
Android Mediascanner Masterplan
Mediascanner JNI file Name:
Android_media_mediascanner.cpp
Position:
Frameworks\base\media\jni\android_media_mediascanner.cpp
Android_media_mediascanner is a bridge between the Java layer and the server layer
A mymediascannerclient in Android_media_mediascanner is a call to the Java layer android/media/ The entrance to the Mediascannerclient is the bridge where the native layer wants the Java layer to communicate.
Created with Rapha?l 2.1.0 (Java) Mediascanner (Java) Mediascanner (native) Android_media_mediascanner (native) Android_media_mediascanner (c + +) Mediascanner (c + +) Mediascanner Media_jni mymediascannerclient 2. Initialization
In Mediascanner.java initialization, the core of the procedure call is the creation of a Stagefrightmediascanner
static { System.loadLibrary("media_jni"); native_init(); } publicMediaScanner(Context c) { native_setup(); ...... }
Native_init Correspondence Android_media_mediascanner_native_init
Native_setup Correspondence Android_media_mediascanner_native_setup
void*env, jobject thiz){ ALOGV("native_setup"); *=new StagefrightMediaScanner; ...... env->SetLongField(thiz, fields.context, (jlong)mp);}
3. Android_media_mediascanner_processdirectory
Call MediaScanner.cpp Implementation Processdirectory complete work
Call Scandirectories in Mediascanner.java, see Android Mediascanner Source code parsing section 6th
Its function is also through the processdirectory of MediaScanner.cpp to realize the
voidandroid_media_MediaScanner_processDirectory( *env, jobject thiz, jstring path, jobject client){ *= getNativeScanner_l(env, thiz); ....... *= env->NULL); MyMediaScannerClient myClient(env, client); = mp->processDirectory(pathStr, myClient); env->ReleaseStringUTFChars(path, pathStr);}
4. Android_media_mediascanner_processfile
Call StageFrightMediaScanner.cpp Implementation Processfile complete work
staticvoidandroid_media_MediaScanner_processFile( JNIEnv *env, jobject thiz, jstring path, jstring mimeType, jobject client){ // Lock already hold by processDirectory MediaScanner *mp = getNativeScanner_l(env, thiz); constcharNULL); constchar *mimeTypeStr = NULLNULL); ........ MyMediaScannerClient myClient(env, client); MediaScanResult result = mp->processFile(pathStr, mimeTypeStr, myClient);}
5. Mymediascannerclient
Reference android/media/mediascannerclient in Scanfile,handlestringtag, Setmimetype three interfaces
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"); }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Mediascannerjni Source Detailed