Search in sources :

Example 21 with Player

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

the class MainActivity method initializePlayer.

private void initializePlayer() {
    Intent intent = getIntent();
    String action = intent.getAction();
    Uri uri = ACTION_VIEW.equals(action) ? Assertions.checkNotNull(intent.getData()) : Uri.parse(DEFAULT_MEDIA_URI);
    DrmSessionManager drmSessionManager;
    if (intent.hasExtra(DRM_SCHEME_EXTRA)) {
        String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
        String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
        UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
        HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSource.Factory();
        HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
        drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(drmSchemeUuid, FrameworkMediaDrm.DEFAULT_PROVIDER).build(drmCallback);
    } else {
        drmSessionManager = DrmSessionManager.DRM_UNSUPPORTED;
    }
    DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(this);
    MediaSource mediaSource;
    @C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
    if (type == C.TYPE_DASH) {
        mediaSource = new DashMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else if (type == C.TYPE_OTHER) {
        mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else {
        throw new IllegalStateException();
    }
    ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build();
    player.setMediaSource(mediaSource);
    player.prepare();
    player.play();
    player.setRepeatMode(Player.REPEAT_MODE_ALL);
    surfaceControl = new SurfaceControl.Builder().setName(SURFACE_CONTROL_NAME).setBufferSize(/* width= */
    0, /* height= */
    0).build();
    videoSurface = new Surface(surfaceControl);
    player.setVideoSurface(videoSurface);
    MainActivity.player = player;
}
Also used : Util(com.google.android.exoplayer2.util.Util) PlayerControlView(com.google.android.exoplayer2.ui.PlayerControlView) Bundle(android.os.Bundle) SurfaceView(android.view.SurfaceView) FrameworkMediaDrm(com.google.android.exoplayer2.drm.FrameworkMediaDrm) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) Uri(android.net.Uri) Intent(android.content.Intent) Player(com.google.android.exoplayer2.Player) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) View(android.view.View) Button(android.widget.Button) SurfaceHolder(android.view.SurfaceHolder) MediaSource(com.google.android.exoplayer2.source.MediaSource) GridLayout(android.widget.GridLayout) C(com.google.android.exoplayer2.C) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) MediaItem(com.google.android.exoplayer2.MediaItem) HttpMediaDrmCallback(com.google.android.exoplayer2.drm.HttpMediaDrmCallback) Surface(android.view.Surface) UUID(java.util.UUID) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) Nullable(androidx.annotation.Nullable) SurfaceControl(android.view.SurfaceControl) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) Activity(android.app.Activity) Assertions(com.google.android.exoplayer2.util.Assertions) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) Intent(android.content.Intent) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Uri(android.net.Uri) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) Surface(android.view.Surface) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) HttpMediaDrmCallback(com.google.android.exoplayer2.drm.HttpMediaDrmCallback) UUID(java.util.UUID)

Example 22 with Player

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

the class AdTagLoader method onPlaybackStateChanged.

@Override
public void onPlaybackStateChanged(@Player.State int playbackState) {
    @Nullable Player player = this.player;
    if (adsManager == null || player == null) {
        return;
    }
    if (playbackState == Player.STATE_BUFFERING && !player.isPlayingAd() && isWaitingForAdToLoad()) {
        waitingForPreloadElapsedRealtimeMs = SystemClock.elapsedRealtime();
    } else if (playbackState == Player.STATE_READY) {
        waitingForPreloadElapsedRealtimeMs = C.TIME_UNSET;
    }
    handlePlayerStateChanged(player.getPlayWhenReady(), playbackState);
}
Also used : Player(com.google.android.exoplayer2.Player) VideoAdPlayer(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer) Nullable(androidx.annotation.Nullable)

Example 23 with Player

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

the class AdTagLoader method isWaitingForAdToLoad.

/**
 * Returns whether this instance is expecting the first ad in an the upcoming ad group to load
 * within the {@link ImaUtil.Configuration#adPreloadTimeoutMs preload timeout}.
 */
