com.google.android.exoplayer2.source.ConcatenatingMediaSource Java Examples
The following examples show how to use
com.google.android.exoplayer2.source.ConcatenatingMediaSource.
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: ExoPlayerFragment.java From carstream-android-auto with Apache License 2.0 | 6 votes |
private MediaSource buildMediaSource(PlayerQueue playerQueue) { ArrayList<MediaSource> mediaSources = new ArrayList<>(); File[] currentQueue = playerQueue.getCurrentQueue(); for (File file : currentQueue) { Uri fileUri = Uri.fromFile(file); String userAgent = Util.getUserAgent(getContext(), "CarStream"); if (file != null && (file.getName().endsWith(".m3u") || file.getName().endsWith(".m3u8"))) { Handler mHandler = new Handler(); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), userAgent); HlsMediaSource mediaSource = new HlsMediaSource(fileUri, defaultDataSourceFactory, 1800000, mHandler, null); mediaSources.add(mediaSource); } else { ExtractorMediaSource extractorMediaSource = new ExtractorMediaSource(fileUri, new DefaultDataSourceFactory(getContext(), userAgent), new DefaultExtractorsFactory(), null, null); mediaSources.add(extractorMediaSource); } } ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(mediaSources.toArray(new MediaSource[mediaSources.size()])); return concatenatingMediaSource; }
Example #2
Source File: PlayerActivity.java From exoplayer-intro with Apache License 2.0 | 6 votes |
private MediaSource buildMediaSource(Uri uri) { // These factories are used to construct two media sources below DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, "exoplayer-codelab"); ProgressiveMediaSource.Factory mediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory); // Create a media source using the supplied URI MediaSource mediaSource1 = mediaSourceFactory.createMediaSource(uri); // Additionally create a media source using an MP3 Uri audioUri = Uri.parse(getString(R.string.media_url_mp3)); MediaSource mediaSource2 = mediaSourceFactory.createMediaSource(audioUri); return new ConcatenatingMediaSource(mediaSource1, mediaSource2); }
Example #3
Source File: ExoPlayerHelper.java From ExoPlayer-Wrapper with Apache License 2.0 | 6 votes |
private void createMediaSource() { // A MediaSource defines the media to be played, loads the media, and from which the loaded media can be read. // A MediaSource is injected via ExoPlayer.prepare at the start of playback. if (mVideosUris == null) { return; } MediaSource[] mediaSources = new MediaSource[mVideosUris.length]; for (int i = 0; i < mVideosUris.length; i++) { mediaSources[i] = buildMediaSource(mVideosUris[i]); if (mSubTitlesUrls != null && i < mSubTitlesUrls.size() & mSubTitlesUrls.get(i) != null) { mediaSources[i] = addSubTitlesToMediaSource(mediaSources[i], mSubTitlesUrls.get(i)); } } mMediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); addAdsToMediaSource(); }
Example #4
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 #5
Source File: GSYExo2MediaPlayer.java From GSYVideoPlayer with Apache License 2.0 | 5 votes |
public void setDataSource(List<String> uris, Map<String, String> headers, int index, boolean cache) { mHeaders = headers; if (uris == null) { return; } ConcatenatingMediaSource concatenatedSource = new ConcatenatingMediaSource(); for (String uri : uris) { MediaSource mediaSource = mExoHelper.getMediaSource(uri, isPreview, cache, false, mCacheDir, getOverrideExtension()); concatenatedSource.addMediaSource(mediaSource); } playIndex = index; mMediaSource = concatenatedSource; }
Example #6
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(); }
Example #7
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 #8
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; } }