Adding Video Metadata

As we discussed in Chapter 9, Android's MediaStore content provider has a portion, MediaStore.Video, dedicated to video in addition to the portions for image and audio files and metadata that we have previously looked at. When triggering the Camera application via an intent, the Uri to the newly recorded video file that is returned is a content style Uri, which is used in combination with a content provider in this case, the MediaStore. In order to add additional metadata, we can use the Uri...

Network Video Playback

Mediaplayer Onerrorlistener

Android supports HTTP and RTSP video playback in all three video playback methods discussed in Chapter 9. Using either the built-in Media Player activity via an intent or the VideoView class to play either form of network video requires no source code changes. Simply use the HTTP or RTSP URL as the video Uri, and it will work as long as the format is supported. Here is the ViewTheVideo activity example from Chapter 9 that uses a VideoView with an RTSP URL to a video from YouTube's mobile site....

Raw Audio Recording with Audio Record

Aside from using an intent to launch the sound recorder and using the MediaRecorder, Android offers a third method to capture audio, using a class called AudioRecord. AudioRecord is the most flexible of the three methods in that it allows us access to the raw audio stream but has the least number of built-in capabilities, such as not automatically compressing the audio. The basics for using AudioRecord are straightforward. We simply need to construct an object of type AudioRecord, passing in...

Audio Capture with an Intent

Record Sound Action

The easiest way to simply allow audio recording capabilities in an application is to leverage an existing application through an intent that provides recording capabilities. In the case of audio, Android ships with a sound recorder application that can be triggered in this manner. The action used to create the intent is available as a constant called RECORD_SOUND_ACTION within the MediaStore.Audio.Media class. Here is the basic code to trigger the built-in sound recorder. Intent intent new...

Supported Audio Formats

Android supports a variety of audio file formats and codecs for playback it supports fewer for recording, which we'll discuss when we go over recording . AAC Advanced Audio Coding codec as well as both profiles of HE-AAC, High Efficiency AAC , .m4a audio m4a or.3gp audio 3gpp files. AAC is a popular standard that is used by the iPod and other portable media players. Android supports this audio format inside of MPEG-4 audio files and inside of 3GP files which are based on the MPEG-4 format ....

OnStart Command vs onStart

The onStartCommand method was introduced with Android 2.0 API level 5 . Previous to that, the method used was onStart. onStart's parameters are an intent and an int for startId. It does not include the int flags parameter and doesn't have a return. If you are targeting a phone that is running something earlier than 2.0, you can use the onStart method. public void onStart Intent intent, int startid The onDestroy method is called when the OS is destroying a Service. In this example, it is...

Returning Data from the Camera

Of course, simply capturing an image using the built-in camera application won't actually be useful without having the Camera application return the picture to the calling activity when one is captured. This can be accomplished by substituting the startActivity method in our activity with the startActivityForResult method. Using this method allows us the ability to access the data returned from the Camera application, which happens to be the image that was captured by the user as a Bitmap....

Raw Audio Capture and Playback Example

Here is a full example that records using AudioRecord and plays back using AudioTrack. Each of these operations lives in their own thread through the use of AsyncTask, so that they don't make the application become unresponsive by running in the main thread. package import java. import java. import java. import java. import java. import java. import java. import java. import android.view.View.OnClickListener public class AltAudioRecorder extends Activity implements OnClickListener We have two...