[Android]Media Data之多媒体数据库(三)MediaStore

tech2023-02-03  98

MediaStore提供了对数据库管理的对应信息,并且封装了相关的方法方便上层调用。路径如下:/frameworks/base/core/java/android/provider/ MediaStore.java (The Media provider contains meta data for all available media on both internal and external storage devices.)

1. 类结构图

  下面对这些类进行分析并且总结一下方法和字段。   首先,是MediaStore类的相关信息,包含在内部存储和外部存储的所有的多媒体文件元数据,提供相应方法和字段。

2. 字段

字段解析ACTION_IMAGE_CAPTURE标准的intent action,发送给相机应用,拍摄照片并返回ACTION_IMAGE_CAPTURE_SECURE发送给相机应用,拍摄照片并返回,设备被固定ACTION_VIDEO_CAPTURE标准的intent action,发送给相机应用,录制视频并返回AUTHORITY“media”EXTRA_DURATION_LIMIT指定录像时长的最大值EXTRA_FINISH_ON_COMPLETIONIntent-extra的名字用来控制MovieView 的onCompletion方法EXTRA_FULL_SCREENIntent-extra的名字用来控制ViewImage的UIEXTRA_MEDIA_ALBUMIntent-extra的名字用来定义albumEXTRA_MEDIA_ARTISTIntent-extra的名字用来定义artistEXTRA_MEDIA_FOCUSIntent-extra的名字用来定义search focus.EXTRA_MEDIA_TITLEIntent-extra的名字用来定义 song titleEXTRA_OUTPUTIntent-extra的名字用来表示一个存储图片和视频content resolver 的Uri.EXTRA_SCREEN_ORIENTATIONIntent-extra的名字用来控制ViewImage或者MovieView.EXTRA_SHOW_ACTION_ICONSIntent-extra的名字用来控制ViewImage的UI.EXTRA_SIZE_LIMIT指定最大字长.EXTRA_VIDEO_QUALITYIntent-extra的名字用来控制录制视频的质量.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH一个显示搜索音乐并且自动播放的IntentINTENT_ACTION_MEDIA_SEARCHActivity Action: 显示搜索音乐.INTENT_ACTION_MUSIC_PLAYERThis constant was deprecated in API level 15. Use CATEGORY_APP_MUSIC instead.INTENT_ACTION_STILL_IMAGE_CAMERAIntent action在图片模式下启动camera.INTENT_ACTION_STILL_IMAGE_CAMERA_SECUREIntent action在图片模式下启动camera,设备被锁定INTENT_ACTION_TEXT_OPEN_FROM_SEARCH显示搜索可读media文件并且自动播放的intentINTENT_ACTION_VIDEO_CAMERAIntent action 在录像模式下启动相机INTENT_ACTION_VIDEO_PLAY_FROM_SEARCHAn intent to perform a search for video media and automatically play content from the result when possible.MEDIA_IGNORE_FILENAMEName of the file signaling the media scanner to ignore media in the containing directory and its subdirectories.MEDIA_SCANNER_VOLUMEName of current volume being scanned by the media scanner.UNKNOWN_STRINGThe string that is used when a media attribute is not known.

3. 方法

方法名解析getMediaScannerUri()Uri for querying the state of the media scanner.getVersion(Context context)Get the media provider’s version.

4. MediaStore内部类

  根据上面的类结构图可知,对于MediaStore内部类的属性也非常重要,下面就其内部类相关信息进行总结。

4.1 Media.Audio

  Media.Audio是所有音频文件的容器。下面分析的是其内部类、字段和方法。

4.1.1 MediaStore.Audio.AlbumColumns

  代表一张专辑的列。

字段解析ALBUMThe album on which the audio file appears, if anyALBUM_ARTCached album art.ALBUM_IDThe id for the albumALBUM_KEYA non human readable key calculated from the ALBUM, used for searching, sorting and groupingARTISTThe artist whose songs appear on this albumFIRST_YEARThe year in which the earliest songs on this album were released.LAST_YEARThe year in which the latest songs on this album were released.NUMBER_OF_SONGSThe number of songs on this albumNUMBER_OF_SONGS_FOR_ARTISTThis column is available when getting album info via artist, and indicates the number of songs on the album by the given artist.

4.1.2 MediaStore.Audio.Albums

  艺术家,继承BaseColumns, AlbumColumns接口

字段解析CONTENT_TYPEThe MIME type for this table.DEFAULT_SORT_ORDERThe default sort order for this tableENTRY_CONTENT_TYPEThe MIME type for entries in this table. 方法解析getContentUri(String volumeName)Get the content:// style URI for the albums table on the given volume.

4.1.3 MediaStore.Audio.ArtistColumns

  代表一个艺术家的列

字段解析ARTISTThe artist who created the audio file, if anyARTIST_KEYA non human readable key calculated from the ARTIST, used for searching, sorting and groupingNUMBER_OF_ALBUMSThe number of albums in the database for this artistNUMBER_OF_TRACKSThe number of albums in the database for this artist

4.1.4 MediaStore.Audio.Artists

  艺术家 ,继承BaseColumns, ArtistColumns接口

内部类解析MediaStore.Audio.Artists.Albums对于每个艺术家所包含的所有专辑的子目录 字段解析CONTENT_TYPEThe MIME type for this table.DEFAULT_SORT_ORDERThe default sort order for this tableENTRY_CONTENT_TYPEThe MIME type for entries in this table.EXTERNAL_CONTENT_URIThe content:// style URI for the “primary” external storage volume.INTERNAL_CONTENT_URIThe content:// style URI for the internal storage. 方法解析getContentUri(String volumeName)Get the content:// style URI for the artists table on the given volume.

4.1.5 MediaStore.Audio.AudioColumns

  在多个表中展示出来的音频文件的列

字段解析ALBUMThe album the audio file is from, if anyALBUM_IDThe id of the album the audio file is from, if anyALBUM_KEYA non human readable key calculated from the ALBUM, used for searching, sorting and groupingARTISTThe artist who created the audio file, if anyARTIST_IDThe id of the artist who created the audio file, if anyARTIST_KEYA non human readable key calculated from the ARTIST, used for searching, sorting and groupingBOOKMARKThe position, in ms, playback was at when playback for this file was last stopped.COMPOSERThe composer of the audio file, if anyDURATIONThe duration of the audio file, in msIS_ALARMNon-zero if the audio file may be an alarmIS_MUSICNon-zero if the audio file is musicIS_NOTIFICATIONNon-zero if the audio file may be a notification soundIS_PODCASTNon-zero if the audio file is a podcastIS_RINGTONENon-zero if the audio file may be a ringtoneTITLE_KEYA non human readable key calculated from the TITLE, used for searching, sorting and groupingTRACKThe track number of this song on the album, if any.YEARThe year the audio file was recorded, if any

4.1.6 MediaStore.Audio.Genres

  包含音频文件的流派,继承BaseColumns, GenresColumns

内部类解析MediaStore.Audio.Genres.Members对于每种流派所包含的所有成员的子目录 字段解析CONTENT_TYPEThe MIME type for this table.DEFAULT_SORT_ORDERThe default sort order for this tableENTRY_CONTENT_TYPEThe MIME type for entries in this table.EXTERNAL_CONTENT_URIThe content:// style URI for the “primary” external storage volume.INTERNAL_CONTENT_URIThe content:// style URI for the internal storage. 方法解析getContentUri(String volumeName)Get the content:// style URI for the audio genres table on the given volume.getContentUriForAudioId(String volumeName, int audioId)Get the content:// style URI for querying the genres of an audio file.

4.1.7 MediaStore.Audio.GenresColumns

  代表一个音频流派的列

字段解析NAMEThe name of the genre

4.1.8 MediaStore.Audio.Media

  继承自AudioColumns

字段解析CONTENT_TYPEThe MIME type for this table.DEFAULT_SORT_ORDERThe default sort order for this tableENTRY_CONTENT_TYPEThe MIME type for an audio track.EXTRA_MAX_BYTESThe name of the Intent-extra used to define a maximum file size for a recording made by the SoundRecorder application.RECORD_SOUND_ACTIONActivity Action: Start SoundRecorder application.EXTERNAL_CONTENT_URIThe content:// style URI for the “primary” external storage volume.INTERNAL_CONTENT_URIThe content:// style URI for the internal storage. 方法解析getContentUri(String volumeName)Get the content:// style URI for the audio media table on the given volume.getContentUriForPath(String path) 

4.1.9 MediaStore.Audio.Playlists

  包含音频文件的播放列表

内部类解析MediaStore.Audio.Playlists.Members每个播放列表所包含的所有成员的子目录 字段解析CONTENT_TYPEThe MIME type for this table.DEFAULT_SORT_ORDERThe default sort order for this tableENTRY_CONTENT_TYPEThe MIME type for entries in this table.EXTERNAL_CONTENT_URIThe content:// style URI for the “primary” external storage volume.INTERNAL_CONTENT_URIThe content:// style URI for the internal storage. 方法解析getContentUri(String volumeName)Get the content:// style URI for the audio playlists table on the given volume.

