1.
Introduction to Multimedia in Android
Multimedia features such as audio playback, video playback, and animations significantly
improve user experience by making applications more interactive and engaging.
Android provides built-in APIs like:
MediaPlayer → audio & video playback
VideoView → easy video integration
Animation APIs → UI motion effects
2. Audio Playback in Android
Using MediaPlayer
The MediaPlayer class is used to play audio files stored in:
res/raw folder
External storage
Online URLs
Steps:
1. Add audio file to res/raw
2. Create MediaPlayer instance
3. Start/Stop playback
Sample Code (Java)
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
MediaPlayer mediaPlayer;
Button playBtn, stopBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
playBtn = findViewById([Link]);
stopBtn = findViewById([Link]);
mediaPlayer = [Link](this, [Link].sample_audio);
[Link](v -> [Link]());
[Link](v -> {
if ([Link]()) {
[Link]();
mediaPlayer = [Link](this, [Link].sample_audio);
}
});
}
}
3. Video Playback in Android
Using VideoView
VideoView simplifies video playback with built-in controls.
Steps:
1. Add video to res/raw (or use URL)
2. Use VideoView in XML
3. Attach MediaController
XML Layout
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Java Code
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class VideoActivity extends AppCompatActivity {
VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_video);
videoView = findViewById([Link]);
String path = "[Link]://" + getPackageName() + "/" + [Link].sample_video;
Uri uri = [Link](path);
[Link](uri);
MediaController controller = new MediaController(this);
[Link](controller);
[Link]();
}
}
4. Animations in Android
Animations improve UI responsiveness and user engagement.
Types of Animations:
1. View Animation (Tween Animation)
2. Property Animation
3. Drawable Animation
Example: Fade Animation
XML (res/anim/fade_in.xml)
<alpha xmlns:android="[Link]
android:duration="1000"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
Java Code
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class AnimationActivity extends AppCompatActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_animation);
button = findViewById([Link]);
Animation fadeIn = [Link](this, [Link].fade_in);
[Link](fadeIn);
}
}
Example: Property Animation (Scale)
[Link]()
.scaleX(1.5f)
.scaleY(1.5f)
.setDuration(500);
5. Benefits of Multimedia in Android Apps
Enhances user engagement
Improves accessibility (audio cues)
Enables rich content delivery
Makes UI visually appealing
6. Best Practices
Release MediaPlayer resources:
@Override
protected void onDestroy() {
[Link]();
if (mediaPlayer != null) {
[Link]();
}
}
Optimize video size to reduce memory usage
Avoid excessive animations (affects performance)
Use compressed media files
1. Introduction
Drawable Animation (also called Frame Animation) is a technique in Android where a
sequence of images (frames) is displayed one after another to create an animation effect—just
like a flipbook.
It is useful for:
Loading animations
Game sprites
Simple UI effects
2. What is a Drawable?
A Drawable is a general abstraction for “something that can be drawn” on the screen.
Types include:
Image drawables (PNG, JPG)
Shape drawables
Animation drawables
3. AnimationDrawable Class
Android provides the AnimationDrawable class to implement frame-by-frame animation.
Key Features:
Displays a list of drawable resources in sequence
Each frame has a duration
Can loop continuously
4. Steps to Create Drawable Animation
Step 1: Add Images
Place multiple images in:
res/drawable/
Example:
[Link]
[Link]
[Link]
Step 2: Create Animation XML
Create a file in:
res/drawable/[Link]
XML Code
<animation-list xmlns:android="[Link]
android:oneshot="false">
<item android:drawable="@drawable/frame1" android:duration="200" />
<item android:drawable="@drawable/frame2" android:duration="200" />
<item android:drawable="@drawable/frame3" android:duration="200" />
</animation-list>
Explanation:
oneshot="false" → loops animation
duration → time for each frame (milliseconds)
5. Layout File
XML Layout
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/animation" />
6. Java Code to Start Animation
Simple Code
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
ImageView imageView;
AnimationDrawable animationDrawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
imageView = findViewById([Link]);
// Get animation
animationDrawable = (AnimationDrawable) [Link]();
// Start animation
[Link](() -> [Link]());
}
}
7. Stop Animation (Optional)
[Link]();
8. Advantages of Drawable Animation
Easy to implement
No complex coding required
Good for simple animations
9. Limitations
Uses more memory (many images)
Not suitable for complex animations
Can slow down performance if too many frames
10. Real-Life Examples
Loading spinner
Walking character animation
Button effects
11. Conclusion
Drawable animation is one of the simplest ways to add motion to Android apps. By
using AnimationDrawable, developers can quickly create frame-by-frame animations using
XML and minimal Java code.