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

Android横竖屏切换继续播放视频

时间:2016-04-17 19:14:54      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:

只需要重新onSaveInstanceState方法,在其里面记住我们要记录的参数

技术分享
package com.bawei.day07_videoview;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.MediaController;
import android.widget.TextView;
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);
        // 得到SD卡路径
        String path = Environment.getExternalStorageDirectory().getPath();
        videoView.setVideoPath(path + "/xiao.3gp");
        // 播放器
        MediaController controller = new MediaController(MainActivity.this);
        videoView.setMediaController(controller);
        controller.setMediaPlayer(videoView);
        videoView.start();
        // 当横屏时接着播放
        if (savedInstanceState != null) {
            // 得到进度
            int ss = savedInstanceState.getInt("aa");
            // 接着播放
            videoView.seekTo(ss);
        }

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        // TODO Auto-generated method stub
        super.onSaveInstanceState(outState);
        // 记录当前播放进度
        outState.putInt("aa", videoView.getCurrentPosition());
    }
}
技术分享

Android横竖屏切换继续播放视频

标签:

原文地址:http://www.cnblogs.com/wbp0818/p/5401798.html

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