1. MediaScanner HEAD
2. 应用层 MediaProvider
packages\providers\MediaProvider
(1) MediaProvider
packages\providers\MediaProvider\MediaProvider.java
MediaProvider继承于ContentProvider,主要用于创建媒体库的数据库表.
详细内容请查阅如何创建Provider.
MediaProvider中包涵一个BroadcastReceiver,用于监听SDCard挂载/卸载
(2) MediaReceiver
监听扫描事件, 调用MSS
Action :
Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MEDIA_MOUNTED
scan volume MediaScannerService
else
scanFile filepath MediaScannerService
(3) MediaScannerService MSS
onStartCommand==>ServiceHandler==>scanFile
当我们调用startService的时候,如果对应的Service还未创建就会调用onCreate方 法===方法。每次startService的时候就调用onStartCommand,所以ServiceHandler就在此发送消息了。
call: MediaScanner :: scanSingleFile, scanDirectories
3. JAVA 层
Call Stack : Google注解
/*
* In summary:
* Java MediaScannerService calls
* Java MediaScanner scanDirectories, which calls
* Java MediaScanner processDirectory (native method), which calls
* native MediaScanner processDirectory, which calls
* native MyMediaScannerClient scanFile, which calls
* Java MyMediaScannerClient scanFile, which calls
* Java MediaScannerClient doScanFile, which calls
* Java MediaScanner processFile (native method), which calls
* native MediaScanner processFile, which calls
* native parseMP3, parseMP4, parseMidi, parseOgg or parseWMA, which calls
* native MyMediaScanner handleStringTag, which calls
* Java MyMediaScanner handleStringTag.
* Once MediaScanner processFile returns, an entry is inserted in to the database.
*/
(1) MediaScanner
frameworks/base/media/java/android/media/MediaScanner.java
Call JNI
static {
System.loadLibrary("media_jni");
native_init();
}
scanDirectories ? jni processDirectory
scanSingleFile ==> MyMediaScannerClient.doScanFile
deal with image, audio, video ? jni processFile
4. JNI层
(1) android_media_MediaScanner.cpp
frameworks\base\media\jni\android_media_MediaScanner.cpp
MediaScanner *mp = getNativeScanner_l(env, thiz);
mp->processDirectory(pathStr, myClient);
mp->processFile(pathStr, mimeTypeStr, myClient);
android_media_MediaScanner中比较重要的是MyMediaScannerClient类, 该类会被继续传到底层,用于调用java层(MediaScanner.java)的 scanFile, handleStringTag, setMimeType
5. Server Proxyer
libmedia – libmedia.so
frameworks\av\media\libmedia\MediaScanner.cpp
处理具体的文件
如果是文件夹需要返回JAVA层中,采用scanFile处理
6. Server
frameworks\av\media\libstagefright\StagefrightMediaScanner.cpp
libstagefright.so
根据文件后缀判断可处理的文件
然后通过MediaMetadataRetriever获取视频的详细信息,
最后同过handleString一步一步向上传, 在MediaScannerService中把信息写入数据库.
版权声明:本文为博主原创文章,未经博主允许不得转载。