Building a simple audio app in Android (Part 1/3)

MediaPlayer introduction

Nazmul Idris (Naz)
Aug 22, 2017 · 4 min read

Introduction

Android Media APIs encompass a lot of advanced functionality that allow developers to create rich media experiences. They include things like ExoPlayer, MediaSession, audio focus, volume shaping, and lots of other amazing capabilities just around media playback and control.

The goal of this series of articles is to get you started with the Android MediaPlayer API by going thru the journey of creating a very basic audio playback application called “A Simple MediaPlayer” app. This is the first part of a 3 part series that includes:

Part 1/3 — MediaPlayer introduction

This article will cover the following:

Basic MediaPlayer tasks

Here are the basic tasks that MediaPlayer needs to handle:

This list covers the basic playback tasks for audio content, but it isn’t exhaustive. There are more complex functions for sophisticated audio apps such as streaming media, dealing with audio focus, volume shaping, and working with MediaSession. For more information on these advanced topics, please consult the MediaPlayer API guide.

Simplified state machine

Here is a simplified description of MediaPlayer’s state machine for audio playback:

First create an instance of MediaPlayer.

Now that your audio has been loaded, you can play and pause your audio. And you can stop and restart playback.

When you are done with the instance of MediaPlayer, be sure to release() it. Once released, you have to create a new MediaPlayer object and start from Step 1 in order to play another media file.

To get started with building the app, please checkout Part 2/3 of this series- Building the app.

Android Media Resources

Android Developers

The official Android Developers publication on Medium

Nazmul Idris (Naz)

Written by

Google SWE, entrepreneur, leader, designer, dancer, TaiChi'er, Yogi, racer, healer, storyteller. I ❤️ leadership, authenticity, empowerment, & lifelong learning

Android Developers

The official Android Developers publication on Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade