編輯:關於Android編程
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
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.
*/
scanDirectories ⇒ jni processDirectory (1) android_media_MediaScanner.cpp android_media_MediaScanner中比較重要的是MyMediaScannerClient類, 該類會被繼續傳到底層,用於調用java層(MediaScanner.java)的 scanFile, handleStringTag, setMimeType libmedia – libmedia.so frameworksavmedialibstagefrightStagefrightMediaScanner.cpp
(1) MediaScanner<喎?/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPjxiciAvPg0KZnJhbWV3b3Jrcy9iYXNlL21lZGlhL2phdmEvYW5kcm9pZC9tZWRpYS9NZWRpYVNjYW5uZXIuamF2YTwvcD4NCjxwPkNhbGwgSk5JPC9wPg0KPHByZSBjbGFzcz0="brush:java;">
static {
System.loadLibrary(media_jni);
native_init();
}
scanSingleFile ==> MyMediaScannerClient.doScanFile
deal with image, audio, video ⇒ jni processFile4. JNI層
frameworksasemediajniandroid_media_MediaScanner.cpp
MediaScanner *mp = getNativeScanner_l(env, thiz);
mp->processDirectory(pathStr, myClient);
mp->processFile(pathStr, mimeTypeStr, myClient);5. Server Proxyer
frameworksavmedialibmediaMediaScanner.cpp
處理具體的文件
如果是文件夾需要返回JAVA層中,采用scanFile處理6. Server
libstagefright.so
根據文件後綴判斷可處理的文件
然後通過MediaMetadataRetriever獲取視頻的詳細信息,
最後同過handleString一步一步向上傳, 在MediaScannerService中把信息寫入數據庫.
1. Allocation TrackerAllocation Tracker是android studio自帶的一個功能,我們可以在MemoryMonitor中打開使用
Android中屏蔽電源鍵長按、Home鍵、Home鍵長按 這幾個“按鈕”的觸發,都會產生一個Action == Intent.ACTION_CLOSE_SYSTE
Android Studio + Gradle的組合用起來非常方便,很多第三方開源項目也早都遷移到了Studio,為此今天就來介紹下查看、編譯並導入第三方開源項目的方法。
android中提供了4中動畫: AlphaAnimation 透明度動畫效果 ScaleAnimation 縮放動畫效果 TranslateAnimation 位移動畫