Java Code Examples for com.google.android.exoplayer2.ui.PlayerView#setPlayer()

The following examples show how to use com.google.android.exoplayer2.ui.PlayerView#setPlayer() . 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: VideoActivity.java    From arcusandroid with Apache License 2.0 7 votes vote down vote up
private void initializePlayer() {
    CameraPreviewGetter.instance().pauseUpdates();

    PlayerView video = findViewById(R.id.video_view);
    video.setUseController(playbackModel.getType() == PlaybackModel.PlaybackType.CLIP);
    video.requestFocus();

    TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(DEFAULT_BANDWIDTH_METER);
    player = ExoPlayerFactory.newSimpleInstance(
            new DefaultRenderersFactory(this),
            new DefaultTrackSelector(trackSelectionFactory),
            new DefaultLoadControl()
    );

    video.setPlayer(player);

    String userAgent = Util.getUserAgent(this, getPackageName());
    DataSource.Factory dsf = new DefaultDataSourceFactory(this, userAgent);
    MediaSource mediaSource = new HlsMediaSource.Factory(dsf).createMediaSource(Uri.parse(playbackModel.getUrl()));

    player.prepare(mediaSource);
    player.addListener(eventListener);

    player.setPlayWhenReady(playWhenReady);
    player.seekTo(currentWindow, playbackPosition);
}
 
Example 2
Source File: MainActivity.java    From lbry-android with MIT License 6 votes vote down vote up
private void renderPictureInPictureMode() {
    findViewById(R.id.content_main).setVisibility(View.GONE);
    findViewById(R.id.floating_balance_main_container).setVisibility(View.GONE);
    findViewById(R.id.global_now_playing_card).setVisibility(View.GONE);
    findViewById(R.id.global_sdk_initializing_status).setVisibility(View.GONE);
    findViewById(R.id.app_bar_main_container).setFitsSystemWindows(true);
    hideActionBar();

    for (PIPModeListener listener : pipModeListeners) {
        listener.onEnterPIPMode();
    }

    View pipPlayerContainer = findViewById(R.id.pip_player_container);
    PlayerView pipPlayer = findViewById(R.id.pip_player);
    pipPlayer.setPlayer(appPlayer);
    pipPlayer.setUseController(false);
    pipPlayerContainer.setVisibility(View.VISIBLE);
    playerReassigned = true;
}
 
Example 3
Source File: MainActivity.java    From lbry-android with MIT License 6 votes vote down vote up
public void checkNowPlaying() {
    Fragment fragment = getCurrentFragment();
    if (fragment instanceof FileViewFragment) {
        return;
    }

    if (nowPlayingClaim != null) {
        findViewById(R.id.global_now_playing_card).setVisibility(View.VISIBLE);
        ((TextView) findViewById(R.id.global_now_playing_title)).setText(nowPlayingClaim.getTitle());
        ((TextView) findViewById(R.id.global_now_playing_channel_title)).setText(nowPlayingClaim.getPublisherTitle());
    }
    if (appPlayer != null) {
        PlayerView playerView = findViewById(R.id.global_now_playing_player_view);
        playerView.setPlayer(null);
        playerView.setPlayer(appPlayer);
        playerView.setUseController(false);
        playerReassigned = true;

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
}
 
Example 4
Source File: DefaultPlayer.java    From ARVI with Apache License 2.0 5 votes vote down vote up
@Override
public final void attach(@NonNull final PlayerView playerView) {
    Preconditions.nonNull(playerView);
    checkPlayerState();

    playerView.setPlayer(this.exoPlayer);
}
 
Example 5
Source File: DefaultPlayer.java    From ARVI with Apache License 2.0 5 votes vote down vote up
@Override
public final void detach(@NonNull PlayerView playerView) {
    Preconditions.nonNull(playerView);
    checkPlayerState();

    playerView.setPlayer(null);
}
 
Example 6
Source File: MainActivity.java    From lbry-android with MIT License 5 votes vote down vote up
private void renderFullMode() {
    if (!inFullscreenMode) {
        showActionBar();
    } else {
        findViewById(R.id.app_bar_main_container).setFitsSystemWindows(false);
    }

    findViewById(R.id.content_main).setVisibility(View.VISIBLE);
    Fragment fragment = getCurrentFragment();
    boolean canShowFloatingBalance = fragment == null ||
            fragment instanceof FollowingFragment ||
            fragment instanceof FileViewFragment ||
            fragment instanceof ChannelFragment ||
            fragment instanceof EditorsChoiceFragment ||
            fragment instanceof AllContentFragment ||
            fragment instanceof LibraryFragment ||
            fragment instanceof SearchFragment;
    findViewById(R.id.floating_balance_main_container).setVisibility(!canShowFloatingBalance || inFullscreenMode ? View.INVISIBLE : View.VISIBLE);
    if (!(fragment instanceof FileViewFragment) && !inFullscreenMode) {
        findViewById(R.id.global_now_playing_card).setVisibility(View.VISIBLE);
    }
    if (!Lbry.SDK_READY && !inFullscreenMode) {
        findViewById(R.id.global_sdk_initializing_status).setVisibility(View.VISIBLE);
    }
    for (PIPModeListener listener : pipModeListeners) {
        listener.onExitPIPMode();
    }

    View pipPlayerContainer = findViewById(R.id.pip_player_container);
    PlayerView pipPlayer = findViewById(R.id.pip_player);
    pipPlayer.setPlayer(null);
    pipPlayerContainer.setVisibility(View.INVISIBLE);
    playerReassigned = true;
}
 
Example 7
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
public void onResume() {
    super.onResume();
    checkParams();

    Context context = getContext();
    Helper.setWunderbarValue(currentUrl, context);
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        LbryAnalytics.setCurrentScreen(activity, "File", "File");
        if (claim != null && claim.isPlayable() && activity.isInFullscreenMode()) {
            enableFullScreenMode();
        }
    }

    if (MainActivity.appPlayer != null) {
        if (MainActivity.playerReassigned) {
            setPlayerForPlayerView();
            MainActivity.playerReassigned = false;
        }

        View root = getView();
        if (root != null) {
            PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
            if (playerView.getPlayer() == null) {
                playerView.setPlayer(MainActivity.appPlayer);
            }
        }

        loadAndScheduleDurations();
    }

    if (!Lbry.SDK_READY) {
        if (context instanceof MainActivity) {
            ((MainActivity) context).addSdkStatusListener(this);
        }
    } else {
        onSdkReady();
    }
    checkCommentSdkInitializing();
}
 
