Initializing Video Content for Playback

Once you have created and assigned the Surface Holder to your Media Player, use the setDataSource method to specify the path, URL, or Content Provider URI of the video resource to play.

As with audio playback, if you're passing a URL to an online media file, the file must be capable of progressive download using the RTSP or HTTP protocols.

Once you've selected your media source, calprepare to initialize the Media Player in preparation for playback as shown in Listing 11-6.

LISTING 11-6: Initializing video for playback using the Media Player

Available for download on public void surfaceCreated(SurfaceHolder holder) { try {




mediaPlayer.start(); } catch (IllegalArgumentException e) {

Log.d("MEDIA_PLAYER", e.getMessage()); } catch (IllegalStateException e) {

Log.d("MEDIA_PLAYER", e.getMessage()); } catch (IOException e) {

Log.d("MEDIA_PLAYER", e.getMessage());

Unlike audio resources, Android doesn't yet support the playback of video resources included in the application package. Similarly, you cannot use the create static methods as shortcuts to creating your Media Player objects, nor can you use a URI to point to a local file using the file:// schema.

Was this article helpful?

0 0
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