0% found this document useful (0 votes)
29 views9 pages

Unit 3

The document discusses various multimedia and sensor capabilities in Android such as playing audio and video, accessing the camera, detecting sensor data, using Bluetooth, and integrating Google Maps. It provides details on key classes and methods for these features.

Uploaded by

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

Unit 3

The document discusses various multimedia and sensor capabilities in Android such as playing audio and video, accessing the camera, detecting sensor data, using Bluetooth, and integrating Google Maps. It provides details on key classes and methods for these features.

Uploaded by

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

Unit 3:Multimedia: Playing Audio, Video and

Camera
 Audio: Android provides APIs for playing various audio
formats like MP3, WAV, etc. You can use the MediaPlayer
class to control playback, volume, and other
functionalities.

Playing Audio:
MediaPlayer Class:
o Usage: Used to control playback of audio and video
files.
o Common Methods:
o create(context, resourceID): Initializes a MediaPlayer
object with a resource.
o setDataSource(String path): Sets the data source to
a file path.
o prepare(): Prepares the MediaPlayer for playback.
o start(): Starts or resumes playback.
o pause(): Pauses playback.
o stop(): Stops playback.
o release(): Releases the resources associated with the
MediaPlayer.

AudioManager Class:

o Usage: Manages audio focus and volume controls.


o Common Methods:
o requestAudioFocus(): Requests audio focus.
o abandonAudioFocus(): Abandons audio focus.
o setStreamVolume(): Sets the volume of a stream.

 Video: Similar to audio, Android offers MediaPlayer and


VideoView classes for playing video files. VideoView provides a
widget for embedding video playback within your app.
Playing Video:
VideoView Class:
Usage: Displays video files.

Common Methods:

o setVideoURI(Uri uri): Sets the URI of the video file.


o start(): Starts or resumes playback.
o pause(): Pauses playback.
o stopPlayback(): Stops playback.

MediaController Class:
Usage: Provides controls for the VideoView.

Common Methods:

o setMediaPlayer(MediaPlayerControl player):
Attaches the MediaPlayer to the
MediaController.
o setAnchorView(View view): Sets the view that
acts as the anchor for the controller.

Camera: The Camera class allows access to the device's


camera for capturing photos and videos. You can control
various camera settings like resolution, focus, and flash.

Camera2 API:
o Usage: Provides a more flexible API for controlling
the camera.
o Key Components:
o CameraManager: Manages camera devices.
o CameraDevice: Represents a single camera device.
o CameraCaptureSession: Handles the capture of
images from the camera.
o CaptureRequest: Contains the settings and
parameters for a single capture.
Common Operations:
Opening the Camera
CameraManager manager = (CameraManager)
getSystemService(Context.CAMERA_SERVICE);
manager.openCamera(cameraId, stateCallback,
null);

Capturing an Image:
CaptureRequest.Builder builder =
cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_C
APTURE);builder.addTarget(imageReader.getSurface());

Graphics: Android Graphics and


Animation
 Android Graphics: Android uses a powerful graphics
framework based on Canvas and OpenGL.
o Canvas: A virtual surface for drawing shapes,
images, and text using primitives and bitmaps.

Common Methods:
o drawLine(float startX, float startY, float stopX,
float stopY, Paint paint): Draws a line.
o drawRect(float left, float top, float right, float
bottom, Paint paint): Draws a rectangle.
o drawCircle(float cx, float cy, float radius, Paint
paint): Draws a circle.

Paint Class:
o Usage: Holds the style and color information
about how to draw geometries, text, and
bitmaps.
o Common Methods:
o setColor(int color): Sets the color.
o setStrokeWidth(float width): Sets the width for
stroking.

OpenGL: A high-performance 3D graphics API for creating


complex animations and game graphics.

 Animation: Android provides various animation classes


like Animation and Animator for creating smooth transitions
and visual effects. You can define animations using XML or
code.

Property Animation:
o ObjectAnimator: Animates a property of an object.

Example

ObjectAnimator animator =
ObjectAnimator.ofFloat(view, "translationX", 0f,
100f); animator.setDuration(1000);
animator.start();

View Animation:
o TranslateAnimation: Moves a view from one
position to another.
o RotateAnimation: Rotates a view.
o ScaleAnimation: Scales a view.
o AlphaAnimation: Changes the alpha level of a
view.

Sensors: Working, Categories,


Framework, Accessing Sensors
How Sensors Work:

 Sensors: Detect and respond to changes in the


environment.

Types of Sensors:
 Motion Sensors: Accelerometer, Gyroscope.
 Environmental Sensors: Thermometer, Barometer.
 Position Sensors: Magnetometer, Proximity sensor.

Sensor Framework:
o SensorManager:
o Usage: Manages all sensors on the device.

Common Methods:
o getDefaultSensor(int type): Returns the default
sensor for a given type.
o registerListener(SensorEventListener listener,
Sensor sensor, int samplingPeriodUs): Registers a
listener.

SensorEventListener:

o Usage: Interface to receive sensor events.

Methods:

o onSensorChanged(SensorEvent event): Called when


sensor values change.
o onAccuracyChanged(Sensor sensor, int accuracy):
Called when sensor accuracy changes.

Sensor Class:
o Usage: Represents a specific sensor.
o Properties:
o getName(): Returns the sensor's name.
o getType(): Returns the sensor's type.
Bluetooth: Bluetooth Adapter,
Paired Devices, Enabling/Disabling
 Bluetooth Adapter: The BluetoothAdapter class represents
the Bluetooth radio on the device. It allows you to check
its availability, enable/disable Bluetooth, and manage
paired devices.

Bluetooth Adapter Class:

BluetoothAdapter:
Usage: Represents the device's Bluetooth adapter.

Common Methods:
o getDefaultAdapter(): Gets the default Bluetooth adapter.
o enable(): Enables Bluetooth.
o disable(): Disables Bluetooth.
o isEnabled(): Checks if Bluetooth is enabled.
o getBondedDevices(): Returns a set of paired (bonded)
devices.

 Paired Devices: Paired devices are Bluetooth devices


that have been previously connected and authorized with
your device.

Paired Devices:
Bonding Process: Exchange of security
codes.
Methods:
o getBondedDevices(): Gets a set of paired
devices.
 Enabling/Disabling Bluetooth: You can use the
BluetoothAdapter methods to enable or disable Bluetooth
functionality on the device.

Enabling Bluetooth:
BluetoothAdapter bluetoothAdapter =
BluetoothAdapter.getDefaultAdapter();

if (!bluetoothAdapter.isEnabled()) {

bluetoothAdapter.enable();

Disabling Bluetooth:
if (bluetoothAdapter.isEnabled()) {

bluetoothAdapter.disable();

Maps & Location: Google Maps


 What is Google Maps: Google Maps is a web mapping
service developed by Google that offers functionalities
like:

oInteractive Maps: View and navigate geographical


locations with detailed street maps, satellite imagery,
and 3D terrain.
o Turn-by-turn Navigation: Get voice-guided
directions for driving, walking, cycling, and public
transport.
o Points of Interest (POI): Search and find places
like restaurants, cafes, gas stations, etc.
 Types of Google Maps: There are different views
available in Google Maps:
o Standard Map: Shows a traditional road map view.
o Satellite View: Provides a view of the earth from
space with satellite imagery.
o Terrain View: Displays a topographic view of the
land with elevation information.
o Hybrid: Combination of normal and satellite views.
 Methods of Google Maps: You can integrate Google
Maps functionality within your app using the Google Maps
Android API. This allows you to:

o Display a map within your app.


o Add markers and overlays to the map.
o Get directions between locations.
o Access user location data (with permission).

Adding a Map:
XML Layout
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragm
ent"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Manipulating the Map:


GoogleMap Class:
o addMarker(MarkerOptions options): Adds a marker.
o moveCamera(CameraUpdate update): Moves the camera to a
specific position.
o animateCamera(CameraUpdate update): Animates the movement of
the camera.
Handling Map Events:

Listeners:
setOnMapClickListener(GoogleMap.OnMapClickListener listener): Handles
map click events.
setOnMarkerClickListener(GoogleMap.OnMarkerClickListener listener):
Handles marker click events.

You might also like