FileDocCategorySizeDatePackage
AudioAttachmentView.javaAPI DocAndroid 1.5 API5716Wed May 06 22:42:46 BST 2009com.android.mms.ui

AudioAttachmentView

public class AudioAttachmentView extends android.widget.LinearLayout implements SlideViewInterface
This class provides an embedded editor/viewer of audio attachment.

Fields Summary
private static final String
TAG
private final android.content.res.Resources
mRes
private android.widget.TextView
mNameView
private android.widget.TextView
mAlbumView
private android.widget.TextView
mArtistView
private android.widget.TextView
mErrorMsgView
private android.net.Uri
mAudioUri
private android.media.MediaPlayer
mMediaPlayer
private boolean
mIsPlaying
Constructors Summary
public AudioAttachmentView(android.content.Context context)


       
        super(context);
        mRes = context.getResources();
    
public AudioAttachmentView(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
        mRes = context.getResources();
    
Methods Summary
private voidcleanupMediaPlayer()

        if (mMediaPlayer != null) {
            try {
                mMediaPlayer.stop();
                mMediaPlayer.release();
            } finally {
                mMediaPlayer = null;
            }
        }
    
protected voidonFinishInflate()

        mNameView = (TextView) findViewById(R.id.audio_name);
        mAlbumView = (TextView) findViewById(R.id.album_name);
        mArtistView = (TextView) findViewById(R.id.artist_name);
        mErrorMsgView = (TextView) findViewById(R.id.audio_error_msg);
    
private voidonPlaybackError()

        Log.e(TAG, "Error occurred while playing audio.");
        showErrorMessage(mRes.getString(R.string.cannot_play_audio));
        stopAudio();
    
public voidpauseAudio()

        // TODO Auto-generated method stub

    
public voidpauseVideo()

        // TODO Auto-generated method stub

    
public voidreset()

        synchronized (this) {
            if (mIsPlaying) {
                stopAudio();
            }
        }
        mErrorMsgView.setVisibility(GONE);
    
public voidseekAudio(int seekTo)

        // TODO Auto-generated method stub

    
public voidseekVideo(int seekTo)

        // TODO Auto-generated method stub

    
public voidsetAudio(android.net.Uri audio, java.lang.String name, java.util.Map extras)

        synchronized (this) {
            mAudioUri = audio;
        }

        mNameView.setText(name);
        mAlbumView.setText((String) extras.get("album"));
        mArtistView.setText((String) extras.get("artist"));
    
public voidsetImage(java.lang.String name, android.graphics.Bitmap bitmap)

        // TODO Auto-generated method stub

    
public voidsetImageRegionFit(java.lang.String fit)

        // TODO Auto-generated method stub

    
public voidsetImageVisibility(boolean visible)

        // TODO Auto-generated method stub

    
public voidsetText(java.lang.String name, java.lang.String text)

        // TODO Auto-generated method stub

    
public voidsetTextVisibility(boolean visible)

        // TODO Auto-generated method stub

    
public voidsetVideo(java.lang.String name, android.net.Uri video)

        // TODO Auto-generated method stub

    
public voidsetVideoVisibility(boolean visible)

        // TODO Auto-generated method stub

    
public voidsetVisibility(boolean visible)

        // TODO Auto-generated method stub

    
private voidshowErrorMessage(java.lang.String msg)

        mErrorMsgView.setText(msg);
        mErrorMsgView.setVisibility(VISIBLE);
    
public synchronized voidstartAudio()

        if (!mIsPlaying && (mAudioUri != null)) {
            mMediaPlayer = MediaPlayer.create(mContext, mAudioUri);
            if (mMediaPlayer != null) {
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
                    public void onCompletion(MediaPlayer mp) {
                        stopAudio();
                    }
                });
                mMediaPlayer.setOnErrorListener(new OnErrorListener() {
                    public boolean onError(MediaPlayer mp, int what, int extra) {
                        onPlaybackError();
                        return true;
                    }
                });

                mIsPlaying = true;
                mMediaPlayer.start();
            }
        }
    
public voidstartVideo()

        // TODO Auto-generated method stub

    
public synchronized voidstopAudio()

        try {
            cleanupMediaPlayer();
        } finally {
            mIsPlaying = false;
        }
    
public voidstopVideo()

        // TODO Auto-generated method stub