Android导入视频


package com.hui.weblab;


import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;

public class androidmanifest4 extends Activity {
    private VideoView mVideoView;
    private Button playBtn, stopBtn;
    MediaController mMediaController;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.androidmanifest);
        mVideoView = new VideoView(this);
        mVideoView = (VideoView) findViewById(R.id.video);
        mMediaController = new MediaController(this);
        playBtn = (Button) findViewById(R.id.playbutton);
        stopBtn = (Button) findViewById(R.id.stopbutton);
        playBtn.setOnClickListener(new mClick());
        stopBtn.setOnClickListener(new mClick());
    }

    class mClick implements View.OnClickListener {
        @Override
        public void onClick(View v) {

            String uri = "android.resource://" + getPackageName() + "/" + R.raw.b_6;

            mVideoView.setVideoURI(Uri.parse(uri));
            mMediaController.setMediaPlayer(mVideoView);
            mVideoView.setMediaController(mMediaController);
            if (v == playBtn) {
                mVideoView.start();
            } else if (v == stopBtn) {
                mVideoView.stopPlayback();
            }
        }
    }
}

  

原创文章,作者:kirin,如若转载,请注明出处:https://blog.ytso.com/273008.html

(0)
上一篇 2022年7月9日
下一篇 2022年7月9日

相关推荐

发表回复

登录后才能评论