Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Android media library of analysis: MediaProvider     - Haproxy multi-domain certificate HTTPS (Server)

- Change the kernel boot sequence after CentOS 7 kernel upgrade (Linux)

- How to statistical data of various size Redis (Database)

- Btrfs file system creation and their characteristics in Linux (Linux)

- php performance monitoring module XHProf (Linux)

- Features and prevention methods elaborate network security grayware (Linux)

- Three details reflect the Unix system security (Linux)

- To solve the Mac in question invalid BASH under configuration environment variable (Linux)

- sa weak passwords intrusion prevention (Linux)

- Use scripts easily install the latest Linux kernel in Ubuntu (Linux)

- Deploy the project to the server from GitHub (Server)

- Linux installation notes under GAMIT (Linux)

- Android studio multi-channel ultra-compact version of the package (Programming)

- Python MySQL database connection (Database)

- Ubuntu 14.04 installed Nvidia CUDA 7.5 and build Python Theano deep learning development environment (Linux)

- Zabbix Agent (Server)

- Setting Hibernate connection MySQL database connection pool coding (Database)

- Smooth upgrade to OpenSSH 6.1 Procedure (Linux)

- Ubuntu prevent arp attacks (Linux)

- grep, egrep and regular expressions (Linux)

 
         
  Android media library of analysis: MediaProvider
     
  Add Date : 2017-05-23      
         
         
         
  In doing Android media application (Audio, Image, Video) requires Android media provider (MediaProvider) to do a detailed analysis, the following look at my record harvest:

First, get MediaProvider:
The project in the system source packages \ providers directory proposed and import Eclipse, easy to read

Second, engineering structures and internal relations:
It can be seen from the chart contains four files:
MediaScannerService.Java: media services, with the implementation instance broadcast media scan class initialization database work, but also provides an interface outside;
MediaScannerReceiver.Java: a broadcast receiver, a broadcast receiving system for distributed media services and media services to start;
MediaProvider.Java: wrapper class media database, the code larger than (more than four thousand lines), the function is more complex, but in general is to create a database, provide external URI additions and deletions to the database in order to achieve change search function;
MediaThumbRequest.Java: media file thumbnails request class, used in conjunction with MediaProvider;

The position and role of which is shown in Figure MediaProvider content in red box;
The figure also includes other content:
1, App layer: audio, image, video library and how to interact;
2, the frame layer (android.media package under): how the media scan;
3, Native Layer: how are the media file parsing;
4, resource storage layer: sd card, U disk and other media, DTCM store thumbnails;

Third, Detailed category

1, MediaScannerReceiver:

 public void onReceive (Context context, Intent intent) {
  String action = intent.getAction ();
  Uri uri = intent.getData ();
  // String externalStoragePath =
  // Environment.getExternalStorageDirectory () getPath ().;
  String externalSDStoragePath = Environment
    .getExternalSDStorageDirectory () getPath ().;
  String externalUDiskStoragePath = Environment
    .getExternalUDiskStorageDirectory () getPath ().;
  String externalExtSDStoragePath = Environment
    .getExternalExtSDStorageDirectory () getPath ().;

  if (action.equals (Intent.ACTION_BOOT_COMPLETED)) {
   // Scan internal storage
   scan (context, MediaProvider.INTERNAL_VOLUME);
  } Else {
   if (uri.getScheme (). equals ( "file")) {
    // Handle intents related to external storage
    String path = uri.getPath ();
    if (action.equals (Intent.ACTION_MEDIA_MOUNTED)) {
     if (externalSDStoragePath.equals (path))
      scan (context, MediaProvider.EXTERNAL_VOLUME_SD);
     else if (externalUDiskStoragePath.equals (path))
      scan (context, MediaProvider.EXTERNAL_VOLUME_UDISK);
     else if (externalExtSDStoragePath.equals (path))
      scan (context, MediaProvider.EXTERNAL_VOLUME_EXTSD);
     else
      Slog.w (TAG, "unknown volume path" + path);
    } Else if (action.equals (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)
      && Path! = Null
      && (Path.startsWith (externalSDStoragePath + "/")
        || Path.startsWith (externalExtSDStoragePath
          + "/") || Path
         .startsWith (externalUDiskStoragePath + "/"))) {
     scanFile (context, path);
    }
   }
  }
 }

Three categories need to start scanning service:
a, system startup is completed;
b, media mount (EXTERNAL_VOLUME_SD, EXTERNAL_VOLUME_UDISK, EXTERNAL_VOLUME_EXTSD);
c, broadcast media file scanning (ACTION_MEDIA_SCANNER_SCAN_FILE);

scanFile and scan method is very simple, just to start media services:

 private void scan (Context context, String volume) {
  Bundle args = new Bundle ();
  args.putString ( "volume", volume);
  context.startService (new Intent (context, MediaScannerService.class)
    .putExtras (args));
 }

 private void scanFile (Context context, String path) {
  Bundle args = new Bundle ();
  Slog.i (TAG, "Start scanFile.");
  args.putString ( "filepath", path);
  context.startService (new Intent (context, MediaScannerService.class)
    .putExtras (args));
 }

2, MediaScannerService:
Step one: Start a thread

 public void run () {
  // Reduce priority below other background threads to avoid interfering
  // With other services at boot time.
  Process.setThreadPriority (Process.THREAD_PRIORITY_BACKGROUND
    + Process.THREAD_PRIORITY_LESS_FAVORABLE);
  Looper.prepare ();

  mServiceLooper = Looper.myLooper ();
  mServiceHandler = new ServiceHandler ();

  Looper.loop ();
 }

Get the current thread's message queue, use the handler to process the message;

Step Two: Start ServiceHandler process messages
ServiceHandler or processed in two, one is scanned, the second is to resolve specific media file;
The second is to look at how to achieve:

     IBinder binder = arguments.getIBinder ( "listener");
     IMediaScannerListener listener = (binder == null? Null
       : IMediaScannerListener.Stub.asInterface (binder));
     Uri uri = scanFile (filePath,
       arguments.getString ( "mimetype"));
     if (listener! = null) {
      listener.scanCompleted (filePath, uri);
     }

Code

 private final IMediaScannerService.Stub mBinder = new IMediaScannerService.Stub () {
  public void requestScanFile (String path, String mimeType,
    IMediaScannerListener listener) {
   if (Config.LOGD) {
    Log.d (TAG, "IMediaScannerService.scanFile:" + path
      + "MimeType:" + mimeType);
   }
   Bundle args = new Bundle ();
   args.putString ( "filepath", path);
   args.putString ( "mimetype", mimeType);
   if (listener! = null) {
    args.putIBinder ( "listener", listener.asBinder ());
   }
   startService (new Intent (MediaScannerService.this,
     MediaScannerService.class) .putExtras (args));
  }

  public void scanFile (String path, String mimeType) {
   requestScanFile (path, mimeType, null);
  }
 };

So the question is: if we want the system to resolve the App library specific to a document, it should be how to do it?
You can see from the above code, bound interfaces MediaScannerService give us, we only need to pass filepath IMediaScannerListener listener and a can, a media library after completion will resolve callback method tells us scanCompleted analytical results;

Step three: Create MediaScanner objects to complete scanning and parsing;
Visible concrete scanning, analytical work is not done MediaScannerService, MediaScannerService only calling sacn, when acanfile method creates MediaScanner object and at his disposal;
MediaScanner in android.media.MediaScanner system framework inside, do not be discussed here;

MediaScannerService basic content of these;

3, MediaProvider:
MediaProvider is to create a database, provide external URI additions and deletions to the database in order to achieve change search function;

4, MediaThumbRequest:
Audio, Image, Video files are there thumbnail, the thumbnail path is stored in the DB, its true files are stored in sd card DICM folder, MediaThumbRequest only available to MediaProvider class action database.
Mainly on two methods, a new thumbnail method: execute, a thumbnail update method: updateDatabase
New skills get: Get application thumbnail, expect the next article;

So far, MediaProvider clear structural analysis, follow-up plans to make two articles:
APP system used in media library;
Scanning media files, parsing is how to achieve;
     
         
         
         
  More:      
 
- Valgrind * not * leak check tool (Linux)
- Using IE can also be easily remotely control the computer (Linux)
- Hadoop + Zookeeper NameNode achieve high availability (Server)
- Teach you how to ensure password security under the Linux operating system (Linux)
- Confrontation dragged Library - Web front-end encryption slow (Linux)
- Oracle 11g partition maintenance (two) - Coalescing Partitions (Database)
- Linux operating tips: Can not open file for writing or operation not permitted solution (Linux)
- Use Git in Eclipse (Linux)
- JQuery implements the same content merge cells (Programming)
- Linux and hardware (Linux)
- Linux initialization init systems - Systemd (Linux)
- CentOS 7 virt-manager can not connect a local hypervisor (Linux)
- Getting Started with Linux system to learn: How do I know which processes are running on the CPU core (Linux)
- Redmine Installation (Linux)
- To deploy MySQL database with separate read and write OneProxy (Database)
- To compile and install Redis Linux and master-slave replication configuration (Database)
- Linux remote wake the computer original code [C] (Linux)
- Installing Linux and Windows 10 dual system (Linux)
- Linux Network Programming - raw socket can do (Programming)
- How to Install Node.js in CentOS 7 (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.