Java Code Examples for com.google.android.exoplayer2.ExoPlayerFactory#newSimpleInstance()
The following examples show how to use
com.google.android.exoplayer2.ExoPlayerFactory#newSimpleInstance() .
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: PlayerTextureView.java From Mp4Composer-android with MIT License | 6 votes |
public PlayerTextureView(Context context, String path) { super(context, null, 0); // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "yourApplicationName")); // This is the MediaSource representing the media to be played. MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(path)); LoopingMediaSource loopingMediaSource = new LoopingMediaSource(videoSource); // SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(context); // Prepare the player with the source. player.prepare(loopingMediaSource); player.addVideoListener(this); setSurfaceTextureListener(this); }
Example 3
Source File: ExoPlayer2Helper.java From mimi-reader with Apache License 2.0 | 6 votes |
public ExoPlayer2Helper(Context context) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); dataSourceFactory = new FileDataSourceFactory(this); extractorsFactory = new DefaultExtractorsFactory(); DefaultTrackSelector trackSelector = new DefaultTrackSelector(bandwidthMeter); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context); EventLogger eventLogger = new EventLogger(trackSelector); player = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector); player.addListener(this); player.addListener(eventLogger); player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); player.setVideoListener(this); }
Example 4
Source File: DefaultPlayer.java From ARVI with Apache License 2.0 | 6 votes |
@Override public final void init() { if(isInitialized()) { return; } // initializing the actual ExoPlayer this.exoPlayer = ExoPlayerFactory.newSimpleInstance( this.context, this.renderersFactory, this.trackSelector, this.loadControl, this.drmSessionManager, this.bandwidthMeter ); this.exoPlayer.addListener(this.eventHandler); this.volumeController = new DefaultVolumeController(this.exoPlayer); }
Example 5
Source File: VideoPlayerComponent.java From android-arch-components-lifecycle with Apache License 2.0 | 6 votes |
private void initializePlayer() { if (player == null) { trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); player.addListener(this); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "testApp"), bandwidthMeter); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); ExtractorMediaSource videoSource = new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(true); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { Log.d(TAG, "Have Resume position true!" + resumePosition); player.seekTo(resumeWindow, resumePosition); } player.prepare(videoSource, !haveResumePosition, false); } }
Example 6
Source File: ExoPlayerAdapter.java From leanback-showcase with Apache License 2.0 | 5 votes |
/** * Constructor. */ public ExoPlayerAdapter(Context context) { mContext = context; mPlayer = ExoPlayerFactory.newSimpleInstance(mContext, new DefaultTrackSelector(), new DefaultLoadControl()); mPlayer.addListener(this); }
Example 7
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 8
Source File: VodPlaybackFragment.java From xipl with Apache License 2.0 | 5 votes |
/** * Sets up the usage of the internal player used by the library. */ protected void configureInternalPlayer() { Bundle arguments = getArguments(); String url = arguments.getString(VodTvSectionFragment.AV_CONTENT_LINK_BUNDLE); // Configure the ExoPlayer instance that will be used to play the media DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getActivity(), Util.getUserAgent(getActivity(), getActivity().getApplicationInfo().loadLabel(getActivity().getPackageManager()).toString())); mSimpleExoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getActivity()), new DefaultTrackSelector(), new DefaultLoadControl()); ExtractorMediaSource.Factory factory = new ExtractorMediaSource.Factory(dataSourceFactory); Uri uri = Uri.parse(url); mSimpleExoPlayer.prepare(factory.createMediaSource(uri)); mSimpleExoPlayer.addListener(new Player.DefaultEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { super.onPlayerStateChanged(playWhenReady, playbackState); if (playbackState == Player.STATE_READY && mPlayerGlue.getSeekProvider() == null) { mPlayerGlue.setSeekProvider(new ProviderPlaybackSeekDataProvider(mPlayerGlue.getDuration())); // Force content to fit to screen if wanted. if (getVodProperties().isVideoFitToScreen()) { DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics(); mPlayerGlue.getPlayerAdapter().getCallback().onVideoSizeChanged(mPlayerGlue.getPlayerAdapter(), displayMetrics.widthPixels, displayMetrics.heightPixels); } } } }); // Configure Leanback for playback. Use the updatePeriodMs used before in ExoPlayerAdapter LeanbackPlayerAdapter playerAdapter = new LeanbackPlayerAdapter(getActivity(), mSimpleExoPlayer, 16); mPlayerGlue = new PlaybackTransportControlGlue<>(getActivity(), playerAdapter); mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this)); mPlayerGlue.setTitle(arguments.getString(VodTvSectionFragment.AV_CONTENT_TITLE_BUNDLE)); mPlayerGlue.setSubtitle(arguments.getString(VodTvSectionFragment.AV_CONTENT_GROUP_BUNDLE)); setBackgroundType(BG_LIGHT); mPlayerGlue.playWhenPrepared(); }
Example 9
Source File: ExoPlayerView.java From DanDanPlayForAndroid with MIT License | 5 votes |
private void initViewBefore(Context context) { if (!(context instanceof AppCompatActivity)) { throw new IllegalArgumentException("Context must be AppCompatActivity"); } //是否使用surface view isUseSurfaceView = SPUtils.getInstance().getBoolean("surface_renders", true); //获取绑定的Activity实例 mAttachActivity = (AppCompatActivity) context; //加载布局 View.inflate(context, R.layout.layout_exo_player_view, this); //获取播放器实例,ffmpeg扩展不支持TextureView exoPlayer = isUseSurfaceView ? new ExoFFmpegPlayer(mAttachActivity, trackSelector) : ExoPlayerFactory.newSimpleInstance(mAttachActivity, trackSelector); //屏幕翻转控制 mOrientationListener = new OrientationEventListener(mAttachActivity) { @Override public void onOrientationChanged(int orientation) { if (mIsNeverPlay) { return; } // 根据角度进行横屏切换 if (orientation >= 60 && orientation <= 120) { mAttachActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } else if (orientation >= 240 && orientation <= 300) { mAttachActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } }; //声音管理器 mAudioManager = (AudioManager) mAttachActivity.getSystemService(Context.AUDIO_SERVICE); if (mAudioManager != null) mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); }
Example 10
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 11
Source File: ExoPlayerAdapter.java From tv-samples with Apache License 2.0 | 5 votes |
/** * Constructor. */ public ExoPlayerAdapter(Context context) { mContext = context; mPlayer = ExoPlayerFactory.newSimpleInstance(mContext, new DefaultTrackSelector(), new DefaultLoadControl()); mPlayer.addListener(this); }
Example 12
Source File: PlayerContainerView.java From Anecdote with Apache License 2.0 | 5 votes |
public void setVideoUrl(String url) { mVideoUrl = url; boolean needNewPlayer = mPlayer == null; if (needNewPlayer) { TrackSelection.Factory trackSelectionFactory = new FixedTrackSelection.Factory(); mTrackSelector = new DefaultTrackSelector(trackSelectionFactory); mPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), mTrackSelector); mPlayer.addListener(this); mPlayerView.setPlayer(mPlayer); mPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT); } // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "unknown"), 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(Uri.parse(url), dataSourceFactory, extractorsFactory, null, null); LoopingMediaSource loopingMediaSource = new LoopingMediaSource(videoSource); // Prepare the player with the source. mPlayer.prepare(loopingMediaSource); mPlayer.setVolume(0); mPlayerView.requestFocus(); mPlayer.setPlayWhenReady(true); // autoplay }
Example 13
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 14
Source File: MainActivity.java From ExoplayerExample with The Unlicense | 5 votes |
private void prepareExoPlayerFromByteArray(byte[] data){ exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(null), new DefaultLoadControl()); exoPlayer.addListener(eventListener); final MByteArrayDataSource byteArrayDataSource = new MByteArrayDataSource(data); Log.i(TAG,"ByteArrayDataSource constructed."); /* DataSpec dataSpec = new DataSpec(byteArrayDataSource.getUri()); try { byteArrayDataSource.open(dataSpec); } catch (IOException e) { e.printStackTrace(); } */ DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return byteArrayDataSource; } }; Log.i(TAG,"DataSource.Factory constructed."); MediaSource audioSource = new ExtractorMediaSource(byteArrayDataSource.getUri(), factory, new DefaultExtractorsFactory(),null,null); Log.i(TAG,"Audio source constructed."); exoPlayer.prepare(audioSource); initMediaControls(); }
Example 15
Source File: ImageActivity.java From cloudinary_android with MIT License | 4 votes |
private void initExoPlayer() { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); exoPlayerView = ((SimpleExoPlayerView) findViewById(R.id.exoPlayer)); exoPlayerView.setPlayer(exoPlayer); listener = new ExoPlayer.EventListener() { @Override public void onTracksChanged(TrackGroupArray trackGroupArray, TrackSelectionArray trackSelectionArray) { if (trackGroupArray.length > 0) { progressBar.setVisibility(View.GONE); } } @Override public void onLoadingChanged(boolean b) { progressBar.setVisibility(b ? View.VISIBLE : View.GONE); } @Override public void onPlayerStateChanged(boolean b, int i) { } @Override public void onPlayerError(ExoPlaybackException e) { progressBar.setVisibility(View.GONE); Toast.makeText(ImageActivity.this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); } @Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { } }; }
Example 16
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 17
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 18
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 19
Source File: ExoPlayerFragment.java From carstream-android-auto with Apache License 2.0 | 4 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); titleView = view.findViewById(R.id.player_title); albumView = view.findViewById(R.id.player_album); playerView = view.findViewById(R.id.exoplayer_view); playerView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() { @Override public void onVisibilityChange(int visibility) { titleView.setVisibility(visibility); albumView.setVisibility(visibility); mListener.onNativePlayerControlsVisibilityChange(visibility); } }); player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(getContext()), new DefaultTrackSelector(), new DefaultLoadControl()); playerView.setPlayer(player); playerView.requestFocus(); player.setPlayWhenReady(true); playerQueue = new PlayerQueue(filePath); MediaSource mediaSource = buildMediaSource(playerQueue); player.seekToDefaultPosition(playerQueue.currentIndex()); player.prepare(mediaSource, true, false); player.addListener(this); setAspectRatio(mListener.getAspectRatio()); playerFocusHelper = new PlayerFocusHelper(getContext()) { @Override protected void onStop() { super.onStop(); player.setPlayWhenReady(false); } @Override protected void onPause() { super.onPause(); player.setPlayWhenReady(false); } @Override public boolean isPlaying() { return player.getPlayWhenReady(); } @Override protected void onPlay() { super.onPlay(); player.setPlayWhenReady(true); } }; }
Example 20
Source File: SimpleExoPlayerInitializer.java From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static SimpleExoPlayer initializeExoPlayer(Context context) { return ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(context), new DefaultTrackSelector(), new DefaultLoadControl()); }