private void releasePlayer() { if (player != null) { playerPosition = player.getCurrentPosition(); player.release(); player = null; // eventLogger.endSession(); // eventLogger = null; } }
@Override public void onSingleManifestError(IOException exception) { if (canceled) { return; } player.onRenderersError(exception); }
@Override public void onPause() { super.onPause(); if (!true) { releasePlayer(); } else { player.setBackgrounded(true); } audioCapabilitiesReceiver.unregister(); }
@Override public void onAudioCapabilitiesChanged(AudioCapabilities audioCapabilities) { boolean audioCapabilitiesChanged = !audioCapabilities.equals(this.audioCapabilities); if (player == null || audioCapabilitiesChanged) { this.audioCapabilities = audioCapabilities; releasePlayer(); preparePlayer(); } else if (player != null) { player.setBackgrounded(false); } }
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 surfaceDestroyed(SurfaceHolder holder) { if (player != null) { player.blockingClearSurface(); } }
@Override public void surfaceCreated(SurfaceHolder holder) { if (player != null) { player.setSurface(holder.getSurface()); } }
@Override public void onSingleManifest(SmoothStreamingManifest manifest) { if (canceled) { return; } Handler mainHandler = player.getMainHandler(); LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE)); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player); // Check drm support if necessary. DrmSessionManager drmSessionManager = null; if (manifest.protectionElement != null) { if (Util.SDK_INT < 18) { player.onRenderersError( new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME)); return; } try { drmSessionManager = new StreamingDrmSessionManager( manifest.protectionElement.uuid, player.getPlaybackLooper(), drmCallback, null, player.getMainHandler(), player); } catch (UnsupportedDrmException e) { player.onRenderersError(e); return; } } // Build the video renderer. DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent); ChunkSource videoChunkSource = new SmoothStreamingChunkSource( manifestFetcher, new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_VIDEO), videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS); ChunkSampleSource videoSampleSource = new ChunkSampleSource( videoChunkSource, loadControl, VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player, DemoPlayer.TYPE_VIDEO); TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer( context, videoSampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, drmSessionManager, true, mainHandler, player, 50); // Build the audio renderer. DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent); ChunkSource audioChunkSource = new SmoothStreamingChunkSource( manifestFetcher, new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_AUDIO), audioDataSource, null, LIVE_EDGE_LATENCY_MS); ChunkSampleSource audioSampleSource = new ChunkSampleSource( audioChunkSource, loadControl, AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player, DemoPlayer.TYPE_AUDIO); TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer( audioSampleSource, drmSessionManager, true, mainHandler, player, AudioCapabilities.getCapabilities(context)); // Build the text renderer. DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent); ChunkSource textChunkSource = new SmoothStreamingChunkSource( manifestFetcher, new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_TEXT), textDataSource, null, LIVE_EDGE_LATENCY_MS); ChunkSampleSource textSampleSource = new ChunkSampleSource( textChunkSource, loadControl, TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player, DemoPlayer.TYPE_TEXT); TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player, mainHandler.getLooper()); // Invoke the callback. TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT]; renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer; renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer; renderers[DemoPlayer.TYPE_TEXT] = textRenderer; player.onRenderers(renderers, bandwidthMeter); }
public void init() { manifestFetcher.singleLoad(player.getMainHandler().getLooper(), this); }