com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection Java Examples
The following examples show how to use
com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoActivity.java From arcusandroid with Apache License 2.0 | 7 votes |
private void initializePlayer() { CameraPreviewGetter.instance().pauseUpdates(); PlayerView video = findViewById(R.id.video_view); video.setUseController(playbackModel.getType() == PlaybackModel.PlaybackType.CLIP); video.requestFocus(); TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(DEFAULT_BANDWIDTH_METER); player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(this), new DefaultTrackSelector(trackSelectionFactory), new DefaultLoadControl() ); video.setPlayer(player); String userAgent = Util.getUserAgent(this, getPackageName()); DataSource.Factory dsf = new DefaultDataSourceFactory(this, userAgent); MediaSource mediaSource = new HlsMediaSource.Factory(dsf).createMediaSource(Uri.parse(playbackModel.getUrl())); player.prepare(mediaSource); player.addListener(eventListener); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); }
Example #2
Source File: PlaybackFragment.java From tv-samples with Apache License 2.0 | 6 votes |
private void initializePlayer() { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector); mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY); mPlaylistActionListener = new PlaylistActionListener(mPlaylist); mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener); mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this)); mPlayerGlue.playWhenPrepared(); play(mVideo); ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow(); setAdapter(mRowsAdapter); }
Example #3
Source File: PlaybackFragment.java From androidtv-Leanback with Apache License 2.0 | 6 votes |
private void initializePlayer() { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector); mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY); mPlaylistActionListener = new PlaylistActionListener(mPlaylist); mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener); mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this)); mPlayerGlue.playWhenPrepared(); play(mVideo); ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow(); setAdapter(mRowsAdapter); }
Example #4
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 6 votes |
public ExoMediaPlayer(@NonNull Context context) { this.context = context; bufferRepeater.setRepeaterDelay(BUFFER_REPEAT_DELAY); bufferRepeater.setRepeatListener(new BufferRepeatListener()); mainHandler = new Handler(); ComponentListener componentListener = new ComponentListener(); RendererProvider rendererProvider = new RendererProvider(context, mainHandler, componentListener, componentListener, componentListener, componentListener); DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = generateDrmSessionManager(); rendererProvider.setDrmSessionManager(drmSessionManager); renderers = rendererProvider.generate(); adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); LoadControl loadControl = ExoMedia.Data.loadControl != null ? ExoMedia.Data.loadControl : new DefaultLoadControl(); player = ExoPlayerFactory.newInstance(renderers.toArray(new Renderer[renderers.size()]), trackSelector, loadControl); player.addListener(this); analyticsCollector = new AnalyticsCollector.Factory().createAnalyticsCollector(player, Clock.DEFAULT); player.addListener(analyticsCollector); setupDamSessionManagerAnalytics(drmSessionManager); }
Example #5
Source File: AndExoPlayerView.java From MagicalExoPlayer with MIT License | 6 votes |
private void initializePlayer() { if (simpleExoPlayer == null) { bandwidthMeter = new DefaultBandwidthMeter(); extractorsFactory = new DefaultExtractorsFactory(); trackSelectionFactory = new AdaptiveTrackSelection.Factory(); trackSelector = new DefaultTrackSelector(); simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector); playerView.setPlayer(simpleExoPlayer); simpleExoPlayer.setPlayWhenReady(currPlayWhenReady); simpleExoPlayer.seekTo(currentWindow, playbackPosition); simpleExoPlayer.addListener(componentListener); } }
Example #6
Source File: VideoPlayer.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
private void setExoViewSource(@NonNull VideoSlide videoSource, boolean autoplay) 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); exoPlayer.addListener(new ExoPlayerListener(window)); //noinspection ConstantConditions exoView.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); exoPlayer.setPlayWhenReady(autoplay); }
Example #7
Source File: KExoMediaPlayer.java From K-Sonic with MIT License | 6 votes |
public KExoMediaPlayer(Context context) { this.context = context.getApplicationContext(); // =========@Init@========= TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector, new DefaultLoadControl(), null); player.addListener(eventLogger); player.addListener(playerListener); player.setVideoListener(playerListener); player.setPlayWhenReady(false); mainHandler = new Handler(); userAgent = Util.getUserAgent(this.context, "KExoMediaPlayer"); mediaDataSourceFactory = new DefaultDataSourceFactory(this.context, userAgent, BANDWIDTH_METER); }
Example #8
Source File: CompositeTrackSelectorCreator.java From no-player with Apache License 2.0 | 6 votes |
CompositeTrackSelector create(Options options, DefaultBandwidthMeter bandwidthMeter) { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory( bandwidthMeter, options.minDurationBeforeQualityIncreaseInMillis(), AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS, AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS, AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION, AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE, AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS, Clock.DEFAULT ); DefaultTrackSelector trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); DefaultTrackSelector.Parameters trackSelectorParameters = trackSelector.buildUponParameters() .setMaxVideoBitrate(options.maxVideoBitrate()) .build(); trackSelector.setParameters(trackSelectorParameters); ExoPlayerTrackSelector exoPlayerTrackSelector = ExoPlayerTrackSelector.newInstance(trackSelector); ExoPlayerAudioTrackSelector audioTrackSelector = new ExoPlayerAudioTrackSelector(exoPlayerTrackSelector); ExoPlayerVideoTrackSelector videoTrackSelector = new ExoPlayerVideoTrackSelector(exoPlayerTrackSelector); ExoPlayerSubtitleTrackSelector subtitleTrackSelector = new ExoPlayerSubtitleTrackSelector(exoPlayerTrackSelector); return new CompositeTrackSelector(trackSelector, audioTrackSelector, videoTrackSelector, subtitleTrackSelector); }
Example #9
Source File: TubiPlayerActivity.java From TubiPlayer with MIT License | 6 votes |
protected void initMoviePlayer() { // 1. Create a default TrackSelector mMainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 3. Create the mMoviePlayer mMoviePlayer = ExoPlayerFactory.newSimpleInstance(this, mTrackSelector); mEventLogger = new EventLogger(mTrackSelector); mMoviePlayer.addAnalyticsListener(mEventLogger); mMoviePlayer.addMetadataOutput(mEventLogger); mTubiPlayerView.setPlayer(mMoviePlayer, this); mTubiPlayerView.setMediaModel(mediaModel); }
Example #10
Source File: ProviderTvPlayer.java From xipl with Apache License 2.0 | 5 votes |
/** * Initializes and prepares the player but doesn't make it play the content. * * @param context the context needed to initialize the player. */ private void init(Context context) { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); player.prepare(getMediaSource(context)); }
Example #11
Source File: VideoPlayer.java From Telegram with GNU General Public License v2.0 | 5 votes |
public VideoPlayer() { mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER)); mainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); lastReportedPlaybackState = ExoPlayer.STATE_IDLE; NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying); }
Example #12
Source File: VideoPlayer.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public VideoPlayer() { mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER)); mainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); lastReportedPlaybackState = ExoPlayer.STATE_IDLE; NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying); }
Example #13
Source File: YouTubePlayerV2Fragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
private SimpleExoPlayer createExoPlayer() { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); Context context = getContext(); DefaultRenderersFactory defaultRenderersFactory = new DefaultRenderersFactory(context); return ExoPlayerFactory.newSimpleInstance(getContext(), defaultRenderersFactory, trackSelector, new DefaultLoadControl(), null, bandwidthMeter); }
Example #14
Source File: VideoExoPlayer.java From TigerVideo with Apache License 2.0 | 5 votes |
/**--------------------- 创建SimpleExoPlayer ----------------------------**/ private void initExoPlayer() { mMediaDataSourceFactory = buildDataSourceFactory(true); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mEventLogger = new EventLogger(mTrackSelector); mMainHandler = new Handler(Looper.getMainLooper()); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext, null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); mExoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, mTrackSelector); mExoPlayer.addListener(mEventLogger); mExoPlayer.setAudioDebugListener(mEventLogger); mExoPlayer.setVideoDebugListener(mEventLogger); mExoPlayer.setMetadataOutput(mEventLogger); mExoPlayer.setTextOutput(null); mExoPlayer.setVideoListener(null); mExoPlayer.removeListener(this); mExoPlayer.setVideoTextureView(null); mExoPlayer.setVideoListener(this); mExoPlayer.addListener(this); mExoPlayer.setTextOutput(this); }
Example #15
Source File: ExoVideoView.java From ExoVideoView with Apache License 2.0 | 5 votes |
private void createExoPlayer(MediaSourceCreator creator) { if (player != null) { releasePlayer(); } DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()); renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); SimpleExoPlayer.Builder builder = new SimpleExoPlayer.Builder(getContext(), renderersFactory); TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(getContext(),new AdaptiveTrackSelection.Factory()); builder.setTrackSelector(new DefaultTrackSelector(getContext(),adaptiveTrackSelectionFactory)); builder.setTrackSelector(trackSelector); builder.setBandwidthMeter(new DefaultBandwidthMeter.Builder(getContext()).build()); SimpleExoPlayer internalPlayer = builder.build(); internalPlayer.addListener(componentListener); internalPlayer.addListener(creator.getEventLogger()); internalPlayer.addMetadataOutput(creator.getEventLogger()); setPlayer(internalPlayer); }
Example #16
Source File: VideoPlayer.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public VideoPlayer() { mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER)); mainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); lastReportedPlaybackState = ExoPlayer.STATE_IDLE; NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying); }
Example #17
Source File: VideoPlayer.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public VideoPlayer() { mediaDataSourceFactory = new ExtendedDefaultDataSourceFactory(ApplicationLoader.applicationContext, BANDWIDTH_METER, new DefaultHttpDataSourceFactory("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)", BANDWIDTH_METER)); mainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); lastReportedPlaybackState = ExoPlayer.STATE_IDLE; NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.playerDidStartPlaying); }
Example #18
Source File: StoryAudioPlayer.java From zom-android-matrix with Apache License 2.0 | 5 votes |
private SimpleExoPlayer getOrCreatePlayer() { if (player == null) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); concatenatingMediaSource = new ConcatenatingMediaSource(); player.prepare(concatenatingMediaSource); } return player; }
Example #19
Source File: VideoViewActivity.java From zom-android-matrix with Apache License 2.0 | 5 votes |
private void initializePlayer() { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); //test TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create the player mExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); ////Set media controller mPlayerView.setUseController(true);//set to true or false to see controllers mPlayerView.requestFocus(); // Bind the player to the view. mPlayerView.setPlayer(mExoPlayer); DataSpec dataSpec = new DataSpec(mMediaUri); final InputStreamDataSource inputStreamDataSource = new InputStreamDataSource(this, dataSpec); try { inputStreamDataSource.open(dataSpec); } catch (IOException e) { e.printStackTrace(); } DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return inputStreamDataSource; } }; MediaSource audioSource = new ExtractorMediaSource(inputStreamDataSource.getUri(), factory, new DefaultExtractorsFactory(), null, null); mExoPlayer.prepare(audioSource); mExoPlayer.setPlayWhenReady(true); //run file/link when ready to play. }
Example #20
Source File: VideoPlayer.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public VideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); inflate(context, R.layout.video_player_layout, this); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); RenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()); this.exoView = findViewById(R.id.video_view); this.exoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); this.exoPlayer.addListener(new ExoPlayerListener()); if (exoView != null) { exoView.setPlayer(exoPlayer); } this.audioView = findViewById(R.id.audio_btn); this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // VolumeChangeObserver.INSTANCE.registerReceiver(); // VolumeChangeObserver.INSTANCE.addCallback(observerCallback); audioVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); exoPlayer.setVolume(audioVolume); if (audioVolume == 0) { audioView.setImageResource(R.drawable.common_video_player_mute_icon); isMuted = true; } }
Example #21
Source File: VideoPlayer.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public void setVideoSource(@NonNull VideoSlide videoSource, boolean autoplay) { Context context = getContext(); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector, loadControl); exoPlayer.addListener(new ExoPlayerListener(window, playerStateCallback)); exoPlayer.addListener(new Player.DefaultEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playerCallback != null) { switch (playbackState) { case Player.STATE_READY: if (playWhenReady) playerCallback.onPlaying(); break; case Player.STATE_ENDED: playerCallback.onStopped(); break; } } } }); exoView.setPlayer(exoPlayer); exoControls.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(context, "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(context, defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); createMediaSource = () -> new ExtractorMediaSource.Factory(attachmentDataSourceFactory) .setExtractorsFactory(extractorsFactory) .createMediaSource(videoSource.getUri()); exoPlayer.prepare(createMediaSource.create()); exoPlayer.setPlayWhenReady(autoplay); }
Example #22
Source File: VideoPlayerActivity.java From Camera-Roll-Android-App with Apache License 2.0 | 4 votes |
private void initPlayer() { // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), null); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource videoSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this); // Create the player player = ExoPlayerFactory.newSimpleInstance(renderersFactory, new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(null)), new DefaultLoadControl()); // Bind the player to the view. SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView); simpleExoPlayerView.setPlayer(player); // Prepare the player with the source. player.prepare(videoSource); player.setRepeatMode(Player.REPEAT_MODE_ONE); player.setPlayWhenReady(true); final ImageButton playPause = findViewById(R.id.play_pause); player.addListener(new SimpleEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { //update PlayPause-Button if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && showAnimations()) { if (player.getPlayWhenReady()) { playPause.setImageResource(R.drawable.play_to_pause_avd); } else { playPause.setImageResource(R.drawable.pause_to_play_avd); } Drawable d = playPause.getDrawable(); if (d instanceof Animatable) { ((Animatable) d).start(); } } else { if (player.getPlayWhenReady()) { playPause.setImageResource(R.drawable.ic_pause_white); } else { playPause.setImageResource(R.drawable.ic_play_arrow_white); } } } }); }
Example #23
Source File: LiveVideoPlayerActivity.java From LiveVideoBroadcaster with Apache License 2.0 | 4 votes |
private void initializePlayer(String rtmpUrl) { Intent intent = getIntent(); boolean needNewPlayer = player == null; if (needNewPlayer) { boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false); @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = useExtensionRenderers() ? (preferExtensionDecoders ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF; TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(), null, extensionRendererMode); // player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, // new DefaultLoadControl(new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE), 500, 1500, 500, 1500), // null, extensionRendererMode); player.addListener(this); eventLogger = new EventLogger(trackSelector); player.addListener(eventLogger); player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(shouldAutoPlay); debugViewHelper = new DebugTextViewHelper(player, debugTextView); debugViewHelper.start(); } if (needNewPlayer || needRetrySource) { // String action = intent.getAction(); Uri[] uris; String[] extensions; uris = new Uri[1]; uris[0] = Uri.parse(rtmpUrl); extensions = new String[1]; extensions[0] = ""; if (Util.maybeRequestReadExternalStoragePermission(this, uris)) { // The player will be reinitialized if the permission is granted. return; } MediaSource[] mediaSources = new MediaSource[uris.length]; for (int i = 0; i < uris.length; i++) { mediaSources[i] = buildMediaSource(uris[i], extensions[i]); } MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { player.seekTo(resumeWindow, resumePosition); } player.prepare(mediaSource, !haveResumePosition, false); needRetrySource = false; } }
Example #24
Source File: MainActivity.java From WhatsAppStatusSaver with Apache License 2.0 | 4 votes |
public void showImagePopup(Point p, final String uri) { Activity context = MainActivity.this; //COMPLETED solving video problem final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.image_popup_layout); dialog.show(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.copyFrom(dialog.getWindow().getAttributes()); dialog.getWindow().setAttributes(lp); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.getWindow().setDimAmount(0); // Getting a reference to Close button, and close the popup when clicked. FloatingActionButton close = (FloatingActionButton) dialog.findViewById(R.id.close_image_popup_button); ImageView statusImage = (ImageView) dialog.findViewById(R.id.full_status_image_view); final SimpleExoPlayerView simpleExoPlayerView = dialog.findViewById(R.id.full_status_video_view); final SimpleExoPlayer player; if (uri.endsWith(".jpg")) { GlideApp.with(context).load(uri).into(statusImage); } else if (uri.endsWith(".mp4")) { statusImage.setVisibility(View.GONE); simpleExoPlayerView.setVisibility(View.VISIBLE); Uri myUri = Uri.parse(uri); // initialize Uri here // 1. Create a default TrackSelector BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // 3. Create the player player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); //Set media controller simpleExoPlayerView.setUseController(true); simpleExoPlayerView.requestFocus(); // Bind the player to the view. simpleExoPlayerView.setPlayer(player); //Measures bandwidth during playback. Can be null if not required. DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter(); //Produces DataSource instances through which media data is loaded. DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util. getUserAgent(this, "exoplayer2example"), bandwidthMeterA); //Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource videoSource = new ExtractorMediaSource(myUri, dataSourceFactory, extractorsFactory, null, null); player.prepare(videoSource); player.setPlayWhenReady(true); //run file/link when ready to play. dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { player.release(); } }); } close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // popup.dismiss(); dialog.cancel(); } }); }
Example #25
Source File: DoubleViewTubiPlayerActivity.java From TubiPlayer with MIT License | 4 votes |
private void setupAdPlayer() { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER_AD); trackSelector_ad = new DefaultTrackSelector(adaptiveTrackSelectionFactory); adPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector_ad); }
Example #26
Source File: Player.java From zapp with MIT License | 4 votes |
public Player(Context context) { settings = new SettingsRepository(context); networkConnectionHelper = new NetworkConnectionHelper(context); String userAgent = Util.getUserAgent(context, context.getString(R.string.app_name)); TransferListener transferListener = new OnlyWifiTransferListener(); dataSourceFactory = new DefaultDataSourceFactory(context, userAgent, transferListener); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); playerHandler = new Handler(player.getApplicationLooper()); trackSelectorWrapper = new TrackSelectorWrapper(trackSelector); // media session setup mediaSession = new MediaSessionCompat(context, context.getPackageName()); MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession); mediaSessionConnector.setPlayer(player, null); mediaSession.setActive(true); // audio focus setup AudioAttributes audioAttributes = new AudioAttributes.Builder() .setUsage(C.USAGE_MEDIA) .setContentType(C.CONTENT_TYPE_MOVIE) .build(); player.setAudioAttributes(audioAttributes, true); playerEventHandler = new PlayerEventHandler(); // enable subtitles enableSubtitles(settings.getEnableSubtitles()); // wakelocks playerWakeLocks = new PlayerWakeLocks(context, "Zapp::Player"); Disposable wakelockDisposable = playerEventHandler .getShouldHoldWakelock() .distinctUntilChanged() .subscribe(this::shouldHoldWakelockChanged); disposables.add(wakelockDisposable); // set listeners networkConnectionHelper.startListenForNetworkChanges(this::setStreamQualityByNetworkType); }
Example #27
Source File: TrackSelectorWrapperTest.java From zapp with MIT License | 4 votes |
@Before public void setup() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); trackSelectorWrapper = new TrackSelectorWrapper(trackSelector); }
Example #28
Source File: MediaPlayerFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
private void initializePlayer() { Intent intent = fragActivity.getIntent(); boolean needNewPlayer = player == null; if (needNewPlayer) { boolean preferExtensionDecoders = intent.getBooleanExtra(PREFER_EXTENSION_DECODERS, false); UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null; DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null; if (drmSchemeUuid != null) { String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL); String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES); try { drmSessionManager = buildDrmSessionManager(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray); } catch (UnsupportedDrmException e) { int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported : (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown); showToast(errorStringId); return; } } @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = ((ExplorerApplication) fragActivity.getApplication()).useExtensionRenderers() ? (preferExtensionDecoders ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF; TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); trackSelectionHelper = new TrackSelectionHelper(trackSelector, videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(fragActivity, trackSelector, new DefaultLoadControl(), drmSessionManager, extensionRendererMode); player.addListener(this); eventLogger = new EventLogger(trackSelector); player.addListener(eventLogger); player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(shouldAutoPlay); debugViewHelper = new DebugTextViewHelper(player, debugTextView); debugViewHelper.start(); } if (needNewPlayer || needRetrySource) { String action = intent.getAction(); Uri[] uris; String[] extensions; if (Intent.ACTION_VIEW.equals(action)) { uris = new Uri[] {intent.getData()}; extensions = new String[] {intent.getStringExtra(EXTENSION_EXTRA)}; } else if (ACTION_VIEW.equals(action)) { uris = new Uri[] {intent.getData()}; extensions = new String[] {intent.getStringExtra(EXTENSION_EXTRA)}; } else if (ACTION_VIEW_LIST.equals(action)) { String[] uriStrings = intent.getStringArrayExtra(URI_LIST_EXTRA); uris = new Uri[uriStrings.length]; for (int i = 0; i < uriStrings.length; i++) { uris[i] = Uri.parse(uriStrings[i]); } extensions = intent.getStringArrayExtra(EXTENSION_LIST_EXTRA); if (extensions == null) { extensions = new String[uriStrings.length]; } } else { if (!Intent.ACTION_MAIN.equals(action)) { showToast(getString(R.string.unexpected_intent_action, action)); } return; } if (Util.maybeRequestReadExternalStoragePermission(fragActivity, uris)) { // The player will be reinitialized if the permission is granted. return; } MediaSource[] mediaSources = new MediaSource[uris.length]; for (int i = 0; i < uris.length; i++) { mediaSources[i] = buildMediaSource(uris[i], extensions[i]); } MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { player.seekTo(resumeWindow, resumePosition); } player.prepare(mediaSource, !haveResumePosition, false); needRetrySource = false; updateButtonVisibilities(); } }
Example #29
Source File: StoryExoPlayerManager.java From zom-android-matrix with Apache License 2.0 | 4 votes |
public static void load(MediaInfo mediaInfo, SimpleExoPlayerView view, boolean play) { VisualizerView visualizerView = view.findViewById(R.id.exo_visualizer_view); visualizerView.reset(); // Had the player been setup? if (view.getPlayer() == null) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); //test TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); SimpleExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(view.getContext(), trackSelector); // Bind to views visualizerView.setExoPlayer(exoPlayer); view.setPlayer(exoPlayer); } if (mediaInfo.isAudio()) { visualizerView.loadAudioFile(mediaInfo.uri); visualizerView.setVisibility(View.VISIBLE); } else { visualizerView.setVisibility(View.GONE); } view.getVideoSurfaceView().setAlpha(mediaInfo.isAudio() ? 0 : 1); DataSpec dataSpec = new DataSpec(mediaInfo.uri); final VideoViewActivity.InputStreamDataSource inputStreamDataSource = new VideoViewActivity.InputStreamDataSource(view.getContext(), dataSpec); try { inputStreamDataSource.open(dataSpec); } catch (IOException e) { e.printStackTrace(); } DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return inputStreamDataSource; } }; MediaSource mediaSource = new ExtractorMediaSource(inputStreamDataSource.getUri(), factory, new DefaultExtractorsFactory(), null, null); //LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource); ((SimpleExoPlayer)view.getPlayer()).prepare(mediaSource); if (play) { view.getPlayer().setPlayWhenReady(true); //run file/link when ready to play. } }
Example #30
Source File: PlayerActivity.java From leafpicrevived with GNU General Public License v3.0 | 4 votes |
/** * Internal methods */ private void initializePlayer() { Intent intent = getIntent(); boolean needNewPlayer = player == null; if (needNewPlayer) { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory, getThemeHelper()); lastSeenTrackGroupArray = null; UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null; DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null; if (drmSchemeUuid != null) { String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL); String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES); boolean multiSession = intent.getBooleanExtra(DRM_MULTI_SESSION, false); int errorStringId = R.string.error_drm_unknown; try { drmSessionManager = buildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession); } catch (UnsupportedDrmException e) { errorStringId = e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown; } if (drmSessionManager == null) { showToast(errorStringId); return; } } DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER); player = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector); player.addListener(new PlayerEventListener()); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(shouldAutoPlay); if (Prefs.getLoopVideo()) { player.setRepeatMode(Player.REPEAT_MODE_ALL); } else { player.setRepeatMode(Player.REPEAT_MODE_OFF); } } String action = intent.getAction(); Uri[] uris; String[] extensions; if (intent.getData() != null && intent.getType() != null) { uris = new Uri[]{intent.getData()}; extensions = new String[]{intent.getType()}; } else { // TODO: 12/7/16 asdasd showToast(getString(R.string.unexpected_intent_action, action)); return; } MediaSource[] mediaSources = new MediaSource[uris.length]; for (int i = 0; i < uris.length; i++) { mediaSources[i] = buildMediaSource(uris[i], extensions[i]); } MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { player.seekTo(resumeWindow, resumePosition); } player.prepare(mediaSource, !haveResumePosition, false); inErrorState = false; supportInvalidateOptionsMenu(); }