Search in sources :

Example 6 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class ImaAdsLoader method start.

@Override
public void start(AdsMediaSource adsMediaSource, DataSpec adTagDataSpec, Object adsId, AdViewProvider adViewProvider, EventListener eventListener) {
    checkState(wasSetPlayerCalled, "Set player using adsLoader.setPlayer before preparing the player.");
    if (adTagLoaderByAdsMediaSource.isEmpty()) {
        player = nextPlayer;
        @Nullable Player player = this.player;
        if (player == null) {
            return;
        }
        player.addListener(playerListener);
    }
    @Nullable AdTagLoader adTagLoader = adTagLoaderByAdsId.get(adsId);
    if (adTagLoader == null) {
        requestAds(adTagDataSpec, adsId, adViewProvider.getAdViewGroup());
        adTagLoader = adTagLoaderByAdsId.get(adsId);
    }
    adTagLoaderByAdsMediaSource.put(adsMediaSource, checkNotNull(adTagLoader));
    adTagLoader.addListenerWithAdView(eventListener, adViewProvider);
    maybeUpdateCurrentAdTagLoader();
}
Also used : Player(com.google.android.exoplayer2.Player) VideoAdPlayer(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer) Nullable(androidx.annotation.Nullable)

Example 7 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class ImaAdsLoader method maybePreloadNextPeriodAds.

private void maybePreloadNextPeriodAds() {
    @Nullable Player player = ImaAdsLoader.this.player;
    if (player == null) {
        return;
    }
    Timeline timeline = player.getCurrentTimeline();
    if (timeline.isEmpty()) {
        return;
    }
    int nextPeriodIndex = timeline.getNextPeriodIndex(player.getCurrentPeriodIndex(), period, window, player.getRepeatMode(), player.getShuffleModeEnabled());
    if (nextPeriodIndex == C.INDEX_UNSET) {
        return;
    }
    timeline.getPeriod(nextPeriodIndex, period);
    @Nullable Object nextAdsId = period.getAdsId();
    if (nextAdsId == null) {
        return;
    }
    @Nullable AdTagLoader nextAdTagLoader = adTagLoaderByAdsId.get(nextAdsId);
    if (nextAdTagLoader == null || nextAdTagLoader == currentAdTagLoader) {
        return;
    }
    long periodPositionUs = timeline.getPeriodPositionUs(window, period, period.windowIndex, /* windowPositionUs= */
    C.TIME_UNSET).second;
    nextAdTagLoader.maybePreloadAds(Util.usToMs(periodPositionUs), Util.usToMs(period.durationUs));
}
Also used : Player(com.google.android.exoplayer2.Player) VideoAdPlayer(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer) Timeline(com.google.android.exoplayer2.Timeline) Nullable(androidx.annotation.Nullable)

Example 8 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class MediaSessionConnector method invalidateMediaSessionPlaybackState.

/**
 * Updates the playback state of the media session.
 *
 * <p>Apps normally only need to call this method when the custom actions provided by a {@link
 * CustomActionProvider} changed and the playback state needs to be updated immediately.
 */
