Transferred from: http://www.2cto.com/kf/201309/242876.html
Mainly divided into several sections:
1. How is the internal storage of Android media files? 2. How does the andoid media file get? 3. Some tips on using media files. 1. How is android multimedia stored? Android multimedia files are mainly stored in the/data/data/com.android.providers.media/databases directory, the directory has two DB files, one is the internal storage database file (internal.db), One is the memory card database (EXTERNAL-XXXX.DB). The operation of the media file is mainly around these two databases. The two databases are completely identical in structure. Let's take a look at what tables these two databases contain. Album_art Audio searchalbum_info audio_genres searchhelpertitlealbums audio_genres_map thumbnailsandroid_metadata Audio_meta videoartist_info audio_playlists videothumbnailsartists audio_playlists_mapartists_albums_map Images first from the basic analysis: Images table: The main storage images information. You can look at the structure of this table: CREATE table images (_id INTEGER PRIMARY key,_data text,_size integer,_display_name text,mime_type TEXT, titletext,date_added integer,date_modified integer,description text,picasa_id text,isprivate INTEGER,latitude DOUBLE , longitude Double,datetaken integer,orientation integer,mini_thumb_magic integer,bucket_id TEXT,bucket_display_name TEXT), which contains some basic information, which everyone can see. Thumbnails table: This table is directly related to the images table. Mainly stores thumbnails of images, and Android automatically generates a thumbnail file for each picture file saved into the system. There are some special tricks on this, and we'll talk about it later.。 We can look at the structure of this table: CREATE table thumbnails (_id integer PRIMARY key,_data text,image_id integer,kind integer,width Integer, Height INTEGER); Each image corresponds to a thumbnail record. Video table: The main storage of the visual information. Similar to the images table. The table structure is as follows: CREATE table video (_id INTEGER PRIMARY key,_data TEXT not null,_display_name text,_size integer,mime_type text,date _added integer,date_modified integer,title text,duration integer,artist text,album TEXT,resolution TEXT,description Text,isprivate integer,tags text,category text,language text,mini_thumb_data text,latitude DOUBLE,longitude DOUBLE, Datetaken integer,mini_thumb_magic Integer, bucket_id text, bucket_display_name text, bookmark integer); Videothumbnails Table: Stores thumbnail information for video. This is similar to the Thumbnails table. Audio table: It is slightly more complicated than video information and picture information, mainly store some album (album), singer (artists) information, and album and singer information is a separate table storage, audio is actually a view, real audio data information stored in Audio_ Meta table. We can look at the definition of Audio view: CREATE view Audio as SELECT * from Audio_meta left OUTER JOIN artists on audio_meta.artist_id=artists.ar Tist_id left OUTER joins albums on audio_meta.album_id=albums.album_id; ALbums table: mainly stores album information. Artists table: Main store singer Information. Not much to repeat. Some of the other tables we may use less often, do not describe, interested in self-study. 2. How is Android multimedia available? Android provides the relevant APIs for media acquisition and storage, mainly in Android.provider.MediaStorepackage. MediaStore.Audio.AlbumColumnsColumns representing an albumMediaStore.Audio.ArtistColumnsColumns representing an ArtistMediaStore.Audio.AudioColumnsColumns for Audio file, the show up in multiple tables. MediaStore.Audio.GenresColumnsColumns representing an Audio genreMediaStore.Audio.PlaylistsColumnsColumns Representing a playlistMediaStore.Files.FileColumnsFields for master table for all media Files. MediaStore.Images.ImageColumnsMediaStore.MediaColumnsCommon fields for most Mediaprovider TablesMediaStore.Video.VideoColumnsMediaStoreThe media provider contains meta data for all available media on both Interna L and external storage devices. Mediastore.audiocontainer for all audio content. MediaStore.Audio.AlbumsContains Artists for audio FilesMediaStore.Audio.ArtistsContains artists for audio FilesMediaStore.Audio.Artists.AlbumsSub-directory of each artist containing all albums in which a song by the artist appears. MediaStore.Audio.GenresContains all genres for Audio filesmediastore.audio.genres.memberssub-directory of each genre containing all members. MediaStore.Audio.MediaMediaStore.Audio.PlaylistsContains Playlists for Audio Filesmediastore.audio.playlists.memberssub-directory of each playlist containing all members. Mediastore.filesmedia provider table containing an index of all files in the media storage, including Non-media files. Mediastore.imagescontains meta data for all available images. MediaStore.Images.MediaMediaStore.Images.ThumbnailsThis class allows developers to query and get both kinds of thumbnails: mini_kind:512 x 384 thumbnail micro_kind:96 x 96 ThumbnailMediaStore.VideoMediaStore.Video.MediaMediaStore.Video.ThumbnailsThis class allows developers to query and Get kinds of thumbnails:mini_kind:512 x 384 thumbnail micro_kind:96 x thumbnail simply observe that these classes, which are the encapsulation of some tables in the database, understand the bottom The storage structure of the layer, for understanding these classes's role is easy. There are two types of address descriptions for each media file in the Android system. The first pattern, you know, in Android, content provider is a unified interface for storing and acquiring common data, and content provider assigns URI addresses to each class of resources. The address of the patch includes the MediaStore.Images.Media.INTERNAL_CONTENT_URI and MediaStore.Images.Media.EXTERNAL_CONTENT_URI two base addresses, The values are Content://media/internal/images/media and Content://media/external/images/media, corresponding to the internal library and the external library address. The address of each image is basically the internal ID of the add-on under the base URL address above. For example, a memory card with an image ID of 2, the corresponding URI address is CONTENT://MEDIA/EXTERNAL/IMAGES/MEDIA/2. Knowing this address, you can basically manipulate all the information in this picture. Another description of the file address identifier is the traditional file path mode, such as a memory card on the image address may be described as:/mnt/sdcard/images/1.jpg. In fact, this path is stored in the data field in the images table, and with this connection, we can switch between the two modes in any way. The previous mode, mainly through the MediaStore.Images.Media, MediaStore.Audio.Media, MediaStore.Video.Media three libraries in the Query method to inquire or get specific conditions of the media. Basic usage 1: Generate bitmap from a content URI address can take Android.provider.MediaStore.Images.Media.getBitmap (Contentresolvercr,uriurl) method, where Contentresolver is the interface between the application and the resource, and its examples can usually be obtained through the Getcontentresolver () method called in the activity. The URI address is the CONTENT://MEDIA/EXTERNAL/IMAGES/MEDIA/2 similar address described above, which is the address form defined by content provider. Basic Usage 2: Generate bitmap from a traditional address sometimes we only know the path of a picture, and we don't know the interior of the picture.Address, want to get the picture, you can use the Decodexxx method in Android.graphics.BitmapFactory, such as DecodeFile method is to read from the file path, the original image can support Jpg,png,gif, Various formats such as BMP. The Decodebytearray is decoded from the byte stream. Finally, they are converted into bitmap format. Basic Usage 3: Get a thumbnail image of a picture sometimes we need to display thumbnails of the images, and we can use the Android.provider.MediaStore.Images.Thumbnails GetThumbnail method. In fact, you can also use bitmap's Compress method to do some compression processing of the picture.
Detailed Android Multimedia database (GO)