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();
}
}
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();
}
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");
}
}
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();
}
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();
}
Aggregations