Advanced Video

In Chapter 9, we looked at how Android can play back a specific video file that is placed on the device's SD card. In this chapter, we'll take that a step further and look at accessing video that is made available by the MediaStore and video that is available on the Internet.

As discussed in Chapter 1, Android provides a standard means for sharing data across applications. The ContentProvider class is the base class that enables this. Also as discussed, the classes that extend the concept of a ContentProvider for media are the various MediaStore classes. We previously looked at using the MediaStore for images and audio and their related metadata. The MediaStore for use with video behaves in much the same way.

MediaStore.Video is the nested class within the MediaStore class for use with video files in particular. Within MediaStore.Video is MediaStore.Video.Media, which contains the constants that specify the columns available in the MediaStore related to the video media itself, many of which are inherited from other classes, such as MediaStore.MediaColumns. There is also a MediaStore.Video.Thumbnails, which contains the constants that specify the columns available in the MediaStore for thumbnail image storage that is related to video files.

To query the MediaStore for video content, we utilize the Uri specified in the constant MediaStore.Video.Media.EXTERNAL_CONTENT_URI as the data source for a query.

Using the managedQuery method available in the Activity class, we also need to pass in an array of columns that we would like returned. The array specified here indicates that we want the unique ID for the video in the MediaStore, MediaStore.Video.Media._ID. This is followed by MediaStore.Video.Media.DATA, which is the path to the video file itself. The next two specify that we want the title and the MIME-type of the file.

String[] mediaColumns = {

MediaStore.Video.Media._ID,

MediaStore.Video.Media.DATA,

MediaStore.Video.Media.TITLE,

Was this article helpful?

0 0

Post a comment