Example 8
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
private void setPlayerForPlayerView() {
    View root = getView();
    if (root != null) {
        PlayerView view = root.findViewById(R.id.file_view_exoplayer_view);
        view.setPlayer(null);
        view.setPlayer(MainActivity.appPlayer);
    }
}
 
Example 9
Source File: MediaPlayerSingleton.java    From dtube-mobile-unofficial with Apache License 2.0 4 votes vote down vote up
private void init(Activity c) {
    embeddedPlayer = new WebViewVideoView(c,false);

    playerView = new PlayerView(c);
    player = ExoPlayerFactory.newSimpleInstance(c);
    playerView.setShowBuffering(SHOW_BUFFERING_ALWAYS);
    playerView.setPlayer(player);

    this.c = c;

    UiModeManager uiModeManager = (UiModeManager) c.getSystemService(UI_MODE_SERVICE);

    if (uiModeManager.getCurrentModeType()== Configuration.UI_MODE_TYPE_TELEVISION) {
        playerView.findViewById(R.id.exo_fullscreen_button).setVisibility(View.GONE);
        int extraPadding = Tools.numtodp(20, c);
        playerView.findViewById(R.id.control_bar_holder).setPadding(extraPadding,0,extraPadding,extraPadding);
    }

    player.addListener(new Player.EventListener() {
        @Override
        public void onLoadingChanged(boolean isLoading) {

        }

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

        }

        @Override
        public void onPlayerError(ExoPlaybackException error) {
            //hadErrorLoading = true;
            if (!videoToPlay.hasTriedLoadingBackupGateway()){
                //try loading backup stream
                Log.d("dtube3","BACKUP LOAD "+videoToPlay.getBackupVideoStreamURL());
                player.prepare(getMediaSource(videoToPlay.getBackupVideoStreamURL()));
                player.setPlayWhenReady(true);
            }else
                Toast.makeText(c, R.string.video_error, Toast.LENGTH_LONG).show();
        }
    });

    player.addVideoListener(new VideoListener() {
        @Override
        public void onRenderedFirstFrame() {
        }
    });
}
 
Example 10
Source File: Player.java    From zapp with MIT License 4 votes vote down vote up
public void setView(PlayerView videoView) {
	videoView.setPlayer(player);
}
 
Example 11
Source File: VideoPlayer.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
@Override
public void setPlayerView(final PlayerView playerView) {
    if (playerView == null) {
        return;
    }
    playerView.setPlayer(exoPlayer);
    // hide default controls of Exo Player
    playerView.setUseController(false);
    logger.debug("Player state=" + state);
    if (!isPlaying()) {
        seekTo(lastCurrentPosition);
    }
    playerView.setOnTouchListener(new OnSwipeListener(playerView.getContext()) {

        @Override
        public void onSwipeLeft() {
            super.onSwipeLeft();
            if (controller != null) {
                controller.playNext();
            }
        }

        @Override
        public void onSwipeRight() {
            super.onSwipeRight();
            if (controller != null) {
                controller.playPrevious();
            }
        }

        @Override
        public void onClick() {
            super.onClick();

            if (controller != null
                    && state != PlayerState.RESET
                    && state != PlayerState.URI_SET) {
                logger.debug("Player touched");
                if (controller.isShowing() && autoHideControls) {
                    controller.hide();
                } else {
                    controller.setLmsUrl(lmsURL);
                    controller.setTitle(videoTitle);
                    controller.show();
                }
            }
        }
    });
}