Android播放本地视频

代码如下:

public class MainActivity extends Activity implements MediaPlayerControl {

?

????private VideoView videoView;

????private MediaController mediaController;

?

????@Override

????protected void onCreate(Bundle savedInstanceState) {

????????// TODO Auto-generated method stub

????????super.onCreate(savedInstanceState);

????????setContentView(R.layout.mainactivity);

????????videoView = (VideoView) findViewById(R.id.videoView1);

????????mediaController = new MediaController(this);

????????videoView.setMediaController(mediaController);

????????// 判断是否挂载sdcard

????????if (Environment.getExternalStorageState().equals(

????????????????Environment.MEDIA_MOUNTED)) {

????????????File file = Environment.getExternalStorageDirectory();// sdcard根目录

????????????File videoFile = new File(file, "test.mp4");

????????????Uri uri = Uri.fromFile(videoFile);// 获取uri

????????????videoView.setVideoURI(uri);

????????}

????}

?

????@Override

????public boolean canPause() {

????????// TODO Auto-generated method stub

????????return videoView.canPause();

????}

?

????@Override

????public boolean canSeekBackward() {

????????// TODO Auto-generated method stub

????????return videoView.canSeekBackward();

????}

?

????@Override

????public boolean canSeekForward() {

????????// TODO Auto-generated method stub

????????return videoView.canSeekForward();

????}

?

????@Override

????public int getAudioSessionId() {

????????// TODO Auto-generated method stub

????????return 0;

????}

?

????@Override

????public int getBufferPercentage() {

????????// TODO Auto-generated method stub

????????return 0;

????}

?

????@Override

????public int getCurrentPosition() {

????????// TODO Auto-generated method stub

????????return videoView.getCurrentPosition();

????}

?

????@Override

????public int getDuration() {

????????// TODO Auto-generated method stub

????????return videoView.getDuration();

????}

?

????@Override

????public boolean isPlaying() {

????????// TODO Auto-generated method stub

????????return videoView.isPlaying();

????}

?

????@Override

????public void pause() {

????????// TODO Auto-generated method stub

????????if (videoView.isPlaying()) {

????????????videoView.pause();

????????}

????}

?

????@Override

????public void seekTo(int postion) {

????????// TODO Auto-generated method stub

????????videoView.seekTo(postion);

????}

?

????@Override

????public void start() {

????????// TODO Auto-generated method stub

????????videoView.start();

????}

}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。