Java Code Examples for android.widget.VideoView#requestFocus()

The following examples show how to use android.widget.VideoView#requestFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoViewDemo.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.videoview);
    mVideoView = (VideoView) findViewById(R.id.surface_view);

    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(
                VideoViewDemo.this,
                "Please edit VideoViewDemo Activity, and set path"
                        + " variable to your media file URL/path",
                Toast.LENGTH_LONG).show();

    } else {

        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();

    }
}
 
Example 2
Source File: Activity_VideoSurveillance.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
private void initView() {
    pg=new ProgressDialog(Activity_VideoSurveillance.this);
    pg.setMessage("缓冲中...");
    pg.show();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("");
    TextView toolbarText = (TextView) findViewById(R.id.toolbar_text);
    toolbarText.setText("视频监控");
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (!Util.checkNetwork(this)) {
        return;
    }
    videoViewVideo = (VideoView) findViewById(R.id.videoViewVideo);

    try {
        //设置视频控制器
        MediaController mediacontroller = new MediaController(Activity_VideoSurveillance.this);
        mediacontroller.setAnchorView(videoViewVideo);
        videoViewVideo.setMediaController(mediacontroller);
        //视频来源
        videoViewVideo.setVideoURI(Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
    } catch (Exception e) {
        e.printStackTrace();
        pg.dismiss();
    }
    videoViewVideo.requestFocus();
    videoViewVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pg.dismiss();
            //开始播放视频
            videoViewVideo.start();
        }
    });
}
 
Example 3
Source File: VideocastActivity.java    From AnotherRSS with The Unlicense 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_videoweb);
    VideoView videoView = (VideoView) findViewById(R.id.videoView);
    WebView webView = (WebView) findViewById(R.id.webView);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    Intent intent = getIntent();
    Uri uri = intent.getData();
    if (uri != null) {
        String url = uri.toString();
        if (url.endsWith(".mp4")) {
            webView.setVisibility(View.GONE);
            progressBar.setVisibility(View.GONE);
            videoView.setVisibility(View.VISIBLE);
            videoView.setMediaController(AnotherRSS.mediaController);
            videoView.setVideoURI(uri);
            videoView.requestFocus();
            videoView.start();
        } else {
            webView.setVisibility(View.VISIBLE);
            progressBar.setVisibility(View.VISIBLE);
            videoView.setVisibility(View.GONE);
            webView.setWebViewClient(new MyWebClient());
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setUseWideViewPort(true);
            webView.loadUrl(url);
        }
    }
}
 
Example 4
Source File: VideoFragment.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mMediaController = new MediaController(getContext());
    mVideoView = (VideoView) view.findViewById(R.id.video);
    mVideoView.setVideoPath(mVideoUrl);
    mVideoView.setMediaController(mMediaController);
    mVideoView.requestFocus();
}
 
Example 5
Source File: SingleVideoActivity.java    From BaldPhone with Apache License 2.0 4 votes vote down vote up
@Override
protected void bindView(View v, Cursor cursor, Context context) {
    final VideoView videoView = v.findViewById(R.id.vid);
    final ImageView play_stop = v.findViewById(R.id.play_stop);

    videoView.setOnPreparedListener(mp -> {
        float videoProportion = (float) mp.getVideoWidth() / (float) mp.getVideoHeight();
        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) videoView.getLayoutParams();
        lp.dimensionRatio = String.valueOf(videoProportion);
        videoView.setLayoutParams(lp);

    });

    final Uri uri = Uri.parse(cursor.getString(
            cursor.getColumnIndex(MediaStore.Images.Media.DATA)
    ));
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.seekTo(1);
    videoView.setOnCompletionListener(mp -> {
        play_stop.setImageResource(R.drawable.replay_on_background);
        Toggeler.newImageToggeler(
                play_stop,
                play_stop,
                new int[]{R.drawable.stop_on_background, R.drawable.play_on_background},
                new View.OnClickListener[]{
                        view -> videoView.start(),
                        view -> videoView.pause()
                });
    });

    Toggeler.newImageToggeler(
            play_stop,
            play_stop,
            new int[]{R.drawable.stop_on_background, R.drawable.play_on_background},
            new View.OnClickListener[]{
                    view -> videoView.start(),
                    view -> videoView.pause()
            });

    ((VideoViewWrapper) v).setOnShowedChangedListener(shown -> {
        if (shown) {
            videoView.seekTo(1);
            Toggeler.newImageToggeler(
                    play_stop,
                    play_stop,
                    new int[]{R.drawable.stop_on_background, R.drawable.play_on_background},
                    new View.OnClickListener[]{
                            view -> videoView.start(),
                            view -> videoView.pause()
                    });
            play_stop.setImageResource(R.drawable.play_on_background);
            videoView.start();
            videoView.pause();
        } else
            videoView.pause();
    });

}
 
Example 6
Source File: PlayerActivity.java    From android with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        url = getIntent().getStringExtra(KEY_URL);
        url = "http://jzvd.nathen.cn/c6e3dc12a1154626b3476d9bf3bd7266/6b56c5f0dc31428083757a45764763b0-5287d2089db37e62345123a1be272f8b.mp4";
        if (url == null && savedInstanceState != null) {
            url = savedInstanceState.getString(KEY_URL);
        }

        if (url == null) {
            Toast.makeText(getApplicationContext(), TOAST_ERROR_URL, Toast.LENGTH_LONG).show();
            finish();
            return;
        }

        setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);

        videoView = new VideoView(this);
        videoView.setVideoURI(Uri.parse(url));
        videoView.requestFocus();
        videoView.setOnPreparedListener(this);
        videoView.setOnCompletionListener(this);
        videoView.setOnErrorListener(this);

        mc = new MediaController(this);
        mc.setAnchorView(videoView);
        mc.setKeepScreenOn(true);

        videoView.setMediaController(mc);

        llMain = new LinearLayout(this);
        llMain.setGravity(Gravity.CENTER_VERTICAL);
        llMain.setOrientation(LinearLayout.VERTICAL);
        llMain.setLayoutParams(params);

        llMain.addView(videoView, params);
        setContentView(llMain);

        initDialog();
    }
 
Example 7
Source File: VideoPlayerActivity.java    From media-for-mobile with Apache License 2.0 3 votes vote down vote up
private void init() {
    mVideoView = (VideoView) findViewById(R.id.video_view);

    mVideoController = new MediaController(this, false);

    mVideoView.setMediaController(mVideoController);

    mVideoView.requestFocus();
    mVideoView.setZOrderOnTop(true);
}