Search in sources :

Example 21 with VideoView

use of android.widget.VideoView in project android_frameworks_base by crdroidandroid.

the class VideoViewCaptureActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mVideoView = new VideoView(this);
    mVideoView.setOnPreparedListener(mp -> {
        mp.setLooping(true);
        mVideoWidth = mp.getVideoWidth();
        mVideoHeight = mp.getVideoHeight();
        mVideoView.start();
    });
    Uri uri = Uri.parse("android.resource://com.android.test.hwui/" + R.raw.colorgrid_video);
    mVideoView.setVideoURI(uri);
    Button button = new Button(this);
    button.setText("Copy bitmap to /sdcard/surfaceview.png");
    button.setOnClickListener((View v) -> {
        final Bitmap b = Bitmap.createBitmap(mVideoWidth, mVideoHeight, Bitmap.Config.ARGB_8888);
        PixelCopy.request(mVideoView, b, (int result) -> {
            if (result != PixelCopy.SUCCESS) {
                Toast.makeText(VideoViewCaptureActivity.this, "Failed to copy", Toast.LENGTH_SHORT).show();
                return;
            }
            try {
                try (FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/surfaceview.png")) {
                    b.compress(Bitmap.CompressFormat.PNG, 100, out);
                }
            } catch (Exception e) {
            // Ignore
            }
        }, mVideoView.getHandler());
    });
    FrameLayout content = new FrameLayout(this);
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(button, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.addView(mVideoView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    content.addView(layout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
    setContentView(content);
}
Also used : Bitmap(android.graphics.Bitmap) Button(android.widget.Button) VideoView(android.widget.VideoView) FileOutputStream(java.io.FileOutputStream) FrameLayout(android.widget.FrameLayout) Uri(android.net.Uri) View(android.view.View) VideoView(android.widget.VideoView) LinearLayout(android.widget.LinearLayout)

Aggregations

VideoView (android.widget.VideoView)21 View (android.view.View)13 MediaPlayer (android.media.MediaPlayer)10 Uri (android.net.Uri)8 Bitmap (android.graphics.Bitmap)7 FrameLayout (android.widget.FrameLayout)6 Button (android.widget.Button)5 LinearLayout (android.widget.LinearLayout)5 TextView (android.widget.TextView)4 FileOutputStream (java.io.FileOutputStream)4 ImageView (android.widget.ImageView)3 IOException (java.io.IOException)3 IDanmakuView (master.flame.danmaku.controller.IDanmakuView)3 DanmakuTimer (master.flame.danmaku.danmaku.model.DanmakuTimer)3 OnClickListener (android.view.View.OnClickListener)2 MediaController (android.widget.MediaController)2 HashMap (java.util.HashMap)2 BaseDanmaku (master.flame.danmaku.danmaku.model.BaseDanmaku)2 IDanmakus (master.flame.danmaku.danmaku.model.IDanmakus)2 LightningView (acr.browser.lightning.view.LightningView)1