Search in sources :

Example 11 with VideoView

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

the class PreviewVideoFragment method onCreateView.

/**
     * {@inheritDoc}
     */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    Log_OC.v(TAG, "onCreateView");
    View view = inflater.inflate(R.layout.preview_video_fragment, container, false);
    mProgressBar = (ProgressBar) view.findViewById(R.id.syncProgressBar);
    DisplayUtils.colorPreLollipopHorizontalProgressBar(mProgressBar);
    mVideoPreview = (VideoView) view.findViewById(R.id.video_preview);
    mVideoPreview.setOnTouchListener(this);
    mMediaController = (MediaControlView) view.findViewById(R.id.media_controller);
    return view;
}
Also used : View(android.view.View) VideoView(android.widget.VideoView) MediaControlView(com.owncloud.android.media.MediaControlView)

Example 12 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 13 with VideoView

use of android.widget.VideoView in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class SetupWizardActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    setTheme(android.R.style.Theme_Translucent_NoTitleBar);
    super.onCreate(savedInstanceState);
    mImm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    mHandler = new SettingsPoolingHandler(this, mImm);
    setContentView(R.layout.setup_wizard);
    mSetupWizard = findViewById(R.id.setup_wizard);
    if (savedInstanceState == null) {
        mStepNumber = determineSetupStepNumberFromLauncher();
    } else {
        mStepNumber = savedInstanceState.getInt(STATE_STEP);
    }
    final String applicationName = getResources().getString(getApplicationInfo().labelRes);
    mWelcomeScreen = findViewById(R.id.setup_welcome_screen);
    final TextView welcomeTitle = (TextView) findViewById(R.id.setup_welcome_title);
    welcomeTitle.setText(getString(R.string.setup_welcome_title, applicationName));
    mSetupScreen = findViewById(R.id.setup_steps_screen);
    final TextView stepsTitle = (TextView) findViewById(R.id.setup_title);
    stepsTitle.setText(getString(R.string.setup_steps_title, applicationName));
    final SetupStepIndicatorView indicatorView = (SetupStepIndicatorView) findViewById(R.id.setup_step_indicator);
    mSetupStepGroup = new SetupStepGroup(indicatorView);
    mStep1Bullet = (TextView) findViewById(R.id.setup_step1_bullet);
    mStep1Bullet.setOnClickListener(this);
    final SetupStep step1 = new SetupStep(STEP_1, applicationName, mStep1Bullet, findViewById(R.id.setup_step1), R.string.setup_step1_title, R.string.setup_step1_instruction, R.string.setup_step1_finished_instruction, R.drawable.ic_setup_step1, R.string.setup_step1_action);
    final SettingsPoolingHandler handler = mHandler;
    step1.setAction(new Runnable() {

        @Override
        public void run() {
            invokeLanguageAndInputSettings();
            handler.startPollingImeSettings();
        }
    });
    mSetupStepGroup.addStep(step1);
    final SetupStep step2 = new SetupStep(STEP_2, applicationName, (TextView) findViewById(R.id.setup_step2_bullet), findViewById(R.id.setup_step2), R.string.setup_step2_title, R.string.setup_step2_instruction, 0, /* finishedInstruction */
    R.drawable.ic_setup_step2, R.string.setup_step2_action);
    step2.setAction(new Runnable() {

        @Override
        public void run() {
            invokeInputMethodPicker();
        }
    });
    mSetupStepGroup.addStep(step2);
    final SetupStep step3 = new SetupStep(STEP_3, applicationName, (TextView) findViewById(R.id.setup_step3_bullet), findViewById(R.id.setup_step3), R.string.setup_step3_title, R.string.setup_step3_instruction, 0, /* finishedInstruction */
    R.drawable.ic_setup_step3, R.string.setup_step3_action);
    step3.setAction(new Runnable() {

        @Override
        public void run() {
            invokeSubtypeEnablerOfThisIme();
        }
    });
    mSetupStepGroup.addStep(step3);
    mWelcomeVideoUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE).authority(getPackageName()).path(Integer.toString(R.raw.setup_welcome_video)).build();
    final VideoView welcomeVideoView = (VideoView) findViewById(R.id.setup_welcome_video);
    welcomeVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(final MediaPlayer mp) {
            // Now VideoView has been laid-out and ready to play, remove background of it to
            // reveal the video.
            welcomeVideoView.setBackgroundResource(0);
            mp.setLooping(true);
        }
    });
    welcomeVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        @Override
        public boolean onError(final MediaPlayer mp, final int what, final int extra) {
            Log.e(TAG, "Playing welcome video causes error: what=" + what + " extra=" + extra);
            hideWelcomeVideoAndShowWelcomeImage();
            return true;
        }
    });
    mWelcomeVideoView = welcomeVideoView;
    mWelcomeImageView = (ImageView) findViewById(R.id.setup_welcome_image);
    mActionStart = findViewById(R.id.setup_start_label);
    mActionStart.setOnClickListener(this);
    mActionNext = findViewById(R.id.setup_next);
    mActionNext.setOnClickListener(this);
    mActionFinish = (TextView) findViewById(R.id.setup_finish);
    TextViewCompatUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(mActionFinish, getResources().getDrawable(R.drawable.ic_setup_finish), null, null, null);
    mActionFinish.setOnClickListener(this);
}
Also used : VideoView(android.widget.VideoView) Uri(android.net.Uri) TextView(android.widget.TextView) MediaPlayer(android.media.MediaPlayer)

