The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
Playing back media is a popular pastime on Android devices, one in which your
app may want to participate. The easiest way for you to find out what
media is available for you to display, edit, or otherwise work with is via
MediaStore content provider.
MediaStore is part of the Android framework
and allows you to query for images, audio files, and video files that are
indexed on the device.
This chapter will review the general workings of
MediaStore, plus work
through an example of getting video files — and their thumbnails — from
Understanding this chapter requires that you have read the chapters on:
It is also a pretty good idea to have read the chapters on media
recording and playback that might be of relevance, depending on what
you intend to do with the
You might also wish to consider skimming through the chapter on files again, as it will be cross-referenced in several places in this chapter.
The documentation for
describes it this way:
The Media provider contains meta data for all available media on both internal and external storage devices.
This definition… leaves a bit to be desired.
From our standpoint as Android developers, the
MediaStore is a
ContentProvider, supplied by Android. We can use it much like we use
other system-supplied providers, like
In this case, the primary role of
MediaStore is for us to find media,
just as the primary role of
ContactsContract is for us to find contacts.
The “meta data” reference in the documentation refers to the fact that
MediaStore itself does not store the media, even though that’s what the
MediaStore would suggest.
MediaMetadataStore would be a more
accurate description. We can learn about available media — names, durations,
etc. — and we can get a
MediaStore pointing to the media,
but the media itself lives as a file somewhere else.
MediaStore has media as a primary focus. Here, “media” refers to:
MediaStore has intrinsic knowledge of these, particularly for the file
formats and codecs that Android supports. As a result, the index maintained
MediaStore will contain some metadata in common for all file types,
…and other metadata that will be unique to one or two of the major types, such as:
As was mentioned in passing in the chapter on files, Android uses MTP for Android 4.0+ as the USB protocol for sharing files with a desktop or notebook computer.
To power this, Android does not go straight to the filesystem, but rather works
MediaStore maintains an index of all files, not just
“media”. Whatever shows up in
MediaStore is what shows up to the user in
their Windows drive letter, macOS mounted volume, etc.
You too can query
MediaStore for non-media files. Android will try to maintain
a MIME type — probably based on file extensions — and so you can find all
indexed PDF files, for example, by querying
The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).
The preview of this section was traded for a bag of magic beans.
The preview of this section was lost in the sofa cushions.