Android Multimedia

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

MOBILE

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:

 Simple media player running in emulator:


ANDROID MULTIMEDIA
 Playing a video le:
 It is slightly more complicated than playing audio with the MediaPlayer API because video
need a view surface for playing.
 Android has a VideoView widget that handles that task, can use it in any layout manager.
 Android also provides a number of display options, including scaling and tinting.

 main.xml for Simple Video Player:


ANDROID MULTIMEDIA
 SimpleVideo.java:

 Playing an MP4 video in the Android emulator:


ANDROID MULTIMEDIA
 Controlling Camera:
 Use the Android Camera class to take or capture picture, video and save them.
 Single method called take-Picture (Camera. ShutterCallback shutter, Camera.PictureCallback raw, Camera.
PictureCallback jpeg) with 3 callbacks is used to capture photo.
 CameraExample.java for SimpleCamera application:
ANDROID MULTIMEDIA
 CameraExample.java continued:
ANDROID MULTIMEDIA
 ImageCaptureCallback.java
 Set up the creation of a le by using ImageCaptureCallback.
 Create an Outputstream to write image data

 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

 Create a simple Activity and run, it’ll draw a simple rectangle:


XMLDraw.java
ANDROID-ACTIVITY
 Android system initiates its program with in an Activity starting with a call on onCreate() callback method,
which is just like main() function:

Activity Life Cycle


ANDROID-ACTIVITY
 Activity class de nes the following call backs i.e. events:
Sr.No Callback & Description
1 onCreate(): This is the rst callback and called when the activity is rst created.
2 onStart(): This callback is called when the activity becomes visible to the user.
3 onResume(): This is called when the user starts interacting with the application.
4 onPause(): The paused activity does not receive user input and cannot execute any code and called when
the current activity is being paused and the previous activity is being resumed.
5 onStop(): This callback is called when the activity is no longer visible.
6 onDestroy(): This callback is called before the activity is destroyed by the system.
7 onRestart(): This callback is called when the activity restarts after stopping it.
 Refer this https://www.tutorialspoint.com/android/android_acitivities.htm for more.
THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy