private void preparePlayer() { if (player == null) { String userAgent = Util.getUserAgent(this, "ExoPlayerDemo"); player = new DemoPlayer( new HlsRendererBuilder( this, userAgent, VIDEO_URL.toString(), null, audioCapabilities)); player.addListener(this); player.seekTo(playerPosition); playerNeedsPrepare = true; mediaController.setMediaPlayer(player.getPlayerControl()); mediaController.setEnabled(true); } if (playerNeedsPrepare) { player.prepare(); playerNeedsPrepare = false; updateButtonVisibilities(); } player.setSurface(surfaceView.getHolder().getSurface()); player.setPlayWhenReady(true); }
@Override public void surfaceCreated(SurfaceHolder holder) { if (player != null) { player.setSurface(holder.getSurface()); } }