Managing Media Playback Output

The Media Player provides methods to control the volume of the output, manage the screen lock during playback, and set the looping status.

It is not currently possible to play audio into a phone conversation; the Media Player always plays audio using the standard output device —the speaker or connected Bluetooth headset.

Use the isLooping and setLooping methods to specify if the media being played should loop when it completes.

if (!mediaPlayer.isLooping()) mediaPlayer.setLooping(true);

To enable a Wake Lock that will keep the screen on during video playback use the setScreenOnWhile Playing method. This is preferred to setting manual Wake Lock as it doesn't require an additional permission. Wake Locks are described in more detail in Chapter 15.

mediaPlayer.setScreenOnWhilePlaying(true);

You can control the volume for each channel during playback using the setVolume method. It takes a scalar float value between 0 and 1 for both the left and right channels (where 0 is silent and 1 is maximum volume).

mediaPlayer.setVolume(1f, 0.5f);

When playing video resources, you can use getFrame to take a Bitmap screen grab of video media at the specified frame.

RECORDING AUDIO AND VIDEO

Android offers two alternatives for recording audio and video within your application.

The simplest technique is to use Intents to launch the video camera app. This option lets you specify the output location and video recording quality, while letting the native video recording application handle the user experience and error handling.

In cases where you want to replace the native app, or simply need more fine-grained control over the video capture UI or recording settings, you can use the Media Recorder class.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment