Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android MediaScanner 總綱

Android MediaScanner 總綱

編輯:關於Android編程

1. MediaScanner HEAD

這裡寫圖片描述

2. 應用層 MediaProvider

packagesprovidersMediaProvider
(1) MediaProvider
packagesprovidersMediaProviderMediaProvider.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<喎?/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPjxiciAvPg0KZnJhbWV3b3Jrcy9iYXNlL21lZGlhL2phdmEvYW5kcm9pZC9tZWRpYS9NZWRpYVNjYW5uZXIuamF2YTwvcD4NCjxwPkNhbGwgSk5JPC9wPg0KPHByZSBjbGFzcz0="brush:java;"> 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
frameworksasemediajniandroid_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
frameworksavmedialibmediaMediaScanner.cpp
處理具體的文件
如果是文件夾需要返回JAVA層中,采用scanFile處理

6. Server

frameworksavmedialibstagefrightStagefrightMediaScanner.cpp
libstagefright.so
根據文件後綴判斷可處理的文件
然後通過MediaMetadataRetriever獲取視頻的詳細信息,
最後同過handleString一步一步向上傳, 在MediaScannerService中把信息寫入數據庫.

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved