android 播放3gp的列子
2010-09-17 00:07:00 来源:WEB开发网Java代码
package com.google.activity.media;
import java.io.IOException;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import com.google.Main;
import com.google.R;
public class IndexActivity extends Main {
/** 日志TAG */
private static final String TAG = ">>>>>>>> IndexActivity.java <<<<<<<";
/** 控制按钮 */
private ImageButton mBt_play, mBt_pause ,mBt_stop;
/** 提示消息 */
private TextView mTextView;
/** 媒体控制类 */
private MediaPlayer mMediaPlayer;
/** 是否是暂停flag */
private boolean mIsPaused = false;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.media);
setUI();
setAction();
}
/** 获取控件 */
private void setUI(){
mBt_pause = (ImageButton) findViewById(R.id.myButton3);
mBt_play = (ImageButton) findViewById(R.id.myButton1);
mBt_stop = (ImageButton) findViewById(R.id.myButton2);
mTextView = (TextView) findViewById(R.id.myTextView1);
setButtonEnabled(true, false, false);
}
/** 添加事件处理 */
private void setAction(){
mMediaPlayer = new MediaPlayer();
//读取raw文件夹下的mp3文件
mMediaPlayer = MediaPlayer.create(this, R.raw.u01_2);
更多精彩
赞助商链接