Android media usage Summary

Source: Internet
Author: User

Reprint address: http://blog.csdn.net/xingtian713/article/details/6458150

Http://blog.csdn.net/xingtian713/article/details/6525411

It can be divided into several sections:

1. How do Android media files be stored internally?

2. How to obtain the andoid media file?

3. Tips on using media files.

 

1. How does Android multimedia be stored?

Android multimedia files are mainly stored in/data/COM. android. providers. under the media/databases directory, there are two dB files under this directory, one is the internal storage database file (internal. DB), one is the memory card database (external-XXXX.db ). Operations on media files are mainly performed on these two databases. The two databases have exactly the same structure.

Let's take a look at the tables contained in these two databases.

Album_art
Audio search

Album_info
Audio_genres searchhelpertitle

Albums
Audio_genres_map thumbnails

Android_metadata
Audio_meta video

Artist_info
Audio_playlists videothumbnails

Artists
Audio_playlists_map

Artists_albums_map
Images

First from the basic analysis:

Images table: Mainly stores images information. Let's take a look at the structure of this table:

Create Table images (_ id integerprimary key, _ Data Text, _ SIZE integer, _ display_name text, mime_type text, title

Text, date_added integer, date_modifiedinteger, description text, picasa_id text, isprivate integer, latitude doubl

E, longpolling double, datetakeninteger, orientation integer, mini_thumb_magic integer, bucket_id text, bucket_displa

Y_name text );

It contains some basic information.

Thumbnails table: This table is directly related to the images table. It mainly Stores image thumbnails. Android automatically generates a thumbnail file for each image file stored in the system. There are some special skills for this. Let's take a look at the structure of this table:

Create Table thumbnails (_ id integerprimary key, _ Data Text, image_id integer, kind integer, width integer, height
Integer );

Each image corresponds to a thumbnail record.

Video table: stores video information. Similar to the images table. The table structure is as follows:

Create Table video (_ id integerprimary key, _ Data Text not null, _ display_name text, _ SIZE integer, mime_typetext, date_added integer, date_modified integer, title text, durationinteger, artist text, album text, resolution
Text, description text, isprivateinteger, tags text, category text, language text, plain text, latitudedouble, long1_double, datetaken integer, mini_thumb_magic integer, bucket_idtext, bucket_display_name text, Bookmark integer );

Videothumbnails table: stores the thumbnail information of a video. This is similar to the thumbnails table.

Audio table: Audio Information is a little more complex than video information and image information. It mainly stores information about some albums (album) and singers (artists, the album and artist information are stored in a separate table. Audio is actually a view, and the real audio data information is stored in the audio_meta table. Let's take a look at the definition of the audio View:

Create view audio as select * fromaudio_meta left Outer Join artists on audio_meta.artist_id = artists. artist_idleft Outer Join albums on audio_meta.album_id = albums. album_id;

Albums table: stores album information.

Artists table: Mainly stores information about singers. I will not repeat it here.

Other tables may be used less frequently and will not be described. If you are interested, you can study them on your own.

2. How to obtain Android multimedia?

Android provides APIs for media access and storage, which are mainly included in Android. provider. mediastorepackage.

Mediastore. Audio. albumcolumns

Columns representing an album

Mediastore. Audio. artistcolumns

Columns representing an artist

Mediastore. Audio. audiocolumns

Columns for audio file that show up in multiple tables.

Mediastore. Audio. genrescolumns

Columns representing an audio Genre

Mediastore. Audio. playlistscolumns

Columns representing a playlist

Mediastore. Files. filecolumns

Fields for master table for all media files.

Mediastore. Images. imagecolumns

 

Mediastore. mediacolumns

Common fields for most mediaprovider tables

Mediastore. Video. videocolumns

 

Mediastore

The media provider contains meta data for all available media on both internal and external storage devices.

Mediastore. Audio

Container for all audio content.

Mediastore. Audio. albums

Contains artists for audio files

Mediastore. Audio. Artists

Contains artists for audio files

Mediastore. Audio. Artists. albums

Sub-directory of each artist containing all albums on which a song by the artist appears.

Mediastore. Audio. genres

Contains all genres for audio files

Mediastore. Audio. genres. Members

Sub-directory of each genre containing all members.

Mediastore. Audio. Media

 

Mediastore. Audio. Playlists

Contains playlists for audio files

Mediastore. Audio. playlists. Members

Sub-directory of each playlist containing all members.

Mediastore. Files

Media provider table containing an index of all files in the media storage, including non-media files.

Mediastore. Images

Contains meta data for all available images.

Mediastore. Images. Media

 

Mediastore. Images. thumbnails

This class allows developers to query and get two kinds of thumbnails: mini_kind: 512x384 thumbnail micro_kind: 96X96 thumbnail

Mediastore. Video

 

Mediastore. Video. Media

 

Mediastore. Video. thumbnails

This class allows developers to query and get two kinds of thumbnails: mini_kind: 512x384 thumbnail micro_kind: 96X96 thumbnail

After a simple observation, we find that these classes are the encapsulation of some tables in the database and understand the underlying storage structure. It is easy to understand the functions of these classes.

Each media file in Android has two address description methods.

The first mode, as you know, in Android, content provider is a unified interface used to store and obtain public data. Content Provider allocates a URI address for each type of resources, the video address includes mediastore. images. media. internal_content_uri and mediastore. images. media. external_content_uri: Content: // media/Internal/images/media and content: // media/external/images/media, corresponds to the internal library and external library address. The address of each image is basically the internal ID of the slice added under the Basic URL above. For example, if the image ID on a memory card is 2, the corresponding URI address is content: // media/external/images/Media/2. after knowing the address, you can basically operate on all the information of the image.

Another description file address is the traditional file path mode. For example, the image address on a memory card may be/mnt/sdcard/images/1.jpg. In fact, this path is stored in the data field in the images table. With this association, we can switch between the two modes at will.

In the previous mode, the query methods in the mediastore. Images. Media, mediastore. Audio. Media, and mediastore. Video. media libraries are used to query or obtain media with specific conditions.

Basic usage 1: Generate bitmap from a content URI address

Android can be used. provider. mediastore. images. media. the getbitmap (contentresolver Cr, Uri URL) method, in which contentresolver is the contact person between the application and the resource. Its example can usually be obtained through the getcontentresolver () method called in the activity. The URI address is the address similar to content: // media/external/images/Media/2 described above, that is, the address format defined by the content provider.

Basic usage 2: Generate bitmap from a traditional address

Sometimes we only know the path of an image, but do not know the internal address of the image. To get the image, we can use android. graphics. the decodexxx method in bitmapfactory is used. For example, the decodefile method reads images from the file path. The original image can support JPG, PNG, GIF, BMP, and other formats. Decodebytearray is decoded from the byte stream. Finally, it is converted to the bitmap format.

Basic usage 3:Returns a thumbnail of an image.

You can use the getthumbnail method of Android. provider. mediastore. Images. thumbnails to display thumbnails of images. In addition, bitmap compress can also be used to compress images.

Related Article

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.