/** * Constructs an instance. Must be called from a thread that has an associated {@link Looper}. * * @param renderers The {@link Renderer}s that will be used by the instance. * @param trackSelector The {@link TrackSelector} that will be used by the instance. * @param loadControl The {@link LoadControl} that will be used by the instance. */ @SuppressLint("HandlerLeak") public ExoPlayerImpl(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl) { Log.i(TAG, "Init " + ExoPlayerLibraryInfo.VERSION + " [" + Util.DEVICE_DEBUG_INFO + "]"); Assertions.checkState(renderers.length > 0); this.renderers = Assertions.checkNotNull(renderers); this.trackSelector = Assertions.checkNotNull(trackSelector); this.playWhenReady = false; this.playbackState = STATE_IDLE; this.listeners = new CopyOnWriteArraySet<>(); emptyTrackSelections = new TrackSelectionArray(new TrackSelection[renderers.length]); timeline = Timeline.EMPTY; window = new Timeline.Window(); period = new Timeline.Period(); trackGroups = TrackGroupArray.EMPTY; trackSelections = emptyTrackSelections; eventHandler = new Handler() { @Override public void handleMessage(Message msg) { ExoPlayerImpl.this.handleEvent(msg); } }; playbackInfo = new ExoPlayerImplInternal.PlaybackInfo(0, 0); internalPlayer = new ExoPlayerImplInternal(renderers, trackSelector, loadControl, playWhenReady, eventHandler, playbackInfo, this); }
@Override @SuppressWarnings("ReferenceEquality") public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { updateButtonVisibilities(); if (trackGroups != lastSeenTrackGroupArray) { MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); if (mappedTrackInfo != null) { if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_VIDEO) == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) { showToast(R.string.error_unsupported_video); } if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_AUDIO) == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) { showToast(R.string.error_unsupported_audio); } } lastSeenTrackGroupArray = trackGroups; } }
private void updateForCurrentTrackSelections() { if (player == null) { return; } TrackSelectionArray selections = player.getCurrentTrackSelections(); for (int i = 0; i < selections.length; i++) { if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) { // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in // onRenderedFirstFrame(). return; } } // Video disabled so the shutter must be closed. shutterView.setVisibility(VISIBLE); }
@Override public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { targetBufferSize = 0; for (int i = 0; i < renderers.length; i++) { if (trackSelections.get(i) != null) { targetBufferSize += Util.getDefaultBufferSize(renderers[i].getTrackType()); } } allocator.setTargetBufferSize(targetBufferSize); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { Log.d(TAG, "onTracksChanged:" + currentWindowIndex + "_:" + player.getCurrentTimeline().getWindowCount()); if (getWindowCount() > 1) { if (isRemove) { isRemove = false; mediaSourceBuilder.removeMediaSource(resumeWindow); return; } if (windowListener != null) { windowListener.onCurrentIndex(currentWindowIndex, getWindowCount()); currentWindowIndex += 1; } if (mediaSourceBuilder.getIndexType() < 0) { return; } GestureVideoPlayer gestureVideoPlayer = null; if (ExoUserPlayer.this instanceof GestureVideoPlayer) { gestureVideoPlayer = (GestureVideoPlayer) ExoUserPlayer.this; } boolean setOpenSeek = !(mediaSourceBuilder.getIndexType() == currentWindowIndex && mediaSourceBuilder.getIndexType() > 0); if (gestureVideoPlayer != null) { gestureVideoPlayer.setPlayerGestureOnTouch(setOpenSeek); } getPlayerViewListener().setOpenSeek(setOpenSeek); } }
private void updateForCurrentTrackSelections() { if (player == null) { return; } TrackSelectionArray selections = player.getCurrentTrackSelections(); for (int i = 0; i < selections.length; i++) { if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) { // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in // onRenderedFirstFrame(). hideArtwork(); return; } } // Video disabled so the shutter must be closed. if (shutterView != null) { shutterView.setVisibility(VISIBLE); } // Display artwork if enabled and available, else hide it. if (useArtwork) { for (int i = 0; i < selections.length; i++) { TrackSelection selection = selections.get(i); if (selection != null) { for (int j = 0; j < selection.length(); j++) { Metadata metadata = selection.getFormat(j).metadata; if (metadata != null && setArtworkFromMetadata(metadata)) { return; } } } } if (setArtworkFromBitmap(null)) { return; } } // Artwork disabled or unavailable. hideArtwork(); }
private void updateForCurrentTrackSelections() { if (player == null) { return; } TrackSelectionArray selections = player.getCurrentTrackSelections(); for (int i = 0; i < selections.length; i++) { if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) { // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in // onRenderedFirstFrame(). hideArtwork(); return; } } // Video disabled so the shutter must be closed. if (shutterView != null) { shutterView.setVisibility(VISIBLE); } // Display artwork if enabled and available, else hide it. if (useArtwork) { for (int i = 0; i < selections.length; i++) { TrackSelection selection = selections.get(i); if (selection != null) { for (int j = 0; j < selection.length(); j++) { Metadata metadata = selection.getFormat(j).metadata; if (metadata != null && setArtworkFromMetadata(metadata)) { return; } } } } if (setArtworkFromBitmap(defaultArtwork)) { return; } } // Artwork disabled or unavailable. hideArtwork(); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { updateButtonVisibilities(); MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); if (mappedTrackInfo != null) { if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_VIDEO) == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) { showToast(R.string.error_unsupported_video); } if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_AUDIO) == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) { showToast(R.string.error_unsupported_audio); } } }
@Override public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { int targetBufferSize = 0; for (int i = 0; i < renderers.length; i++) { if (trackSelections.get(i) != null) { targetBufferSize += Util.getDefaultBufferSize(renderers[i].getTrackType()); } } allocator.setTargetBufferSize(targetBufferSize); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { if (trackGroups.length > 0) { // update format metadata of station Format format = trackGroups.get(0).getFormat(0); mStation.setMimeType(format.sampleMimeType); mStation.setChannelCount(format.channelCount); mStation.setSampleRate(format.sampleRate); mStation.setBitrate(format.bitrate); saveAppState(); } }
public long updatePeriodTrackSelection(long positionUs, boolean forceRecreateStreams, boolean[] streamResetFlags) { TrackSelectionArray trackSelections = trackSelectorResult.selections; for (int i = 0; i < trackSelections.length; i++) { mayRetainStreamFlags[i] = !forceRecreateStreams && trackSelectorResult.isEquivalent(periodTrackSelectorResult, i); } // Disable streams on the period and get new streams for updated/newly-enabled tracks. positionUs = mediaPeriod.selectTracks(trackSelections.getAll(), mayRetainStreamFlags, sampleStreams, streamResetFlags, positionUs); periodTrackSelectorResult = trackSelectorResult; // Update whether we have enabled tracks and sanity check the expected streams are non-null. hasEnabledTracks = false; for (int i = 0; i < sampleStreams.length; i++) { if (sampleStreams[i] != null) { Assertions.checkState(trackSelections.get(i) != null); hasEnabledTracks = true; } else { Assertions.checkState(trackSelections.get(i) == null); } } // The track selection has changed. loadControl.onTracksSelected(renderers, trackSelectorResult.groups, trackSelections); return positionUs; }
/** * Constructs an instance. Must be called from a thread that has an associated {@link Looper}. * * @param renderers The {@link Renderer}s that will be used by the instance. * @param trackSelector The {@link TrackSelector} that will be used by the instance. * @param loadControl The {@link LoadControl} that will be used by the instance. */ @SuppressLint("HandlerLeak") public ExoPlayerImpl(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl) { Log.i(TAG, "Init " + ExoPlayerLibraryInfo.VERSION_SLASHY + " [" + Util.DEVICE_DEBUG_INFO + "]"); Assertions.checkState(renderers.length > 0); this.renderers = Assertions.checkNotNull(renderers); this.trackSelector = Assertions.checkNotNull(trackSelector); this.playWhenReady = false; this.playbackState = STATE_IDLE; this.listeners = new CopyOnWriteArraySet<>(); emptyTrackSelections = new TrackSelectionArray(new TrackSelection[renderers.length]); timeline = Timeline.EMPTY; window = new Timeline.Window(); period = new Timeline.Period(); trackGroups = TrackGroupArray.EMPTY; trackSelections = emptyTrackSelections; playbackParameters = PlaybackParameters.DEFAULT; Looper eventLooper = Looper.myLooper() != null ? Looper.myLooper() : Looper.getMainLooper(); eventHandler = new Handler(eventLooper) { @Override public void handleMessage(Message msg) { ExoPlayerImpl.this.handleEvent(msg); } }; playbackInfo = new ExoPlayerImplInternal.PlaybackInfo(0, 0); internalPlayer = new ExoPlayerImplInternal(renderers, trackSelector, loadControl, playWhenReady, eventHandler, playbackInfo, this); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { HashMap<String, String> callingMethodParameters = new HashMap<>(); callingMethodParameters.put("trackGroups", String.valueOf(trackGroups)); callingMethodParameters.put("trackSelections", String.valueOf(trackSelections)); infoListener.onNewInfo("onTracksChanged", callingMethodParameters); }
@Override public void onTracksChanged(final TrackGroupArray trackGroups, final TrackSelectionArray trackSelections) { if (Log.logDEnabled()) { Log.d(TAG, "onTracksChanged()"); } }
public long updatePeriodTrackSelection(long positionUs, boolean forceRecreateStreams, boolean[] streamResetFlags) { TrackSelectionArray trackSelections = trackSelectorResult.selections; for (int i = 0; i < trackSelections.length; i++) { mayRetainStreamFlags[i] = !forceRecreateStreams && trackSelectorResult.isEquivalent(periodTrackSelectorResult, i); } // Undo the effect of previous call to associate no-sample renderers with empty tracks // so the mediaPeriod receives back whatever it sent us before. disassociateNoSampleRenderersWithEmptySampleStream(sampleStreams); updatePeriodTrackSelectorResult(trackSelectorResult); // Disable streams on the period and get new streams for updated/newly-enabled tracks. positionUs = mediaPeriod.selectTracks(trackSelections.getAll(), mayRetainStreamFlags, sampleStreams, streamResetFlags, positionUs); associateNoSampleRenderersWithEmptySampleStream(sampleStreams); // Update whether we have enabled tracks and sanity check the expected streams are non-null. hasEnabledTracks = false; for (int i = 0; i < sampleStreams.length; i++) { if (sampleStreams[i] != null) { Assertions.checkState(trackSelectorResult.renderersEnabled[i]); // hasEnabledTracks should be true only when non-empty streams exists. if (rendererCapabilities[i].getTrackType() != C.TRACK_TYPE_NONE) { hasEnabledTracks = true; } } else { Assertions.checkState(trackSelections.get(i) == null); } } // The track selection has changed. loadControl.onTracksSelected(renderers, trackSelectorResult.groups, trackSelections); return positionUs; }
@Override public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { targetBufferSize = targetBufferBytesOverwrite == C.LENGTH_UNSET ? calculateTargetBufferSize(renderers, trackSelections) : targetBufferBytesOverwrite; allocator.setTargetBufferSize(targetBufferSize); }
/** * Calculate target buffer size in bytes based on the selected tracks. The player will try not to * exceed this target buffer. Only used when {@code targetBufferBytes} is {@link C#LENGTH_UNSET}. * * @param renderers The renderers for which the track were selected. * @param trackSelectionArray The selected tracks. * @return The target buffer size in bytes. */ protected int calculateTargetBufferSize( Renderer[] renderers, TrackSelectionArray trackSelectionArray) { int targetBufferSize = 0; for (int i = 0; i < renderers.length; i++) { if (trackSelectionArray.get(i) != null) { targetBufferSize += Util.getDefaultBufferSize(renderers[i].getTrackType()); } } return targetBufferSize; }
/** * Constructs an instance. Must be called from a thread that has an associated {@link Looper}. * * @param renderers The {@link Renderer}s that will be used by the instance. * @param trackSelector The {@link TrackSelector} that will be used by the instance. * @param loadControl The {@link LoadControl} that will be used by the instance. */ @SuppressLint("HandlerLeak") public ExoPlayerImpl(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl) { Log.i(TAG, "Init " + Integer.toHexString(System.identityHashCode(this)) + " [" + ExoPlayerLibraryInfo.VERSION_SLASHY + "] [" + Util.DEVICE_DEBUG_INFO + "]"); Assertions.checkState(renderers.length > 0); this.renderers = Assertions.checkNotNull(renderers); this.trackSelector = Assertions.checkNotNull(trackSelector); this.playWhenReady = false; this.repeatMode = Player.REPEAT_MODE_OFF; this.shuffleModeEnabled = false; this.playbackState = Player.STATE_IDLE; this.listeners = new CopyOnWriteArraySet<>(); emptyTrackSelections = new TrackSelectionArray(new TrackSelection[renderers.length]); window = new Timeline.Window(); period = new Timeline.Period(); trackGroups = TrackGroupArray.EMPTY; trackSelections = emptyTrackSelections; playbackParameters = PlaybackParameters.DEFAULT; Looper eventLooper = Looper.myLooper() != null ? Looper.myLooper() : Looper.getMainLooper(); eventHandler = new Handler(eventLooper) { @Override public void handleMessage(Message msg) { ExoPlayerImpl.this.handleEvent(msg); } }; playbackInfo = new PlaybackInfo(Timeline.EMPTY, null, 0, 0); internalPlayer = new ExoPlayerImplInternal(renderers, trackSelector, loadControl, playWhenReady, repeatMode, shuffleModeEnabled, eventHandler, this); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { if (trackGroups.length > 0) { // update format metadata of station Format format = trackGroups.get(0).getFormat(0); mStation.setMimeType(format.sampleMimeType); mStation.setChannelCount(format.channelCount); mStation.setSampleRate(format.sampleRate); mStation.setBitrate(format.bitrate); } }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { updateForCurrentTrackSelections(); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { // Do Nothing. }
@Override public void onTracksChanged(TrackGroupArray tracks, TrackSelectionArray selections) { updateForCurrentTrackSelections(); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { Timber.e("播放: TrackGroupArray "); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {}
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { // Do nothing. }
/** * Initializes the player. */ public void Initialize(final BA ba, String EventName) { eventName = EventName.toLowerCase(BA.cul); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(BA.applicationContext, trackSelector); player.addListener(new Player.EventListener() { @Override public void onLoadingChanged(boolean isLoading) { } @Override public void onPlayerError(ExoPlaybackException error) { ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_error", String.valueOf(error.getCause())); } @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState != currentState) { currentState = playbackState; if (currentState == Player.STATE_ENDED) ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_complete"); else if (currentState == Player.STATE_READY) ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_ready"); } } @Override public void onPositionDiscontinuity() { } @Override public void onTimelineChanged(Timeline timeline, Object manifest) { } @Override public void onPlaybackParametersChanged( PlaybackParameters playbackParameters) { // TODO Auto-generated method stub } @Override public void onRepeatModeChanged(int repeatMode) { } @Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { ba.raiseEventFromUI(SimpleExoPlayerWrapper.this, eventName + "_trackchanged"); } }); }
@Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { }
public void EventListener(){ this.player.addListener(new ExoPlayer.EventListener() { @Override public void onTimelineChanged(Timeline timeline, Object manifest) { } @Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { } @Override public void onLoadingChanged(boolean isLoading) { } @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { switch (playbackState){ case 2:{ playerView.getProgressBar().setVisibility(View.VISIBLE); }break; case 3:{ playerView.getProgressBar().setVisibility(View.GONE); }break; case 4:{ playerView.getProgressBar().setVisibility(View.GONE); }break; } } @Override public void onPlayerError(ExoPlaybackException error) { } @Override public void onPositionDiscontinuity() { } }); this.player.setPlayWhenReady(true); }
@Override public TrackSelectionArray getCurrentTrackSelections() { return player.getCurrentTrackSelections(); }
@Override public TrackSelectionArray getCurrentTrackSelections() { return trackSelections; }