zoukankan      html  css  js  c++  java
  • Android播放本地视频

    代码如下:

    publicclass MainActivity extends Activity implements MediaPlayerControl {

        private VideoView videoView;

        private MediaController mediaController;

        @Override

        protectedvoid 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

        publicboolean canPause() {

            // TODO Auto-generated method stub

            returnvideoView.canPause();

        }

        @Override

        publicboolean canSeekBackward() {

            // TODO Auto-generated method stub

            returnvideoView.canSeekBackward();

        }

        @Override

        publicboolean canSeekForward() {

            // TODO Auto-generated method stub

            returnvideoView.canSeekForward();

        }

        @Override

        publicint getAudioSessionId() {

            // TODO Auto-generated method stub

            return 0;

        }

        @Override

        publicint getBufferPercentage() {

            // TODO Auto-generated method stub

            return 0;

        }

        @Override

        publicint getCurrentPosition() {

            // TODO Auto-generated method stub

            returnvideoView.getCurrentPosition();

        }

        @Override

        publicint getDuration() {

            // TODO Auto-generated method stub

            returnvideoView.getDuration();

        }

        @Override

        publicboolean isPlaying() {

            // TODO Auto-generated method stub

            returnvideoView.isPlaying();

        }

        @Override

        publicvoid pause() {

            // TODO Auto-generated method stub

            if (videoView.isPlaying()) {

                videoView.pause();

            }

        }

        @Override

        publicvoid seekTo(int postion) {

            // TODO Auto-generated method stub

            videoView.seekTo(postion);

        }

        @Override

        publicvoid start() {

            // TODO Auto-generated method stub

            videoView.start();

        }

    }

  • 相关阅读:
    智能移动机器人背后蕴含的技术——激光雷达
    Kalman Filters
    Fiddler抓HttpClient的包
    VSCode开发WebApi EFCore的坑
    WPF之小米Logo超圆角的实现
    windows react打包发布
    jenkins in docker踩坑汇总
    Using ML.NET in Jupyter notebooks 在jupyter notebook中使用ML.NET ——No design time or full build available
    【Linux知识点】CentOS7 更换阿里云源
    【Golang 报错】exec gcc executable file not found in %PATH%
  • 原文地址:https://www.cnblogs.com/Yellow0-0River/p/4242722.html
Copyright © 2011-2022 走看看