Multimedia Techniques
· Android Multimedia Framework:
· Media Playback, http://developer.android.com/guide/topics/media/mediaplayer.html
o Support for playing variety of common media types (all using MediaPlayer APIs)
o Integrate audio, video and images into your applications
o Play audio or video from
§ Media files stored in your application’s resources (raw resources)
§ Standalone files in the file system, or
§ A data stream over a network connection
· Media and Camera, http://developer.android.com/guide/topics/media/index.html
o Capturing Photo – tutorial training, http://developer.android.com/training/camera/index.html
§ Taking Photos Simply
§ Recording Videos Simply
§ Controlling the Camera
· Examples for the 2nd text book
o Chapter 8: Multimedia Techniques
§
Image (camera pictures), Audio Record and Play
back, Video Record and Play back
o
Image: Loading and Displaying an Image for
Manipulation
o Audio
§
Choosing and Playing Back Audio Files
§
Recording Audio Files
§ Manipulating Raw Audio
§ Using Sound Resources Efficiently
§ Adding Media and Updating Paths
o Video
§ Using the VideoView
§
Video Playback using the MediaPlayer
Media Formats and Types
· Supported Media Format, http://developer.android.com/guide/appendix/media-formats.html
o Network Protocols
§ RTSP (real-time streaming protocol RFC 2326, 1998, http://www.ietf.org/rfc/rfc2326.txt)
· RTP (real-time transmission protocol)
· SDP (session description protocol)
§ HTTP/HTTPS progressive streaming
§ HTTP/HTTPS live streaming draft protocol
o Core Media Formats
§ Audio
§ Image
§ Video
o Video Encoding Recommendations
· Media and Camera, http://developer.android.com/guide/topics/media/index.html
Images
· Camera Device Storage directory
o DCIM/Camera/
· res/drawable
· R.drawable.my_picture
· R.layout.file.row
· image_manipulation.xml
· AndroidManifest.xml
· InputStream
· BitmapFactory class, http://developer.android.com/reference/android/graphics/BitmapFactory.html
o Sources of objects: files, streams, byte arrays
o decodeByteArray()
o decodeFileDescriptor()
o decodeFile()
o decodeResource()
o decodeResourceStream()
o decodeStream()
Android Training – from Android
Developer site
Capturing Photos, http://developer.android.com/training/camera/index.html
Photo Basics, http://developer.android.com/training/camera/photobasics.html
· Request Camera Permission
<manifest ... >
<uses-feature android:name="android.hardware.camera"
android:required="true" />
...
</manifest>
· Take a Photo with the Camera App
The Android way of
delegating actions to other applications is to invoke an Intent
that describes what you want done. This process involves three pieces: The Intent
itself, a call to start the external Activity,
and some code to handle the image data when focus returns to your activity.
·
Get the Thumbnail
If the simple feat of taking a photo is not the culmination of your app's
ambition, then you probably want to get the image back from the camera
application and do something with it.
The Android Camera application encodes the photo in the return Intent
delivered to onActivityResult()
as a small Bitmap
in the extras, under the key "data"
. The following code
retrieves this image and displays it in an ImageView.
·
Save the Full-size Photo
The Android Camera
application saves a full-size photo if you give it a file to save into. You
must provide a fully qualified file name where the camera app should save the
photo.
Generally, any photos that the user captures with the device camera should be
saved on the device in the public external storage so they are accessible by
all apps. The proper directory for shared photos is provided by getExternalStoragePublicDirectory(), with the DIRECTORY_PICTURES
argument. Because the directory provided by this method is shared among all
apps, reading and writing to it requires the READ_EXTERNAL_STORAGE
and WRITE_EXTERNAL_STORAGE
permissions, respectively. The write permission implicitly allows reading, so
if you need to write to the external storage then you need to request only one
permission:
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>
Note:
Files you save in the directories provided by getExternalFilesDir()
are deleted when the user uninstalls your app.
Once you decide the
directory for the file, you need to create a collision-resistant file name. You
may wish also to save the path in a member variable for later use. Here's an
example solution in a method that returns a unique file name for a new photo
using a date-time stamp:
·
Add the Photo to a Gallery
When you create a photo
through an intent, you should know where your image is located, because you
said where to save it in the first place. For everyone else, perhaps the
easiest way to make your photo accessible is to make it accessible from the
system's Media Provider.
Note:
If you saved your photo to the directory provided by getExternalFilesDir(),
the media scanner cannot access the files because they are private to your app.
The following example
method demonstrates how to invoke the system's media scanner to add your photo
to the Media Provider's database, making it available in the Android Gallery
application and to other apps.
· Decode a Scaled Image
Managing multiple full-sized images can be tricky with limited memory. If you find your application running out of memory after displaying just a few images, you can dramatically reduce the amount of dynamic heap used by expanding the JPEG into a memory array that's already scaled to match the size of the destination view. The following example method demonstrates this technique.
Audio
· Audio Recording/Playing Back Audio,
· MediaRecorder.AudioSource, http://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html
o CAMCORDER (constant value 5)
o DEAFULT (0)
o MIC – microphone (1)
o REMOTE_SUBMIX (8) – audio source for a submix of audio streams to be presented remotely
o VOICE_CALL (4)
o VOICE_COMMUNICATION (7)
o VOICE_DOWNLINK (3)
o VOICE_RECOGNITION (6)
o VOICE_UPLINK (2)
· MediaRecorder.OutputFormat, http://developer.android.com/reference/android/media/MediaRecorder.OutputFormat.html
o THREE_GPP – 3GPP media file format (3rd generation partnership)
o MPEG_4
o AMR_NB
· MeidaRecorder.AudioEncoder, http://developer.android.com/reference/android/media/MediaRecorder.AudioEncoder.html
o AMR_NB – adaptive multirate narrowband vocoder
· Media Playback developer guide, http://developer.android.com/guide/topics/media/mediaplayer.html
· Audio Capture, http://developer.android.com/guide/topics/media/audio-capture.html
· Audio file storage directory
o /sdcard/music/
· public class MediaPlayer extends Object, http://developer.android.com/reference/android/media/MediaPlayer.html
o Used to control playback of audio/video files and streams
· public clad MediaRecorder class
· Mediaplayer/MediaRecorder method
o File stream-based
· AudioTrack/AudioRecorder
o Raw audio access in memory
Video Record and Play Back
· VideoView class
o URL of the video
· MediaController class: Play/Pause, Forward, Rewind, and Seek Bar control
· SurfaceView class for rendering the video frames