码迷,mamicode.com
首页 > 移动开发 > 详细

横竖屏切换播放短视频(前提是手机需要先按下横竖屏切换的按钮)

时间:2016-04-14 22:26:04      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

package com.example.meidiaplayar;

 

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {

private VideoView videoView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

videoView = (VideoView) findViewById(R.id.video);

//String path=Environment.getExternalStorageDirectory().getPath();
//设置视频路径
videoView.setVideoPath("/mnt/sdcard/xiaopohai.3gp");
//设置控制器
MediaController controller=new MediaController(MainActivity.this);
videoView.setMediaController(controller);
controller.setMediaPlayer(videoView);
videoView.start();
//将保存的数据给VideoView
if(savedInstanceState!=null){
int time = savedInstanceState.getInt("time");
videoView.seekTo(time);
}
}

//切换屏幕时,走以下代码;
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub

outState.putInt("time", videoView.getCurrentPosition());
super.onSaveInstanceState(outState);
}

}

横竖屏切换播放短视频(前提是手机需要先按下横竖屏切换的按钮)

标签:

原文地址:http://www.cnblogs.com/zhengyanyan/p/5392726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!