Search in sources :

Example 26 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)

Example 27 with VideoView

use of android.widget.VideoView in project platform_frameworks_base by android.

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)

Example 28 with VideoView

use of android.widget.VideoView in project krypton-android by kryptco.

the class GeneratingFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_generating, container, false);
    final View animationContainer = root.findViewById(R.id.animationContainer);
    this.anim = (VideoView) root.findViewById(R.id.generateAnimation);
    final VideoView anim = this.anim;
    anim.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            anim.post(new Runnable() {

                @Override
                public void run() {
                    anim.start();
                }
            });
        }
    });
    anim.setOnInfoListener(new MediaPlayer.OnInfoListener() {

        @Override
        public boolean onInfo(MediaPlayer mp, int what, int extra) {
            if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
                // video started
                animationContainer.setVisibility(View.VISIBLE);
                return true;
            }
            return false;
        }
    });
    anim.setVideoURI(Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.generate_animation));
    anim.seekTo(0);
    return root;
}
Also used : VideoView(android.widget.VideoView) View(android.view.View) VideoView(android.widget.VideoView) MediaPlayer(android.media.MediaPlayer)

Example 29 with VideoView

use of android.widget.VideoView in project tlplib by tinylabproductions.

the class AndroidVideoPlayer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.media_player_layout);
    VideoView videoView = (VideoView) findViewById(R.id.video_display);
    Button closeButton = (Button) findViewById(R.id.close_button);
    // This is needed so the listener wouldn't change if for some reason new Activity was created before closing the first one
    final VideoPlayerListener listenerInstance = listener;
    Intent intent = getIntent();
    final String fileName = intent.getStringExtra(FILE_NAME);
    final String urlToOpen = intent.getStringExtra(URL_TO_OPEN);
    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            if (listenerInstance != null)
                listenerInstance.onVideoComplete();
            openUrl(urlToOpen);
        }
    });
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (listenerInstance != null)
                listenerInstance.onCancel();
            closeActivity();
        }
    });
    videoView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (listenerInstance != null)
                listenerInstance.onVideoClick();
            openUrl(urlToOpen);
            return true;
        }
    });
    File file = extractFromResource("/assets/" + fileName);
    if (file != null) {
        videoView.setVideoPath(file.getAbsolutePath());
        videoView.requestFocus();
        videoView.start();
    } else
        closeActivity();
}
Also used : VideoView(android.widget.VideoView) Intent(android.content.Intent) View(android.view.View) VideoView(android.widget.VideoView) MotionEvent(android.view.MotionEvent) Button(android.widget.Button) File(java.io.File) MediaPlayer(android.media.MediaPlayer)

Example 30 with VideoView

use of android.widget.VideoView in project mytarget-android by myTargetSDK.

the class InstreamAdActivity method startVideo.

public void startVideo(View view) {
    if (instreamAd == null)
        return;
    videoView = new VideoView(this);
    FrameLayout.LayoutParams videoPlayerParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    videoPlayerParams.gravity = Gravity.CENTER;
    videoFrame.addView(videoView, videoPlayerParams);
    playButton.setVisibility(View.GONE);
    FrameLayout.LayoutParams adPlayerParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    adPlayerParams.gravity = Gravity.CENTER;
    View adPlayerView = instreamAd.getPlayer().getView();
    if (adPlayerView.getParent() == null)
        videoFrame.addView(adPlayerView, adPlayerParams);
    instreamAdController.setSkipListener(this);
    instreamAdController.setAdClickListener(this);
    instreamAdController.setAnchorView(videoFrame);
    instreamAdController.setVisibility(View.VISIBLE);
    startPreroll();
}
Also used : VideoView(android.widget.VideoView) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) View(android.view.View) VideoView(android.widget.VideoView)

Aggregations

VideoView (android.widget.VideoView)44 View (android.view.View)25 MediaPlayer (android.media.MediaPlayer)13 TextView (android.widget.TextView)12 FrameLayout (android.widget.FrameLayout)10 ImageView (android.widget.ImageView)9 Uri (android.net.Uri)8 Button (android.widget.Button)7 Bitmap (android.graphics.Bitmap)6 LinearLayout (android.widget.LinearLayout)6 MediaController (android.widget.MediaController)6 Intent (android.content.Intent)5 WebView (android.webkit.WebView)5 MotionEvent (android.view.MotionEvent)3 OnClickListener (android.view.View.OnClickListener)3 AdapterView (android.widget.AdapterView)3 FileOutputStream (java.io.FileOutputStream)3 KeyEvent (android.view.KeyEvent)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 HorizontalScrollView (android.widget.HorizontalScrollView)2