4.1.10 MediaStore.Audio.PlaylistsColumns

  代表播放列表的列

字段解析DATAPath to the playlist file on disk.DATE_ADDEDThe time the file was added to the media provider Units are seconds since 1970.DATE_MODIFIEDThe time the file was last modified Units are seconds since 1970.NAMEThe name of the playlist

4.1.11 MediaStore.Audio.Radio

  音频文件中的收音机文件

字段解析ENTRY_CONTENT_TYPEThe MIME type for entries in this table.

4.2 Media.Files

  Media provider的表,包含了多媒体存储中所有文件的索引,包括非多媒体文件。这个类可以在单词查询中处理多媒体文件和非多媒体文件。

方法解析getContentUri(String volumeName)Get the content:// style URI for the files table on the given volume.getContentUri(String volumeName, long rowId)Get the content:// style URI for a single row in the files table on the given volume.

4.2.1 MediaStore.Files.FileColumns

  所有多媒体文件的主表字段

字段解析MEDIA_TYPEThe media type (audio, video, image or playlist) of the file, or 0 for not a media fileMEDIA_TYPE_AUDIOConstant for the MEDIA_TYPE column indicating that file is an audio file.MEDIA_TYPE_IMAGEConstant for the MEDIA_TYPE column indicating that file is an image file.MEDIA_TYPE_NONEConstant for the MEDIA_TYPE column indicating that file is not an audio, image, video or playlist file.MEDIA_TYPE_PLAYLISTConstant for the MEDIA_TYPE column indicating that file is a playlist file.MEDIA_TYPE_VIDEOConstant for the MEDIA_TYPE column indicating that file is a video file.MIME_TYPEThe MIME type of the filePARENTThe index of the parent directory of the fileTITLEThe title of the content

4.3 MediaStore.Images

  包含所有可用图片的元数据。下面是对其内部类的整理:

4.3.1 MediaStore.Images.ImageColumns

  代表所有图片文件的列

字段解析BUCKET_DISPLAY_NAMEThe bucket display name of the image.BUCKET_IDThe bucket id of the image.DATE_TAKENThe date & time that the image was taken in units of milliseconds since jan 1, 1970.DESCRIPTIONThe description of the imageIS_PRIVATEWhether the video should be published as public or privateLATITUDEThe latitude where the image was captured.LONGITUDEThe longitude where the image was captured.MINI_THUMB_MAGICThe mini thumb id.ORIENTATIONThe orientation for the image expressed as degrees.PICASA_IDThe picasa id of the image

4.3.2 MediaStore.Images.Media

  提供各种操作方法,继承ImageColumns

字段解析CONTENT_TYPEThe MIME type of of this directory of images.DEFAULT_SORT_ORDERThe default sort order for this tableEXTERNAL_CONTENT_URIThe content:// style URI for the “primary” external storage volume.INTERNAL_CONTENT_URIThe content:// style URI for the internal storage. 方法解析getBitmap(ContentResolver cr, Uri url)Retrieves an image for the given url as a Bitmap.getContentUri(String volumeName)Get the content:// style URI for the image media table on the given volume.insertImage(ContentResolver cr, String imagePath, String name, String description)Insert an image and create a thumbnail for it.insertImage(ContentResolver cr, Bitmap source, String title, String description)Insert an image and create a thumbnail for it.query(ContentResolver cr, Uri uri, String[] projection) query(ContentResolver cr, Uri uri, String[] projection, String where,String orderBy) query(ContentResolver cr, Uri uri, String[] projection, String selection,String[] selectionArgs, String orderBy) 

4.3.3 MediaStore.Images.Thumbnails

  这个类允许开发者去查询并且得到两种略缩图,MINI_KIND: 512 x 384 thumbnail MICRO_KIND: 96 x 96 thumbnail

字段解析DATAPath to the thumbnail file on disk.DEFAULT_SORT_ORDERThe default sort order for this tableFULL_SCREEN_KIND HEIGHTThe height of the thumbnailIMAGE_IDThe original image for the thumbnalKINDThe kind of the thumbnailMICRO_KIND MINI_KIND THUMB_DATAThe blob raw data of thumbnailWIDTHThe width of the thumbnalEXTERNAL_CONTENT_URIThe content:// style URI for the “primary” external storage volume.INTERNAL_CONTENT_URIThe content:// style URI for the internal storage. 方法解析cancelThumbnailRequest(ContentResolver cr, long origId)This method cancels the thumbnail request so clients waiting for getThumbnail will be interrupted and return immediately.cancelThumbnailRequest(ContentResolver cr, long origId, long groupId)This method cancels the thumbnail request so clients waiting for getThumbnail will be interrupted and return immediately.getContentUri(String volumeName)Get the content:// style URI for the image media table on the given volume.getThumbnail(ContentResolver cr, long origId, long groupId, int kind, BitmapFactory.Options options)This method checks if the thumbnails of the specified image (origId) has been created.getThumbnail(ContentResolver cr, long origId, int kind, BitmapFactory.Options options)This method checks if the thumbnails of the specified image (origId) has been created.query(ContentResolver cr, Uri uri, String[] projection) queryMiniThumbnail(ContentResolver cr, long origId, int kind, String[] projection) queryMiniThumbnails(ContentResolver cr, Uri uri, int kind, String[] projection) 

4.4 MediaStore.MediaColumns

  大多数MediaProvider表的常见字段。

字段解析DATAPath to the file on disk.DATE_ADDEDThe time the file was added to the media provider Units are seconds since 1970.DATE_MODIFIEDThe time the file was last modified Units are seconds since 1970.DISPLAY_NAMEThe display name of the fileHEIGHTThe height of the image/video in pixels.MIME_TYPEThe MIME type of the fileSIZEThe size of the file in bytesTITLEThe title of the contentWIDTHThe width of the image/video in pixels.

4.5 MediaStore.Video

  包含视频文件的元数据,并提供相应字段和方法。

方法解析query(ContentResolver cr, Uri uri, String[] projection) 

4.5.1 MediaStore.Video.Media

  提供和获取视频文件的Uri,继承VideoColumns

字段解析CONTENT_TYPEThe MIME type for this table.DEFAULT_SORT_ORDERThe default sort order for this tableEXTERNAL_CONTENT_URIThe content:// style URI for the “primary” external storage volume.INTERNAL_CONTENT_URIThe content:// style URI for the internal storage. 方法解析getContentUri(String volumeName)Get the content:// style URI for the video media table on the given volume.

4.5.2 MediaStore.Video.Thumbnails

  这个类让开发者去查询并且得到两种略缩图:MINI_KIND: 512 x 384 thumbnail MICRO_KIND: 96 x 96 thumbnail

字段解析DATAPath to the thumbnail file on disk.DEFAULT_SORT_ORDERThe default sort order for this tableFULL_SCREEN_KIND HEIGHTThe height of the thumbnailKINDThe kind of the thumbnailMICRO_KIND MINI_KIND VIDEO_IDThe original image for the thumbnalWIDTHThe width of the thumbnalEXTERNAL_CONTENT_URIThe content:// style URI for the “primary” external storage volume.INTERNAL_CONTENT_URIThe content:// style URI for the internal storage. 方法解析cancelThumbnailRequest(ContentResolver cr, long origId)This method cancels the thumbnail request so clients waiting for getThumbnail will be interrupted and return immediately.cancelThumbnailRequest(ContentResolver cr, long origId, long groupId)This method cancels the thumbnail request so clients waiting for getThumbnail will be interrupted and return immediately.getContentUri(String volumeName)Get the content:// style URI for the image media table on the given volume.getThumbnail(ContentResolver cr, long origId, long groupId, int kind, BitmapFactory.Options options)This method checks if the thumbnails of the specified image (origId) has been created.getThumbnail(ContentResolver cr, long origId, int kind, BitmapFactory.Options options)This method checks if the thumbnails of the specified image (origId) has been created.

4.5.3 MediaStore.Video.VideoColumns

  代表所有视频文件的列

字段解析ALBUMThe album the video file is from, if anyARTISTThe artist who created the video file, if anyBOOKMARKThe bookmark for the video.BUCKET_DISPLAY_NAMEThe bucket display name of the video.BUCKET_IDThe bucket id of the video.CATEGORYThe YouTube category of the videoDATE_TAKENThe date & time that the video was taken in units of milliseconds since jan 1, 1970.DESCRIPTIONThe description of the video recordingDURATIONThe duration of the video file, in msIS_PRIVATEWhether the video should be published as public or privateLANGUAGEThe language of the videoLATITUDEThe latitude where the video was captured.LONGITUDEThe longitude where the video was captured.MINI_THUMB_MAGICThe mini thumb id.RESOLUTIONThe resolution of the video file, formatted as “XxY”TAGSThe user-added tags associated with a video
最新回复(0)