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

The following examples show how to use android.widget.VideoView#setOnCompletionListener() . 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: VideoTrimActivity.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
private void init(String videoPath) {
    setContentView(R.layout.activity_trim);
    TextView duration = (TextView) findViewById(R.id.duration);
    mPreview = (VideoView) findViewById(R.id.preview);

    mShortVideoTrimmer = new PLShortVideoTrimmer(this, videoPath, Config.TRIM_FILE_PATH);
    mMediaFile = new PLMediaFile(videoPath);

    mSelectedEndMs = mDurationMs = mMediaFile.getDurationMs();
    duration.setText("时长: " + formatTime(mDurationMs));
    Log.i(TAG, "video duration: " + mDurationMs);

    mVideoFrameCount = mMediaFile.getVideoFrameCount(false);
    Log.i(TAG, "video frame count: " + mVideoFrameCount);

    mPreview.setVideoPath(videoPath);
    mPreview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            play();
        }
    });

    initVideoFrameList();
}
 
Example 2
Source File: BrowserActivity.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
	if (view == null) {
		return;
	}
	if (mCustomView != null && callback != null) {
		callback.onCustomViewHidden();
		return;
	}
	try {
		view.setKeepScreenOn(true);
	} catch (SecurityException e) {
		Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
	}
	mOriginalOrientation = getRequestedOrientation();
	FrameLayout decor = (FrameLayout) getWindow().getDecorView();
	mFullscreenContainer = new FullscreenHolder(this);
	mCustomView = view;
	mFullscreenContainer.addView(mCustomView, COVER_SCREEN_PARAMS);
	decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
	setFullscreen(true);
	getCurrentWebView().setVisibility(View.GONE);
	if (view instanceof FrameLayout) {
		if (((FrameLayout) view).getFocusedChild() instanceof VideoView) {
			mVideoView = (VideoView) ((FrameLayout) view).getFocusedChild();
			mVideoView.setOnErrorListener(new VideoCompletionListener());
			mVideoView.setOnCompletionListener(new VideoCompletionListener());
		}
	}
	mCustomViewCallback = callback;
}
 
Example 3
Source File: PreviewVideoActivity.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Called when the activity is first created.
 *
 *  Searches for an {@link OCFile} and ownCloud {@link Account} holding it in the starting {@link Intent}.
 *
 *  The {@link Account} is unnecessary if the file is downloaded; else, the {@link Account} is used to
 *  try to stream the remote file - TODO get the streaming works
 *
 *  {@inheritDoc}
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log_OC.v(TAG, "onCreate");

    setContentView(R.layout.video_layout);

    if (savedInstanceState == null) {
        Bundle extras = getIntent().getExtras();
        mSavedPlaybackPosition = extras.getInt(EXTRA_START_POSITION);
        mAutoplay = extras.getBoolean(EXTRA_AUTOPLAY);

    } else {
        mSavedPlaybackPosition = savedInstanceState.getInt(EXTRA_START_POSITION);
        mAutoplay = savedInstanceState.getBoolean(EXTRA_AUTOPLAY);
    }

    mVideoPlayer = (VideoView) findViewById(R.id.videoPlayer);

    // set listeners to get more contol on the playback
    mVideoPlayer.setOnPreparedListener(this);
    mVideoPlayer.setOnCompletionListener(this);
    mVideoPlayer.setOnErrorListener(this);

    // keep the screen on while the playback is performed (prevents screen off by battery save)
    mVideoPlayer.setKeepScreenOn(true);
}
 
Example 4
Source File: VideoPlayerActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
protected void initViews() {
	mSpinningProgressBar = (ProgressBar) findViewById( R.id.progress_spinner );

	mVideoView = (VideoView) findViewById( R.id.video_view );
	mVideoView.setOnCompletionListener( onCompletionListener );
	mVideoView.setOnErrorListener( onErrorListener );
	mVideoView.setOnPreparedListener( onPreparedListener );

	if( mVideoView == null ) {
		throw new IllegalArgumentException( "Layout must contain a video view with ID video_view" );
	}

	mUri = Uri.parse( getIntent().getExtras().getString( EXTRA_VIDEO_URL ) );
	mVideoView.setVideoURI( mUri );
}
 
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: VideoEnabledWebChromeClient.java    From carstream-android-auto with Apache License 2.0 4 votes vote down vote up
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
    Log.d(getClass().getName(), "onShowCustomView() called with: view = [" + view + "], callback = [" + callback + "]");
    if (view instanceof FrameLayout) {

        // A video wants to be shown
        FrameLayout frameLayout = (FrameLayout) view;
        View focusedChild = frameLayout.getFocusedChild();
        if (focusedChild != null) {
            focusedChild.requestFocus();
            focusedChild.setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if (event.getAction() == KeyEvent.ACTION_DOWN) {
                        if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                            webView.goBack();
                            return true;
                        }
                    }
                    return false;
                }
            });
        }

        // Save video related variables
        this.isVideoFullscreen = true;
        this.videoViewContainer = frameLayout;
        this.videoViewCallback = callback;

        // Hide the non-video view, add the video view, and show it
        activityNonVideoView.setVisibility(View.INVISIBLE);
        activityVideoView.addView(videoViewContainer, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        activityVideoView.setVisibility(View.VISIBLE);
        activityVideoView.setBackgroundColor(Color.BLACK);
        if (focusedChild != null) {
            focusedChild.setBackgroundColor(Color.BLACK);
            if (videoTouchListener != null) {
                focusedChild.setOnTouchListener(videoTouchListener);
            }
        }


        if (focusedChild instanceof VideoView) {
            // VideoView (typically API level <11)
            VideoView videoView = (VideoView) focusedChild;
            // Handle all the required events
            videoView.setOnPreparedListener(this);
            videoView.setOnCompletionListener(this);
            videoView.setOnErrorListener(this);
        } else // Usually android.webkit.HTML5VideoFullScreen$VideoSurfaceView, sometimes android.webkit.HTML5VideoFullScreen$VideoTextureView
        {
            // HTML5VideoFullScreen (typically API level 11+)
            // Handle HTML5 video ended event
            if (webView != null && webView.getSettings().getJavaScriptEnabled()) {
                // Run javascript code that detects the video end and notifies the interface
                handleVideoStretching();
            }
        }

        // Notify full-screen change
        if (toggledFullscreenCallback != null) {
            toggledFullscreenCallback.toggledFullscreen(true);
        }
    }
}
 
Example 7
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();
    }