Example 14 with VideoView

use of android.widget.VideoView in project CameraView by CJT2325.

the class JCameraView method initView.

private void initView() {
    setWillNotDraw(false);
    this.setBackgroundColor(0xff000000);
    //VideoView
    mVideoView = new VideoView(mContext);
    LayoutParams videoViewParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    videoViewParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    mVideoView.setLayoutParams(videoViewParam);
    //mPhoto
    mPhoto = new ImageView(mContext);
    LayoutParams photoParam = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    photoParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    mPhoto.setLayoutParams(photoParam);
    mPhoto.setBackgroundColor(0xff000000);
    mPhoto.setVisibility(INVISIBLE);
    //switchCamera
    mSwitchCamera = new ImageView(mContext);
    LayoutParams imageViewParam = new LayoutParams(iconSize, iconSize);
    imageViewParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    imageViewParam.setMargins(0, iconMargin, iconMargin, 0);
    mSwitchCamera.setLayoutParams(imageViewParam);
    mSwitchCamera.setImageResource(iconSrc);
    mSwitchCamera.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isBorrow || switching || forbiddenSwitch) {
                return;
            }
            switching = true;
            new Thread() {

                /**
                     * switch camera
                     */
                @Override
                public void run() {
                    CameraInterface.getInstance().switchCamera(JCameraView.this);
                }
            }.start();
        }
    });
    //CaptureLayout
    mCaptureLayout = new CaptureLayout(mContext);
    LayoutParams layout_param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    layout_param.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layout_param.addRule(RelativeLayout.CENTER_HORIZONTAL);
    layout_param.setMargins(0, 0, 0, 40);
    mCaptureLayout.setLayoutParams(layout_param);
    mCaptureLayout.setDuration(duration);
    //mFoucsView
    mFoucsView = new FoucsView(mContext, fouce_size);
    LayoutParams foucs_param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    mFoucsView.setLayoutParams(foucs_param);
    mFoucsView.setVisibility(INVISIBLE);
    //add view to ParentLayout
    this.addView(mVideoView);
    this.addView(mPhoto);
    this.addView(mSwitchCamera);
    this.addView(mCaptureLayout);
    this.addView(mFoucsView);
    //START >>>>>>> captureLayout lisenter callback
    mCaptureLayout.setCaptureLisenter(new CaptureLisenter() {

        @Override
        public void takePictures() {
            if (CAMERA_STATE != STATE_IDLE || takePictureing) {
                return;
            }
            CAMERA_STATE = STATE_RUNNING;
            takePictureing = true;
            mFoucsView.setVisibility(INVISIBLE);
            CameraInterface.getInstance().takePicture(new CameraInterface.TakePictureCallback() {

                @Override
                public void captureResult(Bitmap bitmap) {
                    captureBitmap = bitmap;
                    CameraInterface.getInstance().doStopCamera();
                    type = TYPE_PICTURE;
                    isBorrow = true;
                    CAMERA_STATE = STATE_WAIT;
                    mPhoto.setImageBitmap(bitmap);
                    mPhoto.setVisibility(VISIBLE);
                    mCaptureLayout.startAlphaAnimation();
                    mCaptureLayout.startTypeBtnAnimator();
                    takePictureing = false;
                    mSwitchCamera.setVisibility(INVISIBLE);
                    CameraInterface.getInstance().doOpenCamera(JCameraView.this);
                }
            });
        }

        @Override
        public void recordShort(long time) {
            if (CAMERA_STATE != STATE_RUNNING && stopping) {
                return;
            }
            stopping = true;
            mCaptureLayout.setTextWithAnimation();
            postDelayed(new Runnable() {

                @Override
                public void run() {
                    CameraInterface.getInstance().stopRecord(true, new CameraInterface.StopRecordCallback() {

                        @Override
                        public void recordResult(String url) {
                            Log.i(TAG, "stopping ...");
                            mCaptureLayout.isRecord(false);
                            CAMERA_STATE = STATE_IDLE;
                            stopping = false;
                            isBorrow = false;
                        }
                    });
                }
            }, 1500 - time);
        }

        @Override
        public void recordStart() {
            if (CAMERA_STATE != STATE_IDLE && stopping) {
                return;
            }
            mCaptureLayout.isRecord(true);
            isBorrow = true;
            CAMERA_STATE = STATE_RUNNING;
            mFoucsView.setVisibility(INVISIBLE);
            CameraInterface.getInstance().startRecord(mVideoView.getHolder().getSurface(), new CameraInterface.ErrorCallback() {

                @Override
                public void onError() {
                    Log.i("CJT", "startRecorder error");
                    mCaptureLayout.isRecord(false);
                    CAMERA_STATE = STATE_WAIT;
                    stopping = false;
                    isBorrow = false;
                }
            });
        }

        @Override
        public void recordEnd(long time) {
            CameraInterface.getInstance().stopRecord(false, new CameraInterface.StopRecordCallback() {

                @Override
                public void recordResult(final String url) {
                    CAMERA_STATE = STATE_WAIT;
                    videoUrl = url;
                    type = TYPE_VIDEO;
                    new Thread(new Runnable() {

                        @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
                        @Override
                        public void run() {
                            try {
                                if (mMediaPlayer == null) {
                                    mMediaPlayer = new MediaPlayer();
                                } else {
                                    mMediaPlayer.reset();
                                }
                                Log.i("CJT", "URL = " + url);
                                mMediaPlayer.setDataSource(url);
                                mMediaPlayer.setSurface(mVideoView.getHolder().getSurface());
                                mMediaPlayer.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT);
                                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                                mMediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {

                                    @Override
                                    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
                                        updateVideoViewSize(mMediaPlayer.getVideoWidth(), mMediaPlayer.getVideoHeight());
                                    }
                                });
                                mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

                                    @Override
                                    public void onPrepared(MediaPlayer mp) {
                                        mMediaPlayer.start();
                                    }
                                });
                                mMediaPlayer.setLooping(true);
                                mMediaPlayer.prepare();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }).start();
                }
            });
        }

        @Override
        public void recordZoom(float zoom) {
            CameraInterface.getInstance().setZoom(zoom, CameraInterface.TYPE_RECORDER);
        }
    });
    mCaptureLayout.setTypeLisenter(new TypeLisenter() {

        @Override
        public void cancel() {
            if (CAMERA_STATE == STATE_WAIT) {
                if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
                    mMediaPlayer.stop();
                    mMediaPlayer.release();
                    mMediaPlayer = null;
                }
                //                    CameraInterface.getInstance().doOpenCamera(JCameraView.this);
                handlerPictureOrVideo(type, false);
            }
        }

        @Override
        public void confirm() {
            if (CAMERA_STATE == STATE_WAIT) {
                if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
                    mMediaPlayer.stop();
                    mMediaPlayer.release();
                    mMediaPlayer = null;
                }
                //                    CameraInterface.getInstance().doOpenCamera(JCameraView.this);
                handlerPictureOrVideo(type, true);
            }
        }
    });
    mCaptureLayout.setReturnLisenter(new ReturnLisenter() {

        @Override
        public void onReturn() {
            if (jCameraLisenter != null && !takePictureing) {
                jCameraLisenter.quit();
            }
        }
    });
    //END >>>>>>> captureLayout lisenter callback
    mVideoView.getHolder().addCallback(this);
}
Also used : CaptureLisenter(com.cjt2325.cameralibrary.lisenter.CaptureLisenter) VideoView(android.widget.VideoView) Bitmap(android.graphics.Bitmap) ReturnLisenter(com.cjt2325.cameralibrary.lisenter.ReturnLisenter) ImageView(android.widget.ImageView) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) VideoView(android.widget.VideoView) TypeLisenter(com.cjt2325.cameralibrary.lisenter.TypeLisenter) MediaPlayer(android.media.MediaPlayer)

