Search in sources :

Example 1 with VideoController

use of com.byoutline.kickmaterial.views.VideoController in project kickmaterial by byoutline.

the class VideoActivity method setDataFromArgs.

private void setDataFromArgs() {
    Intent intent = getIntent();
    if (intent == null) {
        // NOI18E
        LogUtils.LOGE(TAG, "Null intent");
        return;
    }
    Bundle args = intent.getExtras();
    if (args == null) {
        // NOI18E
        LogUtils.LOGE(TAG, "Null args");
        return;
    }
    String videoUrl = args.getString(BUNDLE_VIDEO_URL);
    String altVideoUrl = args.getString(BUNDLE_ALT_VIDEO_URL);
    String webviewUrl = args.getString(BUNDLE_WEBVIEW_URL);
    Uri uri = Uri.parse(videoUrl);
    videoView.setMediaController(new VideoController(this, webviewUrl));
    videoView.setVideoURI(uri);
    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        boolean tryAltVideo = !TextUtils.isEmpty(altVideoUrl);

        @Override
        public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
            if (tryAltVideo) {
                tryAltVideo = false;
                videoView.setVideoURI(Uri.parse(altVideoUrl));
                videoView.start();
                return true;
            }
            return false;
        }
    });
    videoView.setOnCompletionListener(mediaPlayer -> finish());
    videoView.requestFocus();
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) VideoController(com.byoutline.kickmaterial.views.VideoController) Uri(android.net.Uri) MediaPlayer(android.media.MediaPlayer)

Aggregations

Intent (android.content.Intent)1 MediaPlayer (android.media.MediaPlayer)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 VideoController (com.byoutline.kickmaterial.views.VideoController)1