Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I also wanted my VideoView to be in a paused state when the activity started. I could not find a simple way to have the VideoView show the first (non-black) frame of the video. </p> <p>As a workaround, I created a bitmap thumbnail from the video resource, and then place that thumbnail as the background to the VideoView on activity start. Then when the Video begins playing, you only need to null out the background (or else your playing video is hidden behind your background image).</p> <pre><code>Bitmap thumbAsBitmap = null; BitmapDrawable thumbAsDrawable = null; private String current; private void setupVideo() { try { setVideoFilePath(); if (current == null || current.length() == 0) { Toast.makeText(PreviewMessage.this, "File URL/path is empty", Toast.LENGTH_LONG).show(); } else { keepScreenOn(); mVideoView.setVideoPath(getDataSource(current)); mVideoView.setOnCompletionListener(this); // create and place a thumbnail for the start state thumbAsBitmap = ThumbnailUtils.createVideoThumbnail(current, MediaStore.Images.Thumbnails.MINI_KIND); thumbAsDrawable = new BitmapDrawable(thumbAsBitmap); mVideoView.setBackgroundDrawable(thumbAsDrawable); mVideoView.pause(); isPlaying = false; } } catch (Exception e) { if (mVideoView != null) { mVideoView.stopPlayback(); } } } </code></pre> <p>Then whereever your playbutton is, you can do something like</p> <pre><code> mPlay.setOnClickListener(new OnClickListener() { public void onClick(View view) { if(!isPlaying){ keepScreenOn(); mPlay.setText("Pause"); // make sure to null the background so you can see your video play mVideoView.setBackgroundDrawable(null); mVideoView.start(); isPlaying = true; } else { mPlay.setText("Play"); mVideoView.pause(); isPlaying = false; } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload