FileDocCategorySizeDatePackage
MediaPlayerDemo_Audio.javaAPI DocAndroid 1.5 API2849Wed May 06 22:41:08 BST 2009com.example.android.apis.media

MediaPlayerDemo_Audio

public class MediaPlayerDemo_Audio extends android.app.Activity

Fields Summary
private static final String
TAG
private android.media.MediaPlayer
mMediaPlayer
private static final String
MEDIA
private static final int
LOCAL_AUDIO
private static final int
STREAM_AUDIO
private static final int
RESOURCES_AUDIO
private static final int
LOCAL_VIDEO
private static final int
STREAM_VIDEO
private String
path
private android.widget.TextView
tx
Constructors Summary
Methods Summary
public voidonCreate(android.os.Bundle icicle)


        
        super.onCreate(icicle);
        tx = new TextView(this);
        setContentView(tx);
        Bundle extras = getIntent().getExtras();
        playAudio(extras.getInt(MEDIA));
    
protected voidonDestroy()

        super.onDestroy();
        // TODO Auto-generated method stub
        if (mMediaPlayer != null) {
            mMediaPlayer.release();
            mMediaPlayer = null;
        }

    
private voidplayAudio(java.lang.Integer media)

        try {
            switch (media) {
                case LOCAL_AUDIO:
                    /**
                     * TODO: Set the path variable to a local audio file path.
                     */
                    path = "";
                    if (path == "") {
                        // Tell the user to provide an audio file URL.
                        Toast
                                .makeText(
                                        MediaPlayerDemo_Audio.this,
                                        "Please edit MediaPlayer_Audio Activity, "
                                                + "and set the path variable to your audio file path."
                                                + " Your audio file must be stored on sdcard.",
                                        Toast.LENGTH_LONG).show();

                    }
                    mMediaPlayer = new MediaPlayer();
                    mMediaPlayer.setDataSource(path);
                    mMediaPlayer.prepare();
                    mMediaPlayer.start();
                    break;
                case RESOURCES_AUDIO:
                    /**
                     * TODO: Upload a audio file to res/raw folder and provide
                     * its resid in MediaPlayer.create() method.
                     */
                    mMediaPlayer = MediaPlayer.create(this, R.raw.test_cbr);
                    mMediaPlayer.start();

            }
            tx.setText("Playing audio...");

        } catch (Exception e) {
            Log.e(TAG, "error: " + e.getMessage(), e);
        }