public final void invalidateMediaSessionPlaybackState() {
    PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();
    @Nullable Player player = this.player;
    if (player == null) {
        builder.setActions(buildPrepareActions()).setState(PlaybackStateCompat.STATE_NONE, /* position= */
        0, /* playbackSpeed= */
        0, /* updateTime= */
        SystemClock.elapsedRealtime());
        mediaSession.setRepeatMode(PlaybackStateCompat.REPEAT_MODE_NONE);
        mediaSession.setShuffleMode(PlaybackStateCompat.SHUFFLE_MODE_NONE);
        mediaSession.setPlaybackState(builder.build());
        return;
    }
    Map<String, CustomActionProvider> currentActions = new HashMap<>();
    for (CustomActionProvider customActionProvider : customActionProviders) {
        @Nullable PlaybackStateCompat.CustomAction customAction = customActionProvider.getCustomAction(player);
        if (customAction != null) {
            currentActions.put(customAction.getAction(), customActionProvider);
            builder.addCustomAction(customAction);
        }
    }
    customActionMap = Collections.unmodifiableMap(currentActions);
    Bundle extras = new Bundle();
    @Nullable PlaybackException playbackError = player.getPlayerError();
    boolean reportError = playbackError != null || customError != null;
    int sessionPlaybackState = reportError ? PlaybackStateCompat.STATE_ERROR : getMediaSessionPlaybackState(player.getPlaybackState(), player.getPlayWhenReady());
    if (customError != null) {
        builder.setErrorMessage(customError.first, customError.second);
        if (customErrorExtras != null) {
            extras.putAll(customErrorExtras);
        }
    } else if (playbackError != null && errorMessageProvider != null) {
        Pair<Integer, String> message = errorMessageProvider.getErrorMessage(playbackError);
        builder.setErrorMessage(message.first, message.second);
    }
    long activeQueueItemId = queueNavigator != null ? queueNavigator.getActiveQueueItemId(player) : MediaSessionCompat.QueueItem.UNKNOWN_ID;
    float playbackSpeed = player.getPlaybackParameters().speed;
    extras.putFloat(EXTRAS_SPEED, playbackSpeed);
    float sessionPlaybackSpeed = player.isPlaying() ? playbackSpeed : 0f;
    @Nullable MediaItem currentMediaItem = player.getCurrentMediaItem();
    if (currentMediaItem != null && !MediaItem.DEFAULT_MEDIA_ID.equals(currentMediaItem.mediaId)) {
        extras.putString(PLAYBACK_STATE_EXTRAS_KEY_MEDIA_ID, currentMediaItem.mediaId);
    }
    builder.setActions(buildPrepareActions() | buildPlaybackActions(player)).setActiveQueueItemId(activeQueueItemId).setBufferedPosition(player.getBufferedPosition()).setState(sessionPlaybackState, player.getCurrentPosition(), sessionPlaybackSpeed, /* updateTime= */
    SystemClock.elapsedRealtime()).setExtras(extras);
    @Player.RepeatMode int repeatMode = player.getRepeatMode();
    mediaSession.setRepeatMode(repeatMode == Player.REPEAT_MODE_ONE ? PlaybackStateCompat.REPEAT_MODE_ONE : repeatMode == Player.REPEAT_MODE_ALL ? PlaybackStateCompat.REPEAT_MODE_ALL : PlaybackStateCompat.REPEAT_MODE_NONE);
    mediaSession.setShuffleMode(player.getShuffleModeEnabled() ? PlaybackStateCompat.SHUFFLE_MODE_ALL : PlaybackStateCompat.SHUFFLE_MODE_NONE);
    mediaSession.setPlaybackState(builder.build());
}
Also used : PlaybackException(com.google.android.exoplayer2.PlaybackException) Player(com.google.android.exoplayer2.Player) HashMap(java.util.HashMap) Bundle(android.os.Bundle) PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) MediaItem(com.google.android.exoplayer2.MediaItem) Nullable(androidx.annotation.Nullable) Pair(android.util.Pair)

Example 9 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class PlayerView method setPlayer.

/**
 * Sets the {@link Player} to use.
 *
 * <p>To transition a {@link Player} from targeting one view to another, it's recommended to use
 * {@link #switchTargetView(Player, PlayerView, PlayerView)} 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 Player} to use, or {@code null} to detach the current player. Only
 *     players which are accessed on the main thread are supported ({@code
 *     player.getApplicationLooper() == Looper.getMainLooper()}).
 */
