/*** * 创建实例播放实例,并不开始缓冲 **/ private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); BufferingLoadControl loadControl = new BufferingLoadControl(); if (null == modelType) { setDefaultLoadModel(); } else { loadControl.setListener(new LoadListener() { @Override public void onProgress(long pro) { getPlayerViewListener().showNetSpeed(String.valueOf(pro) + "%"); } }); } DefaultRenderersFactory rf = new DefaultRenderersFactory(activity, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(rf, trackSelector, loadControl); player.setPlaybackParameters(playbackParameters); getPlayerViewListener().setPlayer(player); return player; }
@Override public IBinder onBind(final Intent intent) { bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "SyncPlayer"), bandwidthMeter); extractorsFactory = new DefaultExtractorsFactory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl); mMediaPlayer = player; setCompletionListener(); nbuilder.setSmallIcon(R.mipmap.ic_launcher); return mBinder; }
private void initializePlayer(Uri videoUri){ if (mExoPlayer == null){ TrackSelector trackSelector = new DefaultTrackSelector(); LoadControl loadControl = new DefaultLoadControl(); mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); mExoPlayer.addListener(this); mExoPlayer.seekTo(currentPosition); mPlayerView.setPlayer(mExoPlayer); String userAgent = Util.getUserAgent(getContext(), "Tasty"); MediaSource mediaSource = new ExtractorMediaSource(videoUri, new DefaultDataSourceFactory( getContext(), userAgent), new DefaultExtractorsFactory(), null, null); mExoPlayer.prepare(mediaSource); if (playWhenReady) mExoPlayer.setPlayWhenReady(true); else mExoPlayer.setPlayWhenReady(false); } }
private void setExoViewSource(@NonNull MasterSecret masterSecret, @NonNull VideoSlide videoSource) throws IOException { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); exoView.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), masterSecret, defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); exoPlayer.setPlayWhenReady(true); }
public MediaPeriodHolder(Renderer[] renderers, RendererCapabilities[] rendererCapabilities, long rendererPositionOffsetUs, TrackSelector trackSelector, LoadControl loadControl, MediaSource mediaSource, Object periodUid, int periodIndex, boolean isLastPeriod, long startPositionUs) { this.renderers = renderers; this.rendererCapabilities = rendererCapabilities; this.rendererPositionOffsetUs = rendererPositionOffsetUs; this.trackSelector = trackSelector; this.loadControl = loadControl; this.mediaSource = mediaSource; this.uid = Assertions.checkNotNull(periodUid); this.index = periodIndex; this.isLast = isLastPeriod; this.startPositionUs = startPositionUs; sampleStreams = new SampleStream[renderers.length]; mayRetainStreamFlags = new boolean[renderers.length]; mediaPeriod = mediaSource.createPeriod(periodIndex, loadControl.getAllocator(), startPositionUs); }
private void initExoPlayer(MediaSource sampleSource) { if (exoPlayer == null) { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); } exoPlayer.prepare(sampleSource); exoPlayer.setVideoSurfaceView(svPlayer); exoPlayer.setPlayWhenReady(true); initMediaControls(); }
/** * 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); }
/** * 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); Assertions.checkNotNull(renderers); Assertions.checkState(renderers.length > 0); this.playWhenReady = false; this.playbackState = STATE_IDLE; this.listeners = new CopyOnWriteArraySet<>(); window = new Timeline.Window(); period = new Timeline.Period(); 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); }
public FakeExoPlayer(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl) { this.renderers = renderers; this.trackSelector = trackSelector; this.loadControl = loadControl; this.eventListeners = new CopyOnWriteArraySet<>(); Looper eventListenerLooper = Looper.myLooper(); this.eventListenerHandler = new Handler(eventListenerLooper != null ? eventListenerLooper : Looper.getMainLooper()); this.playbackThread = new HandlerThread("FakeExoPlayer Thread"); playbackThread.start(); this.playbackHandler = new Handler(playbackThread.getLooper()); this.isStartingUp = true; this.isLoading = false; this.playbackState = Player.STATE_IDLE; this.durationUs = C.TIME_UNSET; }
public MediaPeriodHolder(Renderer[] renderers, RendererCapabilities[] rendererCapabilities, long rendererPositionOffsetUs, TrackSelector trackSelector, LoadControl loadControl, MediaSource mediaSource, Object periodUid, int index, MediaPeriodInfo info) { this.renderers = renderers; this.rendererCapabilities = rendererCapabilities; this.rendererPositionOffsetUs = rendererPositionOffsetUs; this.trackSelector = trackSelector; this.loadControl = loadControl; this.mediaSource = mediaSource; this.uid = Assertions.checkNotNull(periodUid); this.index = index; this.info = info; sampleStreams = new SampleStream[renderers.length]; mayRetainStreamFlags = new boolean[renderers.length]; MediaPeriod mediaPeriod = mediaSource.createPeriod(info.id, loadControl.getAllocator()); if (info.endPositionUs != C.TIME_END_OF_SOURCE) { ClippingMediaPeriod clippingMediaPeriod = new ClippingMediaPeriod(mediaPeriod, true); clippingMediaPeriod.setClipping(0, info.endPositionUs); mediaPeriod = clippingMediaPeriod; } this.mediaPeriod = mediaPeriod; }
private static SimpleExoPlayer createPlayer(Context context) { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); return ExoPlayerFactory.newSimpleInstance(context.getApplicationContext(), trackSelector); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (!isPlaying) { Handler mainHandler = new Handler(); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(MainActivity.this, trackSelector, loadControl); SimpleExoPlayerView playerView = (SimpleExoPlayerView) findViewById(R.id.videoView); playerView.setPlayer(player); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MainActivity.this, Util.getUserAgent(MainActivity.this, "yourApplicationName")); MediaSource mediaSource = new ExtractorMediaSource(Uri.parse("https://r7---sn-3c27ln7k.googlevideo.com/videoplayback?id=6fb497d0971b8cdf&itag=22&source=picasa&begin=0&requiressl=yes&mm=30&mn=sn-3c27ln7k&ms=nxu&mv=m&nh=IgphcjAzLmticDAxKgkxMjcuMC4wLjE&pl=22&sc=yes&mime=video/mp4&lmt=1486083166327499&mt=1486135406&ip=134.249.158.189&ipbits=8&expire=1486164239&sparams=ip,ipbits,expire,id,itag,source,requiressl,mm,mn,ms,mv,nh,pl,sc,mime,lmt&signature=3BB06D8D4294F8C49B3CE910B3D6849954302BB1.02ABE00700DFCEF715E72D0EFB73B67841E659F8&key=ck2&ratebypass=yes&title=%5BAnime365%5D%20Kuzu%20no%20Honkai%20-%2004%20(t1174045)"), dataSourceFactory, new DefaultExtractorsFactory(), null, null); player.prepare(mediaSource); player.setPlayWhenReady(true); } }
private void initializePlayer(Uri mediaUri) { if (mExoPlayer == null) { // Create an instance of the ExoPlayer. TrackSelector trackSelector = new DefaultTrackSelector(); LoadControl loadControl = new DefaultLoadControl(); mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); binding.exoStepFragmentPlayerView.setPlayer(mExoPlayer); mExoPlayer.addListener(this); String userAgent = Util.getUserAgent(getContext(), "RecipeStepVideo"); MediaSource mediaSource = new ExtractorMediaSource(mediaUri, new DefaultDataSourceFactory( getContext(), userAgent), new DefaultExtractorsFactory(), null, null); mExoPlayer.prepare(mediaSource); mExoPlayer.setPlayWhenReady(true); } }
private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(eventListener); return player; }
private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(this); return player; }
private SimpleExoPlayer createPreviewPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new WorstVideoTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new PreviewLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(false); player.setVolume(0f); player.prepare(mediaSourceBuilder.getMediaSource(true)); return player; }
private void setUpExoPlayer() { // Create a default TrackSelector TrackSelector trackSelector = createTrackSelector(); // Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); resumeLocalVideo(); exoPlayer.addListener(exoPlayerEventListener); }
private TrackSelector createTrackSelector() { // Create a default TrackSelector // Measures bandwidth during playback. Can be null if not required. BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); return trackSelector; }
private void setUpExoPlayer() { // Create a default TrackSelector TrackSelector trackSelector = createTrackSelector(); // Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); resumeLocalVideo(); exoPlayer.addListener(exoPlayerEventListener); }
private void createExoPlayer() { if (mExoPlayer != null) { releaseExoPlayer(); } // create default TrackSelector TrackSelector trackSelector = new DefaultTrackSelector(); // create default LoadControl - double the buffer LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE * 2)); // create the player mExoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getApplicationContext()), trackSelector, loadControl); }
public ExoPlayerImplInternal(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl, boolean playWhenReady, Handler eventHandler, PlaybackInfo playbackInfo, ExoPlayer player) { this.renderers = renderers; this.trackSelector = trackSelector; this.loadControl = loadControl; this.playWhenReady = playWhenReady; this.eventHandler = eventHandler; this.state = ExoPlayer.STATE_IDLE; this.playbackInfo = playbackInfo; this.player = player; rendererCapabilities = new RendererCapabilities[renderers.length]; for (int i = 0; i < renderers.length; i++) { renderers[i].setIndex(i); rendererCapabilities[i] = renderers[i].getCapabilities(); } standaloneMediaClock = new StandaloneMediaClock(); enabledRenderers = new Renderer[0]; window = new Timeline.Window(); period = new Timeline.Period(); trackSelector.init(this); playbackParameters = PlaybackParameters.DEFAULT; // Note: The documentation for Process.THREAD_PRIORITY_AUDIO that states "Applications can // not normally change to this priority" is incorrect. internalPlaybackThread = new HandlerThread("ExoPlayerImplInternal:Handler", Process.THREAD_PRIORITY_AUDIO); internalPlaybackThread.start(); handler = new Handler(internalPlaybackThread.getLooper(), this); }
protected SimpleExoPlayer(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl) { componentListener = new ComponentListener(); Looper eventLooper = Looper.myLooper() != null ? Looper.myLooper() : Looper.getMainLooper(); Handler eventHandler = new Handler(eventLooper); renderers = renderersFactory.createRenderers(eventHandler, componentListener, componentListener, componentListener, componentListener); // Obtain counts of video and audio renderers. int videoRendererCount = 0; int audioRendererCount = 0; for (Renderer renderer : renderers) { switch (renderer.getTrackType()) { case C.TRACK_TYPE_VIDEO: videoRendererCount++; break; case C.TRACK_TYPE_AUDIO: audioRendererCount++; break; } } this.videoRendererCount = videoRendererCount; this.audioRendererCount = audioRendererCount; // Set initial values. audioVolume = 1; audioSessionId = C.AUDIO_SESSION_ID_UNSET; audioStreamType = C.STREAM_TYPE_DEFAULT; videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT; // Build the player and associated objects. player = new ExoPlayerImpl(renderers, trackSelector, loadControl); }
/** * 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 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setSupportActionBar(toolbar); window = getWindow(); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } channelList = new SortableJsonChannelList(this); // player DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), bandwidthMeter); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); player.addListener(bufferingHandler); player.addListener(videoErrorHandler); videoView.setPlayer(player); // pager channelDetailAdapter = new ChannelDetailAdapter( getSupportFragmentManager(), channelList, onItemChangedListener); viewPager.setAdapter(channelDetailAdapter); viewPager.addOnPageChangeListener(onPageChangeListener); viewPager.setOnClickListener(view -> mContentView.performClick()); parseIntent(getIntent()); }
public SimpleExoPlayer2(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl) { componentListener = new ComponentListener(); videoListeners = new CopyOnWriteArraySet<>(); textOutputs = new CopyOnWriteArraySet<>(); metadataOutputs = new CopyOnWriteArraySet<>(); Looper eventLooper = Looper.myLooper() != null ? Looper.myLooper() : Looper.getMainLooper(); Handler eventHandler = new Handler(eventLooper); renderers = renderersFactory.createRenderers(eventHandler, componentListener, componentListener, componentListener, componentListener); // Obtain counts of video and audio renderers. int videoRendererCount = 0; int audioRendererCount = 0; for (Renderer renderer : renderers) { switch (renderer.getTrackType()) { case C.TRACK_TYPE_VIDEO: videoRendererCount++; break; case C.TRACK_TYPE_AUDIO: audioRendererCount++; break; } } this.videoRendererCount = videoRendererCount; this.audioRendererCount = audioRendererCount; // Set initial values. audioVolume = 1; audioSessionId = C.AUDIO_SESSION_ID_UNSET; audioAttributes = AudioAttributes.DEFAULT; videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT; // Build the player and associated objects. player = createExoPlayerImpl(renderers, trackSelector, loadControl); }
public ExoPlayerImplInternal(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl, boolean playWhenReady, Handler eventHandler, PlaybackInfo playbackInfo, ExoPlayer player) { this.renderers = renderers; this.trackSelector = trackSelector; this.loadControl = loadControl; this.playWhenReady = playWhenReady; this.eventHandler = eventHandler; this.state = ExoPlayer.STATE_IDLE; this.playbackInfo = playbackInfo; this.player = player; rendererCapabilities = new RendererCapabilities[renderers.length]; for (int i = 0; i < renderers.length; i++) { renderers[i].setIndex(i); rendererCapabilities[i] = renderers[i].getCapabilities(); } standaloneMediaClock = new StandaloneMediaClock(); enabledRenderers = new Renderer[0]; window = new Timeline.Window(); period = new Timeline.Period(); trackSelector.init(this); // Note: The documentation for Process.THREAD_PRIORITY_AUDIO that states "Applications can // not normally change to this priority" is incorrect. internalPlaybackThread = new PriorityHandlerThread("ExoPlayerImplInternal:Handler", Process.THREAD_PRIORITY_AUDIO); internalPlaybackThread.start(); handler = new Handler(internalPlaybackThread.getLooper(), this); }
protected SimpleExoPlayer(Context context, TrackSelector trackSelector, LoadControl loadControl, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, @ExtensionRendererMode int extensionRendererMode, long allowedVideoJoiningTimeMs) { mainHandler = new Handler(); componentListener = new ComponentListener(); // Build the renderers. ArrayList<Renderer> renderersList = new ArrayList<>(); buildRenderers(context, mainHandler, drmSessionManager, extensionRendererMode, allowedVideoJoiningTimeMs, renderersList); renderers = renderersList.toArray(new Renderer[renderersList.size()]); // Obtain counts of video and audio renderers. int videoRendererCount = 0; int audioRendererCount = 0; for (Renderer renderer : renderers) { switch (renderer.getTrackType()) { case C.TRACK_TYPE_VIDEO: videoRendererCount++; break; case C.TRACK_TYPE_AUDIO: audioRendererCount++; break; } } this.videoRendererCount = videoRendererCount; this.audioRendererCount = audioRendererCount; // Set initial values. audioVolume = 1; audioSessionId = C.AUDIO_SESSION_ID_UNSET; audioStreamType = C.STREAM_TYPE_DEFAULT; videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT; // Build the player and associated objects. player = new ExoPlayerImpl(renderers, trackSelector, loadControl); }
public ExoPlayerImplInternal(Renderer[] renderers, TrackSelector<T> trackSelector, LoadControl loadControl, boolean playWhenReady, Handler eventHandler, PlaybackInfo playbackInfo) { this.renderers = renderers; this.trackSelector = trackSelector; this.loadControl = loadControl; this.playWhenReady = playWhenReady; this.eventHandler = eventHandler; this.state = ExoPlayer.STATE_IDLE; this.playbackInfo = playbackInfo; rendererCapabilities = new RendererCapabilities[renderers.length]; for (int i = 0; i < renderers.length; i++) { renderers[i].setIndex(i); rendererCapabilities[i] = renderers[i].getCapabilities(); } standaloneMediaClock = new StandaloneMediaClock(); enabledRenderers = new Renderer[0]; window = new Timeline.Window(); period = new Timeline.Period(); trackSelector.init(this); // Note: The documentation for Process.THREAD_PRIORITY_AUDIO that states "Applications can // not normally change to this priority" is incorrect. internalPlaybackThread = new PriorityHandlerThread("ExoPlayerImplInternal:Handler", Process.THREAD_PRIORITY_AUDIO); internalPlaybackThread.start(); handler = new Handler(internalPlaybackThread.getLooper(), this); }
public MediaPeriodHolder(Renderer[] renderers, RendererCapabilities[] rendererCapabilities, TrackSelector<T> trackSelector, MediaSource mediaSource, MediaPeriod mediaPeriod, Object uid, long positionUs) { this.renderers = renderers; this.rendererCapabilities = rendererCapabilities; this.trackSelector = trackSelector; this.mediaSource = mediaSource; this.mediaPeriod = mediaPeriod; this.uid = Assertions.checkNotNull(uid); sampleStreams = new SampleStream[renderers.length]; mayRetainStreamFlags = new boolean[renderers.length]; startPositionUs = positionUs; }
@Override public void init(@NonNull final Context context) { final TrackSelector trackSelector = new DefaultTrackSelector(); mExoPlayer = ExoPlayerFactory .newSimpleInstance(context, trackSelector, new DefaultLoadControl()); mExoPlayer.addListener(mEventListener); mExoPlayer.setAudioDebugListener(mAudioRendererEventListener); mDataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "Fuck Off Music Player")); mExtractorsFactory = new DefaultExtractorsFactory(); }
private void setUpExoPlayer(){ // Create a default TrackSelector TrackSelector trackSelector = createTrackSelector(); // Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); resumeLocalVideo(); exoPlayer.addListener(exoPlayerEventListener); }
private TrackSelector createTrackSelector(){ // Create a default TrackSelector // Measures bandwidth during playback. Can be null if not required. BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); return trackSelector; }
ExoPlayerPlaybackPreparer(ExtractorMediaSourceFactoryProvider extractorMediaSourceFactoryProvider, TrackSelector trackSelector, LoadControl loadControl, RenderersFactory renderersFactory, Handler handler, DiskFileCache diskFileCache, BestMatchUriProvider bestMatchUriProvider, RemoteFileUriProvider remoteFileUriProvider) { this.trackSelector = trackSelector; this.loadControl = loadControl; this.renderersFactory = renderersFactory; this.handler = handler; this.diskFileCache = diskFileCache; this.bestMatchUriProvider = bestMatchUriProvider; this.extractorMediaSourceFactoryProvider = extractorMediaSourceFactoryProvider; this.remoteFileUriProvider = remoteFileUriProvider; }
public void init(Context context, SimpleExoPlayerView simpleExoPlayerView) { // Create a default track selector. BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // Create a player instance. player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); // Bind the player to the view. simpleExoPlayerView.setPlayer(player); // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, context.getString(R.string.application_name))); // This is the MediaSource representing the content media (i.e. not the ad). String contentUrl = context.getString(R.string.content_url); MediaSource contentMediaSource = new ExtractorMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(contentUrl)); // Compose the content media source into a new AdsMediaSource with both ads and content. MediaSource mediaSourceWithAds = new AdsMediaSource( contentMediaSource, /* adMediaSourceFactory= */ this, adsLoader, simpleExoPlayerView.getOverlayFrameLayout(), /* eventHandler= */ null, /* eventListener= */ null); // Prepare the player with the source. player.seekTo(contentPosition); player.prepare(mediaSourceWithAds); player.setPlayWhenReady(true); }
public ExoPlayerImplInternal(Renderer[] renderers, TrackSelector trackSelector, LoadControl loadControl, boolean playWhenReady, @Player.RepeatMode int repeatMode, boolean shuffleModeEnabled, Handler eventHandler, ExoPlayer player) { this.renderers = renderers; this.trackSelector = trackSelector; this.loadControl = loadControl; this.playWhenReady = playWhenReady; this.repeatMode = repeatMode; this.shuffleModeEnabled = shuffleModeEnabled; this.eventHandler = eventHandler; this.state = Player.STATE_IDLE; this.player = player; playbackInfo = new PlaybackInfo(null, null, 0, C.TIME_UNSET); rendererCapabilities = new RendererCapabilities[renderers.length]; for (int i = 0; i < renderers.length; i++) { renderers[i].setIndex(i); rendererCapabilities[i] = renderers[i].getCapabilities(); } standaloneMediaClock = new StandaloneMediaClock(); enabledRenderers = new Renderer[0]; window = new Timeline.Window(); period = new Timeline.Period(); mediaPeriodInfoSequence = new MediaPeriodInfoSequence(); trackSelector.init(this); playbackParameters = PlaybackParameters.DEFAULT; // Note: The documentation for Process.THREAD_PRIORITY_AUDIO that states "Applications can // not normally change to this priority" is incorrect. internalPlaybackThread = new HandlerThread("ExoPlayerImplInternal:Handler", Process.THREAD_PRIORITY_AUDIO); internalPlaybackThread.start(); handler = new Handler(internalPlaybackThread.getLooper(), this); }
protected SimpleExoPlayer(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl) { componentListener = new ComponentListener(); videoListeners = new CopyOnWriteArraySet<>(); textOutputs = new CopyOnWriteArraySet<>(); metadataOutputs = new CopyOnWriteArraySet<>(); videoDebugListeners = new CopyOnWriteArraySet<>(); audioDebugListeners = new CopyOnWriteArraySet<>(); Looper eventLooper = Looper.myLooper() != null ? Looper.myLooper() : Looper.getMainLooper(); Handler eventHandler = new Handler(eventLooper); renderers = renderersFactory.createRenderers(eventHandler, componentListener, componentListener, componentListener, componentListener); // Obtain counts of video and audio renderers. int videoRendererCount = 0; int audioRendererCount = 0; for (Renderer renderer : renderers) { switch (renderer.getTrackType()) { case C.TRACK_TYPE_VIDEO: videoRendererCount++; break; case C.TRACK_TYPE_AUDIO: audioRendererCount++; break; } } this.videoRendererCount = videoRendererCount; this.audioRendererCount = audioRendererCount; // Set initial values. audioVolume = 1; audioSessionId = C.AUDIO_SESSION_ID_UNSET; audioAttributes = AudioAttributes.DEFAULT; videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT; // Build the player and associated objects. player = createExoPlayerImpl(renderers, trackSelector, loadControl); }