(Android)播放视频的简易播放器源码
一,MainActivity.java源码
[html]
import android.app.Activity;
import android.graphics.PixelFormat;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.Su易做图ceHolder;
import android.view.Su易做图ceView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
public class EX07_14 extends Activity
implements Su易做图ceHolder.Callback
{
private TextView mTextView01;
private static final String TAG = "HIPPO_MediaPlayer"; //打印日志的标志
private MediaPlayer mMediaPlayer01;
private Su易做图ceView mSu易做图ceView01;
private Su易做图ceHolder mSu易做图ceHolder01;
private ImageButton mPlay;
private ImageButton mPause;
private ImageButton mReset;
private ImageButton mStop;
private boolean bIsPaused = false;
private boolean bIsReleased = false;
private String strVideoPath = "";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if(!checkSDCard()) //如果没有SD卡
{
mMakeTextToast
(
getResources().getText(R.string.str_err_nosd).toString(),
true
);
}
mTextView01 = (TextView)findViewById(R.id.myTextView1);
getWindow().setFormat(PixelFormat.UNKNOWN);
mSu易做图ceView01 = (Su易做图ceView) findViewById(R.id.mSu易做图ceView1); //显示动画用的容器
mSu易做图ceHolder01 = mSu易做图ceView01.getHolder();
mSu易做图ceHolder01.addCallback(this);
mSu易做图ceHolder01.setFixedSize(176,144);
mSu易做图ceHolder01.setType(Su易做图ceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mPlay = (ImageButton) findViewById(R.id.play);
mPause = (ImageButton) findViewById(R.id.pause);
mReset = (ImageButton) findViewById(R.id.reset);
mStop = (ImageButton) findViewById(R.id.stop);
strVideoPath = "/sdcard/a.3gp";
mPlay.setOnClickListener(new ImageButton.OnClickListener()
{
public void onClick(View view)
{
if(checkSDCard())
{
playVideo(strVideoPath);
}
}
});
mPause.setOnClickListener(new ImageButton.OnClickListener()
{
public void onClick(View view)
{
if(checkSDCard())
{
if (mMediaPlayer01 != null)
{
if(bIsReleased == false)
{
if(bIsPaused==false)
{
mMediaPlayer01.pause();
bIsPaused = true;
mTextView01.setText(R.string.str_pause);
}
else if(bIsPaused==true)
{
mMediaPlayer01.start();
bIsPaused = false;
mTextView01.setText(R.string.str_play);
}
}
}
}
}
});
mReset.setOnClickListener(new ImageButton.OnClickListener()
{
public void onClick(View view)
{
if(checkSDCard())
{
if(bIsReleased == false)
{
if (mMediaPlayer01 != null)
{
mMediaPlayer01.seekTo(0);
}
}
}
}
});
mStop.setOnClick
补充:移动开发 , Android ,