public void setPlayer(@Nullable Player player) {
    Assertions.checkState(Looper.myLooper() == Looper.getMainLooper());
    Assertions.checkArgument(player == null || player.getApplicationLooper() == Looper.getMainLooper());
    if (this.player == player) {
        return;
    }
    @Nullable Player oldPlayer = this.player;
    if (oldPlayer != null) {
        oldPlayer.removeListener(componentListener);
        if (oldPlayer.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)) {
            if (surfaceView instanceof TextureView) {
                oldPlayer.clearVideoTextureView((TextureView) surfaceView);
            } else if (surfaceView instanceof SurfaceView) {
                oldPlayer.clearVideoSurfaceView((SurfaceView) surfaceView);
            }
        }
    }
    if (subtitleView != null) {
        subtitleView.setCues(null);
    }
    this.player = player;
    if (useController()) {
        controller.setPlayer(player);
    }
    updateBuffering();
    updateErrorMessage();
    updateForCurrentTrackSelections(/* isNewPlayer= */
    true);
    if (player != null) {
        if (player.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)) {
            if (surfaceView instanceof TextureView) {
                player.setVideoTextureView((TextureView) surfaceView);
            } else if (surfaceView instanceof SurfaceView) {
                player.setVideoSurfaceView((SurfaceView) surfaceView);
            }
            updateAspectRatio();
        }
        if (subtitleView != null && player.isCommandAvailable(COMMAND_GET_TEXT)) {
            subtitleView.setCues(player.getCurrentCues());
        }
        player.addListener(componentListener);
        maybeShowController(false);
    } else {
        hideController();
    }
}
Also used : Player(com.google.android.exoplayer2.Player) TextureView(android.view.TextureView) Nullable(androidx.annotation.Nullable) SurfaceView(android.view.SurfaceView) GLSurfaceView(android.opengl.GLSurfaceView)

Example 10 with Player

use of org.powerbot.script.rt4.Player in project ExoPlayer by google.

the class PlayerView method updateForCurrentTrackSelections.

private void updateForCurrentTrackSelections(boolean isNewPlayer) {
    @Nullable Player player = this.player;
    if (player == null || !player.isCommandAvailable(Player.COMMAND_GET_TRACK_INFOS) || player.getCurrentTracksInfo().getTrackGroupInfos().isEmpty()) {
        if (!keepContentOnPlayerReset) {
            hideArtwork();
            closeShutter();
        }
        return;
    }
    if (isNewPlayer && !keepContentOnPlayerReset) {
        // Hide any video from the previous player.
        closeShutter();
    }
    if (player.getCurrentTracksInfo().isTypeSelected(C.TRACK_TYPE_VIDEO)) {
        // Video enabled, so artwork must be hidden. If the shutter is closed, it will be opened
        // in onRenderedFirstFrame().
        hideArtwork();
        return;
    }
    // Video disabled so the shutter must be closed.
    closeShutter();
    // Display artwork if enabled and available, else hide it.
    if (useArtwork()) {
        if (setArtworkFromMediaMetadata(player.getMediaMetadata())) {
            return;
        }
        if (setDrawableArtwork(defaultArtwork)) {
            return;
        }
    }
    // Artwork disabled or unavailable.
    hideArtwork();
}
Also used : Player(com.google.android.exoplayer2.Player) Nullable(androidx.annotation.Nullable)

Aggregations

Player (com.google.android.exoplayer2.Player)39 Nullable (androidx.annotation.Nullable)25 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)14 MediaItem (com.google.android.exoplayer2.MediaItem)11 Test (org.junit.Test)10 VideoAdPlayer (com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer)8 Timeline (com.google.android.exoplayer2.Timeline)8 Context (android.content.Context)6 ApplicationProvider (androidx.test.core.app.ApplicationProvider)6 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)6 ForwardingPlayer (com.google.android.exoplayer2.ForwardingPlayer)6 TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled)6 Tile (org.powerbot.script.Tile)6 SuppressLint (android.annotation.SuppressLint)5 Pair (android.util.Pair)5 Surface (android.view.Surface)5 SurfaceTexture (android.graphics.SurfaceTexture)4 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)4 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)4 PlaybackOutput (com.google.android.exoplayer2.robolectric.PlaybackOutput)4