Android Multimedia
Android Multimedia
Android Multimedia
APPLICATION
DEVELOPMENT
By Ankit Attkan
Department of Computer Engineering
National Institute of Technology, Kurukshetra
ANDROID MULTIMEDIA
Android supports multimedia by using the open source multimedia system
called OpenCORE from PacketVideo Corporation.
OpenCORE provides the foundation for Android’s media services, which Android wraps
in an easy-to-use API.
In addition to the OpenCORE framework, the Android platform is migrating to a Google-
written multimedia framework named Stagefright.
It’s anticipated that most, if not all, of the multimedia functionality will be handled by
the Stagefright code base.
ANDROID MULTIMEDIA
OpenCORE is a Java open source, multimedia platform that supports:
Interfaces for third-party and hardware media codecs, input and output devices, and content
policies.
Media playback, streaming, downloading, and progressive playback, including 3rd Generation
Partnership Program (3GPP), Moving Picture Experts Group 4 (MPEG-4), Advanced Audio Coding
(AAC), and Moving Picture Experts Group Audio Layer 3(MP3) containers.
Video and image encoders and decoders, including MPEG-4, International Telecommunication
Union H.263 video standard (H.263), Advanced Video Coding (AVC H.264), and the Joint
Photographic Experts Group (JPEG).
Speech codecs, including Adaptive Multi-Rate audio codecs AMR-NB and AMR-WB
Audio codecs, including MP3, AAC, and AAC+
Media recording, including 3GPP, MPEG-4, and JPEG
Video telephony based on the 3GPP video conferencing standard 324-M
PV test framework to ensure robustness and stability; pro ling tools for memory and CPU usage
ANDROID MULTIMEDIA
OpenCORE’s services and architecture
ANDROID MULTIMEDIA
What is Stage Fright?
• Stage fright is a multimedia system provided by google for android devices.
• Stage fright was introduced with Android 2.3.
• Stage fright has completely replaced the OpenCORE system but still can create
applications that can work with both systems.
• Some of the characteristics of the stage fright system:
Watch all types of media in playback, download and live stream.
Stage fright supports many Real Time Streaming Protocol (RTSP) and HTTP protocols.
Record and Capture all types of media.
Stage also supports fright video calls.
This system supports other hardware and input output devices.
ANDROID MULTIMEDIA
Play an Audio le (MP3 le):
1. Put the MP3 in the res/raw directory in a project (note that you can also use a URI to access
les on the network or via the internet).
2. Create a new instance of the MediaPlayer and reference your MP3 by calling MediaPlayer.
create().
3. Call the MediaPlayer methods prepare() and start().
main.xml for MediaPlayer Example:
ANDROID MULTIMEDIA
MediaPlayerActivity.java:
The Android emulator doesn’t allow to connect to camera devices such as a webcam, on your computer.
All pictures will display a chessboard as shown.
For connecting to a web camera and get live images and video, Goto: http://www.tomgibara.com/android/
camera-source
ANDROID MULTIMEDIA
Recording Audio:
1. Create an instance of android.media.MediaRecorder.
2. Create an instance of andriod.content.ContentValues, and add properties such as TITLE, TIMESTAMP, and
the all-important MIME_TYPE
3. Create a le path for the data to go to using android.content.ContentResolver
4. To set a preview display on a view surface, use MediaRecorder. setPreviewDisplay()
5. Set the source for audio, using MediaRecorder.setAudioSource()
6. Set output le format, using MediaRecorder.setOutputFormat()
7. Set encoding for audio, using MediaRecorder.setAudioEncoder()
8. Use prepare() and start() to prepare and start recordings
9. Use stop() and release() to gracefully stop and clean up recording process
Note: Audio capture requires a physical device running Android or enable "Virtual microphone uses host audio
input“ only if android emulator supports.
ANDROID MULTIMEDIA
Need to edit the AndroidManifest.xml le for granting permission:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
SoundRecordingdemo.java for recording audio application:
ANDROID MULTIMEDIA
Recording Video:
Video recording on Android is no more di cult than recording audio.
Require several permission like RECORD_VIDEO, CAMERA, RECORD_AUDIO, and WRITE_EXTERNAL_
STORAGE. So, edit AndroidManifest.xml.
ANDROID MULTIMEDIA
Create a simple layout that has preview area and some buttons to start, stop, pause, and play
your video recording in main.xml le.
ANDROID MULTIMEDIA
To Record Video:
1. Create an instance of android.media.MediaRecorder.
2. Set up a VideoView.
3. To set a preview display on a view surface, use MediaRecorder.setPreviewDisplay().
4. Set the source for audio, using MediaRecorder.setAudioSource().
5. Set the source for video, using MediaRecorder.setVideoSource().
6. Set your encoding for audio, using MediaRecorder.setAudioEncoder().
7. Set your encoding for video, using MediaRecorder.setVideoEncoder().
8. Set output le format using MediaRecorder.setOutputFormat().
9. Set the video size using setVideoSize().
ANDROID MULTIMEDIA
VideoCam.java for recording video application:
ANDROID MULTIMEDIA
VideoCam.java continued:
VideoCam Application
running
USING ANDROID GRAPHICS
Example to add graphics create le MyView.java and edit MainActivity.java:
USING ANDROID GRAPHICS
Output:
Drawing can be done using android.graphics package or using XML les but need to reference it
in a layout. Example of simple rectangle:
simplerectangle.xml
USING ANDROID GRAPHICS
Referencing simplerectangle.xml to android:layout:
xmllayout.xml