Android MediaScannerJNI source code

Source: Internet
Author: User

Android MediaScannerJNI source code
1. Introduction

For MediaScannerJNI's position in MediaScanner, refer
Android MediaScanner Overview
MediaScanner JNI File Name:
Android_media_MediaScanner.cpp
Location:
Frameworksasemediajniandroid_media_MediaScanner.cpp
Android_media_MediaScanner is a bridge between the JAVA layer and the server layer.

In android_media_MediaScanner, MyMediaScannerClient is a bridge between the Native layer and the JAVA layer to call android/media/MediaScannerClient. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxzdmcgaGVpZ2h0PQ = "260" version = "1.1" width = "634" xmlns = "http://www.w3.org/2000/svg"> Created with Rapha limit 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

During MediaScanner. java initialization, the core of the call is to create a StagefrightMediaScanner

static {        System.loadLibrary(media_jni);        native_init();    }    public MediaScanner(Context c) {        native_setup();        ......    }

Native_init corresponds to android_media_MediaScanner_native_init
Native_setup corresponds to android_media_MediaScanner_native_setup

static voidandroid_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

Call MediaScanner. cpp to implement processDirectory.
Use scanDirectories in MediaScanner. java. For details, see section 6th of Android MediaScanner source code parsing.
Its function is implemented through the processDirectory of MediaScanner. cpp.

static voidandroid_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

Call StageFrightMediaScanner. cpp to implement processFile.

static voidandroid_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 ? env->GetStringUTFChars(mimeType, NULL) : NULL);    ........    MyMediaScannerClient myClient(env, client);    MediaScanResult result = mp->processFile(pathStr, mimeTypeStr, myClient);}
5. MyMediaScannerClient

Reference three interfaces: scanFile, handleStringTag, and setMimeType in android/media/MediaScannerClient

        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);        }

 

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: info-contact@alibabacloud.com 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.