com.google.android.exoplayer2.ui.PlayerView Java Examples

The following examples show how to use com.google.android.exoplayer2.ui.PlayerView. 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: PlayerFragment.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    logger.debug("Player fragment start");

    try{
        final PlayerView playerView = (PlayerView) getView().findViewById(R.id.player_view);
        if(player!=null){
            player.setPlayerView(playerView);

            // setup the flat if player is fullscreen
            player.setFullScreen(isScreenLandscape());
        }
        if(curMessageTypes.contains(VideoNotPlayMessageType.IS_VIDEO_ONLY_ON_WEB)) {
            showVideoNotAvailable(VideoNotPlayMessageType.IS_VIDEO_ONLY_ON_WEB);
        } if(curMessageTypes.contains(VideoNotPlayMessageType.IS_VIDEO_MESSAGE_DISPLAYED)){
            showVideoNotAvailable(VideoNotPlayMessageType.IS_VIDEO_MESSAGE_DISPLAYED);
        }else if(curMessageTypes.contains(VideoNotPlayMessageType.IS_NETWORK_MESSAGE_DISPLAYED)){
            showNetworkError();
        } else if(curMessageTypes.contains(VideoNotPlayMessageType.IS_SHOWN_WIFI_SETTINGS_MESSAGE)){
            showWifiSettingsMessage();
        }
    }catch(Exception e){
        logger.error(e);
    }
}
 
Example #3
Source File: ExoPlayerHelper.java    From ExoPlayer-Wrapper with Apache License 2.0 6 votes vote down vote up
private ExoPlayerHelper(Context context, PlayerView exoPlayerView) {
    if (context == null) {
        throw new IllegalArgumentException("ExoPlayerHelper constructor - Context can't be null");
    }

    if (!(context instanceof Activity)) {
        throw new IllegalArgumentException("ExoPlayerHelper constructor - Context must be an instance of Activity");
    }

    if (exoPlayerView == null) {
        throw new IllegalArgumentException("ExoPlayerHelper constructor - SimpleExoPlayerView can't be null");
    }

    mContext = context;
    mExoPlayerView = exoPlayerView;

    mBottomProgress = mExoPlayerView.findViewById(R.id.bottom_progress);

    setVideoClickable();
    setControllerListener();
    init();
}
 
Example #4
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 #5
Source File: FileViewFragment.java    From lbry-android with MIT License 6 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    View root = getView();
    if (root != null) {
        float speed = item.getItemId() / 100.0f;
        String speedString = String.format("%sx", new DecimalFormat("0.##").format(speed));
        PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
        ((TextView) playerView.findViewById(R.id.player_playback_speed_label)).setText(speedString);

        if (MainActivity.appPlayer != null) {
            PlaybackParameters params = new PlaybackParameters(speed);
            MainActivity.appPlayer.setPlaybackParameters(params);
        }
    }
    return true;
}
 
Example #6
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 #7
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 #8
Source File: SimplePlayerActivity.java    From ExoPlayer-Wrapper with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_simple_player);

    PlayerView exoPlayerView = findViewById(R.id.exoPlayerView);

    mExoPlayerHelper = new ExoPlayerHelper.Builder(this, exoPlayerView)
            .setUiControllersVisibility(true)
            .setAutoPlayOn(true)
            .setVideoUrls(SAMPLE_1)
            .setTagUrl(TEST_TAG_URL)
            .addSavedInstanceState(savedInstanceState)
            .createAndPrepare();
}
 
Example #9
Source File: MainActivity.java    From ExoPlayer-Wrapper with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MyLog.e("onActivityCreate");

    setButtons();

    PlayerView exoPlayerView = findViewById(R.id.exoPlayerView);

    mExoPlayerHelper = new ExoPlayerHelper.Builder(this, exoPlayerView)
            .setVideoUrls(SAMPLE_8)
            .setSubTitlesUrls(new ArrayList<>(Arrays.asList(SUBTITLE)))
            .setTagUrl(TEST_TAG_URL)

            .setRepeatModeOn(true)
            .setAutoPlayOn(false)
            .enableLiveStreamSupport()

            .addSavedInstanceState(savedInstanceState)

            .setUiControllersVisibility(true)
            .addProgressBarWithColor(getResources().getColor(R.color.colorAccent))
            .setFullScreenBtnVisible()
            .addMuteButton(false, false)
            .setMuteBtnVisible()

            .setExoPlayerEventsListener(this)
            .setExoAdEventsListener(this)
            .setThumbImageViewEnabled(this)
            .createAndPrepare();
}
 
