Search in sources :

Example 21 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView 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 22 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project prebid-mobile-android by prebid.

the class GamVideoInstream method initializePlayer.

private static void initializePlayer(Context context) {
    SimpleExoPlayer.Builder playerBuilder = new SimpleExoPlayer.Builder(context);
    player = playerBuilder.build();
    playerView.setPlayer(player);
    adsLoader.setPlayer(player);
    Uri uri = Uri.parse("https://storage.googleapis.com/gvabox/media/samples/stock.mp4");
    // Uri uri = Uri.parse("<![CDATA[https://storage.googleapis.com/gvabox/media/samples/stock.mp4]]>");
    MediaItem mediaItem = MediaItem.fromUri(uri);
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, context.getString(R.string.app_name));
    ProgressiveMediaSource.Factory mediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory);
    MediaSource mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
    DataSpec dataSpec = new DataSpec(adsUri);
    AdsMediaSource adsMediaSource = new AdsMediaSource(mediaSource, dataSpec, "ad", mediaSourceFactory, adsLoader, playerView);
    player.setMediaSource(adsMediaSource);
    player.setPlayWhenReady(true);
    player.prepare();
}
Also used : SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) Uri(android.net.Uri) DataSource(com.google.android.exoplayer2.upstream.DataSource) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Example 23 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project whiteboard-android by netless-io.

the class PlayActivity method setupPlayer.

// region override
protected void setupPlayer() {
    final String uuid = getIntent().getStringExtra(StartActivity.EXTRA_ROOM_UUID);
    try {
        if (mIsUsedExoPlayer) {
            // WhiteExoPlayer demo
            PlayerView playerView = findViewById(R.id.exo_video_view);
            playerView.setVisibility(View.VISIBLE);
            mWhiteMediaPlayer = new WhiteExoPlayer(this);
            ((WhiteExoPlayer) mWhiteMediaPlayer).setPlayerView(playerView);
            ((WhiteExoPlayer) mWhiteMediaPlayer).setVideoPath("https://white-pan.oss-cn-shanghai.aliyuncs.com/101/oceans.mp4");
        } else {
            // WhiteIjkPlayer demo
            IjkVideoView videoView = findViewById(R.id.ijk_video_view);
            videoView.setVisibility(View.VISIBLE);
            mWhiteMediaPlayer = new WhiteIjkPlayer(videoView);
            ((WhiteIjkPlayer) mWhiteMediaPlayer).setVideoPath("https://white-pan.oss-cn-shanghai.aliyuncs.com/101/oceans.mp4");
        }
        mPlayerSyncManager = new PlayerSyncManager(mWhiteMediaPlayer, new PlayerSyncManager.Callbacks() {

            @Override
            public void startBuffering() {
                Log.d(TAG_Native, "startBuffering: ");
            }

            @Override
            public void endBuffering() {
                Log.d(TAG_Native, "endBuffering: ");
            }
        });
        Log.d(TAG_Native, "create success");
    } catch (Throwable e) {
        Log.e(TAG_Native, "create fail");
    }
    DemoAPI.Result result = new DemoAPI.Result() {

        @Override
        public void success(String uuid, String roomToken) {
            initPlayer(uuid, roomToken);
        }

        @Override
        public void fail(String message) {
            alert("创建回放失败: ", message);
        }
    };
    if (uuid != null) {
        demoAPI.getRoomToken(uuid, result);
    } else if (demoAPI.hasDemoInfo()) {
        demoAPI.getNewRoom(result);
    } else {
        alert("无数据", "没有房间 uuid");
    }
}
Also used : WhiteIjkPlayer(com.herewhite.demo.player.ijk.WhiteIjkPlayer) WhiteExoPlayer(com.herewhite.demo.player.exo.WhiteExoPlayer) DemoAPI(com.herewhite.demo.common.DemoAPI) IjkVideoView(com.herewhite.demo.player.ijk.widget.media.IjkVideoView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) PlayerSyncManager(com.herewhite.sdk.combinePlayer.PlayerSyncManager)

Example 24 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project PreviewSeekBar by rubensousa.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    PlayerView playerView = findViewById(R.id.player_view);
    previewTimeBar = playerView.findViewById(R.id.exo_progress);
    previewSeekBar = findViewById(R.id.previewSeekBar);
    previewTimeBar.addOnPreviewVisibilityListener((previewBar, isPreviewShowing) -> {
        Log.d("PreviewShowing", String.valueOf(isPreviewShowing));
    });
    previewTimeBar.addOnScrubListener(new PreviewBar.OnScrubListener() {

        @Override
        public void onScrubStart(PreviewBar previewBar) {
            Log.d("Scrub", "START");
        }

        @Override
        public void onScrubMove(PreviewBar previewBar, int progress, boolean fromUser) {
            Log.d("Scrub", "MOVE to " + progress / 1000 + " FROM USER: " + fromUser);
        }

        @Override
        public void onScrubStop(PreviewBar previewBar) {
            Log.d("Scrub", "STOP");
        }
    });
    exoPlayerManager = new ExoPlayerManager(playerView, previewTimeBar, findViewById(R.id.imageView), getString(R.string.url_thumbnails));
    exoPlayerManager.play(Uri.parse(getString(R.string.url_dash)));
    setupOptions();
    requestFullScreenIfLandscape();
}
Also used : PlayerView(com.google.android.exoplayer2.ui.PlayerView) PreviewBar(com.github.rubensousa.previewseekbar.PreviewBar) ExoPlayerManager(com.github.rubensousa.previewseekbar.sample.exoplayer.ExoPlayerManager)

Example 25 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project prebid-mobile-android by prebid.

the class RubiconInstreamVideoIMADemoActivity method initializePlayer.

private void initializePlayer() {
    SimpleExoPlayer.Builder playerBuilder = new SimpleExoPlayer.Builder(this);
    player = playerBuilder.build();
    playerView.setPlayer(player);
    adsLoader.setPlayer(player);
    Uri uri = Uri.parse(getString(R.string.content_url));
    MediaItem mediaItem = MediaItem.fromUri(uri);
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, getString(R.string.app_name));
    ProgressiveMediaSource.Factory mediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory);
    MediaSource mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
    DataSpec dataSpec = new DataSpec(adsUri);
    AdsMediaSource adsMediaSource = new AdsMediaSource(mediaSource, dataSpec, "ad", mediaSourceFactory, adsLoader, playerView);
    player.setMediaSource(adsMediaSource);
    player.setPlayWhenReady(true);
    player.prepare();
}
Also used : SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) Uri(android.net.Uri) DataSource(com.google.android.exoplayer2.upstream.DataSource) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) MediaItem(com.google.android.exoplayer2.MediaItem) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Aggregations

PlayerView (com.google.android.exoplayer2.ui.PlayerView)25 TextView (android.widget.TextView)20 View (android.view.View)15 ImageView (android.widget.ImageView)14 RecyclerView (androidx.recyclerview.widget.RecyclerView)13 WebView (android.webkit.WebView)12 Uri (android.net.Uri)10 AdapterView (android.widget.AdapterView)10 NestedScrollView (androidx.core.widget.NestedScrollView)10 PhotoView (com.github.chrisbanes.photoview.PhotoView)10 SolidIconView (com.odysee.app.ui.controls.SolidIconView)10 MediaItem (com.google.android.exoplayer2.MediaItem)8 Context (android.content.Context)7 Nullable (androidx.annotation.Nullable)7 Player (com.google.android.exoplayer2.Player)7 MediaSource (com.google.android.exoplayer2.source.MediaSource)7 ProgressiveMediaSource (com.google.android.exoplayer2.source.ProgressiveMediaSource)7 SuppressLint (android.annotation.SuppressLint)6 Intent (android.content.Intent)6 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)6