private boolean isWaitingForAdToLoad() {
    @Nullable Player player = this.player;
    if (player == null) {
        return false;
    }
    int adGroupIndex = getLoadingAdGroupIndex();
    if (adGroupIndex == C.INDEX_UNSET) {
        return false;
    }
    AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(adGroupIndex);
    if (adGroup.count != C.LENGTH_UNSET && adGroup.count != 0 && adGroup.states[0] != AdPlaybackState.AD_STATE_UNAVAILABLE) {
        // An ad is available already.
        return false;
    }
    long adGroupTimeMs = Util.usToMs(adGroup.timeUs);
    long contentPositionMs = getContentPeriodPositionMs(player, timeline, period);
    long timeUntilAdMs = adGroupTimeMs - contentPositionMs;
    return timeUntilAdMs < configuration.adPreloadTimeoutMs;
}
Also used : Player(com.google.android.exoplayer2.Player) VideoAdPlayer(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) Nullable(androidx.annotation.Nullable)

Example 24 with Player

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

the class DrawGroundItems method repaint.

public void repaint(final Graphics render) {
    if (!ctx.game.loggedIn()) {
        return;
    }
    final Player player = ctx.players.local();
    if (player == null) {
        return;
    }
    final Tile tile = player.tile();
    if (tile == null) {
        return;
    }
    final FontMetrics metrics = render.getFontMetrics();
    final int tHeight = metrics.getHeight();
    final int plane = ctx.game.floor();
    final List<GroundItem> check = new ArrayList<GroundItem>();
    ctx.groundItems.select(10).addTo(check);
    for (int x = tile.x() - 10; x <= tile.x() + 10; x++) {
        n: for (int y = tile.y() - 10; y <= tile.y() + 10; y++) {
            int d = 0;
            final Tile loc = new Tile(x, y, plane);
            for (final GroundItem groundItem : ctx.groundItems.select(check).at(loc)) {
                final Point screen = new TileMatrix(ctx, loc).centerPoint();
                if (screen.x == -1 || screen.y == -1) {
                    continue n;
                }
                final String name = groundItem.name();
                String s = "";
                s += groundItem.id();
                if (!name.isEmpty()) {
                    s += " " + name;
                }
                final int stack = groundItem.stackSize();
                if (stack > 1) {
                    s += " (" + groundItem.stackSize() + ")";
                }
                final int ty = screen.y - tHeight * (++d) + tHeight / 2;
                final int tx = screen.x - metrics.stringWidth(s) / 2;
                render.setColor(Color.green);
                render.drawString(s, tx, ty);
            }
        }
    }
}
Also used : Player(org.powerbot.script.rt6.Player) FontMetrics(java.awt.FontMetrics) GroundItem(org.powerbot.script.rt6.GroundItem) ArrayList(java.util.ArrayList) Tile(org.powerbot.script.Tile) Point(java.awt.Point) Point(java.awt.Point) TileMatrix(org.powerbot.script.rt6.TileMatrix)

Example 25 with Player

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

the class DrawObjects method repaint.

@Override
public void repaint(final Graphics render) {
    if (!ctx.game.loggedIn()) {
        return;
    }
    final Player player = ctx.players.local();
    if (player == null) {
        return;
    }
    final FontMetrics metrics = render.getFontMetrics();
    final int textHeight = metrics.getHeight();
    final Map<Tile, AtomicInteger> counts = new HashMap<Tile, AtomicInteger>();
    for (final GameObject object : ctx.objects.select(15)) {
        final Tile t = object.tile();
        if (!counts.containsKey(t)) {
            counts.put(t, new AtomicInteger(0));
        }
        final Point p = object.centerPoint();
        if (p.x == -1) {
            continue;
        }
        render.setColor(Color.black);
        render.fillRect(p.x - 1, p.y - 1, 2, 2);
        final int mainId = object.mainId();
        final int animation = object.animation();
        final String n = object.name();
        String s = (n.isEmpty() ? "" : n + " - ") + object.id();
        if (animation != -1) {
            s = s + " (A: " + animation + ")";
        }
        if (mainId != -1) {
            if (animation != -1) {
                s = s.replace(')', ',') + " MID: " + mainId + ")";
            } else {
                s = s + " (MID: " + mainId + ")";
            }
        }
        final int ty = p.y - textHeight / 2;
        final int tx = p.x - metrics.stringWidth(s) / 2;
        render.setColor(C[object.type().ordinal()]);
        render.drawString(s, tx, ty - textHeight * counts.get(t).getAndIncrement());
    }
}
Also used : Player(org.powerbot.script.rt6.Player) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) FontMetrics(java.awt.FontMetrics) GameObject(org.powerbot.script.rt6.GameObject) Tile(org.powerbot.script.Tile) Point(java.awt.Point) Point(java.awt.Point)

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