Example #10
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
public void onExitPIPMode() {
    View root = getView();
    if (root != null) {
        PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
        playerView.setVisibility(View.VISIBLE);
    }
}
 
Example #11
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
public void onEnterPIPMode() {
    View root = getView();
    if (root != null) {
        PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
        playerView.setVisibility(View.GONE);
    }
}
 
Example #12
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
private void hideBuffering() {
    View root = getView();
    if (root != null) {
        root.findViewById(R.id.player_buffering_progress).setVisibility(View.INVISIBLE);

        PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
        playerView.findViewById(R.id.player_skip_back_10).setVisibility(View.VISIBLE);
        playerView.findViewById(R.id.player_skip_forward_10).setVisibility(View.VISIBLE);
    }
}
 
Example #13
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
private void showBuffering() {
    View root = getView();
    if (root != null) {
        root.findViewById(R.id.player_buffering_progress).setVisibility(View.VISIBLE);

        PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
        playerView.findViewById(R.id.player_skip_back_10).setVisibility(View.INVISIBLE);
        playerView.findViewById(R.id.player_skip_forward_10).setVisibility(View.INVISIBLE);
    }
}
 
Example #14
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 #15
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
public void resetMedia() {
    View root = getView();
    if (root != null) {
        PlayerView view = root.findViewById(R.id.file_view_exoplayer_view);
        view.setShutterBackgroundColor(Color.BLACK);
        root.findViewById(R.id.file_view_exoplayer_container).setVisibility(View.GONE);
    }
    if (MainActivity.appPlayer != null) {
        MainActivity.appPlayer.stop();
    }
    resetPlayer();
}
 
Example #16
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 #17
Source File: ExoPlayerManager.java    From PreviewSeekBar with Apache License 2.0 5 votes vote down vote up
public ExoPlayerManager(PlayerView playerView,
                        PreviewTimeBar previewTimeBar, ImageView imageView,
                        String thumbnailsUrl) {
    this.playerView = playerView;
    this.imageView = imageView;
    this.previewTimeBar = previewTimeBar;
    this.mediaSourceBuilder = new ExoPlayerMediaSourceBuilder(playerView.getContext());
    this.thumbnailsUrl = thumbnailsUrl;
    this.previewTimeBar.addOnScrubListener(this);
    this.previewTimeBar.setPreviewLoader(this);
    this.resumeVideoOnPreviewStop = true;
}
 
Example #18
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 #19
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 #20
Source File: DefaultPlayer.java    From ARVI with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean isAttached(@NonNull PlayerView playerView) {
    Preconditions.nonNull(playerView);
    return ((playerView.getPlayer() != null) && (playerView.getPlayer() == this.exoPlayer));
}
 
Example #21
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();
                }
            }
        }
    });
}
 
Example #22
Source File: ExoPlayerHelper.java    From ExoPlayer-Wrapper with Apache License 2.0 4 votes vote down vote up
public Builder(Context context, PlayerView exoPlayerView) {
    mExoPlayerHelper = new ExoPlayerHelper(context, exoPlayerView);
}
 
Example #23
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 #24
Source File: MediaPlayerSingleton.java    From dtube-mobile-unofficial with Apache License 2.0 4 votes vote down vote up
PlayerView getIPFSPlayerView(){
    return playerView;
}
 
Example #25
Source File: Player.java    From zapp with MIT License 4 votes vote down vote up
public void setView(PlayerView videoView) {
	videoView.setPlayer(player);
}
 
Example #26
Source File: Player.java    From ARVI with Apache License 2.0 2 votes vote down vote up
/**
 * Attaches the specified {@link PlayerView} to the current {@link Player} instance.
 *
 * @param playerView the {@link PlayerView} to be attached
 */
void attach(@NonNull PlayerView playerView);
 
Example #27
Source File: Player.java    From ARVI with Apache License 2.0 2 votes vote down vote up
/**
 * Determines whether the current {@link Player} is attached to the specified {@link PlayerView}.
 *
 * @param playerView
 * @return whether the current Player is attached to the specified Player View or not
 */
boolean isAttached(@NonNull PlayerView playerView);
 
Example #28
Source File: Player.java    From ARVI with Apache License 2.0 2 votes vote down vote up
/**
 * Detaches the current {@link Player} instance from the specified {@link PlayerView}.
 *
 * @param playerView the {@link PlayerView} to detach the {@link Player} from
 */
void detach(@NonNull PlayerView playerView);
 
Example #29
Source File: PlayerListener.java    From edx-app-android with Apache License 2.0 votes vote down vote up
void setPlayerView(PlayerView preview);