Java Code Examples for com.google.android.exoplayer2.SimpleExoPlayer#addVideoListener()

The following examples show how to use com.google.android.exoplayer2.SimpleExoPlayer#addVideoListener() . 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: CustomExoPlayerView.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
public void setPlayer(SimpleExoPlayer player) {
    if (this.player == player) {
        return;
    }
    if (this.player != null) {

        this.player.removeListener(componentListener);
        this.player.removeTextOutput(componentListener);
        this.player.removeVideoListener(componentListener);
        if (surfaceView instanceof TextureView) {
            this.player.clearVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            this.player.clearVideoSurfaceView((SurfaceView) surfaceView);
        }
    }
    this.player = player;
    if (useController) {
        controller.setPlayer(player);
    }
    if (shutterView != null) {
        shutterView.setVisibility(VISIBLE);
    }

    if (player != null) {

        if (surfaceView instanceof TextureView) {
            player.setVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            player.setVideoSurfaceView((SurfaceView) surfaceView);
        }
        player.addVideoListener(componentListener);
        player.addTextOutput(componentListener);
        player.addListener(componentListener);
        maybeShowController(false);
    } else {
        shutterView.setVisibility(VISIBLE);
        controller.hide();
    }
}
 
Example 2
Source File: ExoVideoView.java    From ExoVideoView with Apache License 2.0 5 votes vote down vote up
/**
 * Set the {@link SimpleExoPlayer} to use.
 * <p>
 * To transition a {@link SimpleExoPlayer} from targeting one view to another, it's recommended to
 * use {@link #switchTargetView(SimpleExoPlayer, ExoVideoView, ExoVideoView)} rather
 * than this method. If you do wish to use this method directly, be sure to attach the player to
 * the new view <em>before</em> calling {@code setPlayer(null)} to detach it from the old one.
 * This ordering is significantly more efficient and may allow for more seamless transitions.
 *
 * @param player The {@link SimpleExoPlayer} to use.
 */
public void setPlayer(SimpleExoPlayer player) {
    if (this.player == player) {
        return;
    }
    if (this.player != null) {
        this.player.removeListener(componentListener);
        this.player.removeTextOutput(componentListener);
        this.player.removeVideoListener(componentListener);
        if (surfaceView instanceof TextureView) {
            this.player.clearVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            this.player.clearVideoSurfaceView((SurfaceView) surfaceView);
        }
    }
    this.player = player;
    if (useController) {
        controller.setPlayer(player);
    }
    if (shutterView != null) {
        shutterView.setVisibility(VISIBLE);
    }
    if (player != null) {
        if (surfaceView instanceof TextureView) {
            player.setVideoTextureView((TextureView) surfaceView);
        } else if (surfaceView instanceof SurfaceView) {
            player.setVideoSurfaceView((SurfaceView) surfaceView);
        }
        player.addVideoListener(componentListener);
        player.addTextOutput(componentListener);
        player.addListener(componentListener);
        maybeShowController(false);
        updateForCurrentTrackSelections();
    } else {
        hideController();
        hideArtwork();
    }
}