Android Mediascannerjni Source Detailed

Source: Internet
Author: User

1. Introduction

The position of Mediascannerjni in Mediascanner can be referenced
Android Mediascanner Masterplan
Mediascanner JNI file Name:
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 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, 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.