0% found this document useful (0 votes)
46 views15 pages

Chapter 6

The document discusses multimedia and graphics capabilities in Android. It covers Android APIs for playing audio and video files, recording audio and video, and displaying images. It also discusses graphics APIs for drawing 2D shapes and applying animations. The multimedia APIs are in the android.media package, with the core MediaPlayer class used to play audio and video. The Android SDK provides comprehensive support for multimedia playback, recording, and display through high-level APIs.

Uploaded by

Betelhem Jebesa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views15 pages

Chapter 6

The document discusses multimedia and graphics capabilities in Android. It covers Android APIs for playing audio and video files, recording audio and video, and displaying images. It also discusses graphics APIs for drawing 2D shapes and applying animations. The multimedia APIs are in the android.media package, with the core MediaPlayer class used to play audio and video. The Android SDK provides comprehensive support for multimedia playback, recording, and display through high-level APIs.

Uploaded by

Betelhem Jebesa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

CHAPTER 6:

Multimedia & Graphics In Android

COMPILED BY CHALEW Z.(MSC) 1


Introduction
 In todays world of converging technologies the mobile phone is used for a variety of tasks
beyond simple voice calls.

 Multimedia capabilities, or the playing and recording of audio and video, is one such
significant task that many users find to be of great value.

 Take a quick look around and you will find people using the phone as a means to enjoy a
variety of programs as well as share self-recorded media among friends.

 Android provides the APIs to easily access this capability as well as embed multimedia and
its manipulation directly within an application.

 Three main aspects in multimedia include Media, Audio, and Video.


COMPILED BY CHALEW Z.(MSC) 2
Cont…
Android provides a huge set of 2D-drawing APIs that allow you to create graphics.

Android has got visually appealing graphics and mind-blowing animations.

The Android framework provides a rich set of powerful APIS for applying animation to UI
elements and graphics as well as drawing custom 2D and 3D graphics.

COMPILED BY CHALEW Z.(MSC) 3


Multimedia & Graphics In Android
 The Android SDK provides a set of APIs to handle multimedia files, such as audio, video
and images. Moreover, the SDK provides other API sets that help developers to implement
interesting graphics effects, like animations and so on.

 The modern smart phones and tablets have an increasing storage capacity so that we can
store music files, video files, images etc.

 Not only the storage capacity is important, but also the high definition camera makes it
possible to take impressive photos. In this context, the Multimedia API plays an important
role.

COMPILED BY CHALEW Z.(MSC) 4


Multimedia API
 Android supports a wide list of audio, video and image formats.

 You can give a look here to have an idea; just to name a few formats supported:

COMPILED BY CHALEW Z.(MSC) 5


Cont.…
 Android, additionally can handle local files, meaning files that are stored inside the smart
phone or tablet or remote file using data streaming.
 We can leverage these capabilities in order to build very interesting apps.
 All the classes provided by the Android SDK that we can use to add multimedia capabilities
to our apps are under the android.media package.
 In this package, the heart class is called MediaPlayer.
 This class has several methods that we can use to play audio and video file stored in our
device or streamed from a remote server.
 To stream Internet media using the Media Player, your application must include the
INTERNET permission:

COMPILED BY CHALEW Z.(MSC) 6


Cont.…
 There are 4 state of multimedia file play either video or music:

1. Idle state: When we create a new instance of the MediaPlayer class.

2. Initialization state: This state is triggered when we use setDataSource to set the
information source that MediaPlayer has to use.

3. Prepared state: In this state, the preparation work is completed. We can enter in this state
calling prepare method or prepareAsync.

4. Completed state: The end of the stream is reached.

COMPILED BY CHALEW Z.(MSC) 7


Cont.…

COMPILED BY CHALEW Z.(MSC) 8


Android Audio Recorder
 In android, MediaRecorder class will provide a functionality to record audio or video files.
 The android multimedia framework provides a built in support for capturing and encoding
a variety of common audio and video formats.
 We have a multiple ways to record audio or video but by using MediaRecorder class we
can easily implement audio or video recording.
 Following is the code snippet of defining the permissions in android manifest file to record
audio and save it in device.

COMPILED BY CHALEW Z.(MSC) 9


Image Components
 In Android, ImageView class is used to display an image file in application. Image file is
easy to use but hard to master in Android, because of the various screen sizes in Android
devices.

 An android is enriched with some of the best UI design widgets that allows us to build good
looking and attractive UI based application.

 Below is an ImageView code in XML:

COMPILED BY CHALEW Z.(MSC) 10


Using Android Camera
 If we want to add to our apps the capability to take photos using the integrated smart
phone camera, then the best way is to use an Intent. For example, let us suppose we want
to start the camera as soon as we press a button and show the result in our app.

COMPILED BY CHALEW Z.(MSC) 11


Graphics in Android
 Android implements complete 2-D functions in one package, named android.graphics.
 This package provides various kinds of graphics tools, such as canvas, color filter, point, line, and
rectangles.
 The android.graphics.Paint class is used with canvas to draw objects. It holds the information of
color and style.
Canvas
 To draw 2-dimensional objects an own
class can be derived from the View class
and its onDraw(Canvas canvas) method
can be overwritten
 The Canvas class contains various methods
for drawing 2D primitives such as lines,
rectangles, circles, etc

COMPILED BY CHALEW Z.(MSC) 12


Cont…
Color
 Colors are represented as packed integers, made up of 4 bytes: Alpha, Red, Green, and Blue.
 Alpha is a measure of transparency, from value 0 to value 255.
 The value 0 indicates the color is completely transparent. The value 255 indicates the color is
completely opaque.
 We can create a half-opaque purple color like:
int color1 = Color.argb(127, 255, 0, 255); Or in XML resource file, like:
<color name=“half_op_purple”>#7fff00ff</color>

COMPILED BY CHALEW Z.(MSC) 13


Cont…
 The easiest way to use 2D graphics is extending the View class and overriding the onDraw
method. We can use this technique when we do not need a graphics intensive app.

 In this case, we can use the Canvas class to create 2D graphics. This class provides a set of
method starting with draw * that can be used to draw different shapes like:

COMPILED BY CHALEW Z.(MSC) 14


End,
Any question?

COMPILED BY CHALEW Z.(MSC) 15

You might also like