Example 15 with VideoView

use of android.widget.VideoView in project ABPlayer by winkstu.

the class MainActivity method findViews.

private void findViews() {
    mMediaController = findViewById(R.id.media_controller);
    mBtnRotate = (Button) findViewById(R.id.rotate);
    mBtnHideDanmaku = (Button) findViewById(R.id.btn_hide);
    mBtnShowDanmaku = (Button) findViewById(R.id.btn_show);
    mBtnPauseDanmaku = (Button) findViewById(R.id.btn_pause);
    mBtnResumeDanmaku = (Button) findViewById(R.id.btn_resume);
    mBtnSendDanmaku = (Button) findViewById(R.id.btn_send);
    mBtnSendDanmakus = (Button) findViewById(R.id.btn_send_danmakus);
    mBtnRotate.setOnClickListener(this);
    mBtnHideDanmaku.setOnClickListener(this);
    mMediaController.setOnClickListener(this);
    mBtnShowDanmaku.setOnClickListener(this);
    mBtnPauseDanmaku.setOnClickListener(this);
    mBtnResumeDanmaku.setOnClickListener(this);
    mBtnSendDanmaku.setOnClickListener(this);
    mBtnSendDanmakus.setOnClickListener(this);
    // VideoView
    VideoView mVideoView = (VideoView) findViewById(R.id.videoview);
    // DanmakuView
    mDanmakuView = (IDanmakuView) findViewById(R.id.sv_danmaku);
    DanmakuGlobalConfig.DEFAULT.setDanmakuStyle(DanmakuGlobalConfig.DANMAKU_STYLE_STROKEN, 3).setDuplicateMergingEnabled(false);
    if (mDanmakuView != null) {
        mParser = createParser(this.getResources().openRawResource(R.raw.comments));
        mDanmakuView.setCallback(new Callback() {

            @Override
            public void updateTimer(DanmakuTimer timer) {
            }

            @Override
            public void prepared() {
                mDanmakuView.start();
            }
        });
        mDanmakuView.prepare(mParser);
        mDanmakuView.showFPS(true);
        mDanmakuView.enableDanmakuDrawingCache(true);
        ((View) mDanmakuView).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mMediaController.setVisibility(View.VISIBLE);
            }
        });
    }
    if (mVideoView != null) {
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.start();
            }
        });
        // mVideoView.setVideoPath(Environment.getExternalStorageDirectory() + "/1.flv");
        mVideoView.setVideoURI(Uri.parse("http://us-chicago.acgvideo.com/e/e9/3444659.mp4?expires=1429119900&ssig=o8fAECKGmZkIsdZE31EYOQ&o=401361084&rate=0"));
    }
}
Also used : Callback(master.flame.danmaku.controller.DrawHandler.Callback) VideoView(android.widget.VideoView) DanmakuTimer(master.flame.danmaku.danmaku.model.DanmakuTimer) View(android.view.View) VideoView(android.widget.VideoView) DanmakuSurfaceView(master.flame.danmaku.ui.widget.DanmakuSurfaceView) IDanmakuView(master.flame.danmaku.controller.IDanmakuView) MediaPlayer(android.media.MediaPlayer)

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