com.google.android.exoplayer2.ext.rtmp.RtmpDataSourceFactory Java Examples
The following examples show how to use
com.google.android.exoplayer2.ext.rtmp.RtmpDataSourceFactory.
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: RNRtmpView.java From react-native-rtmpview with MIT License | 6 votes |
public void play() { if (mPlayer != null && mPlayer.getPlaybackState() == Player.STATE_IDLE) { if (this.mTransferListener != null) { this.mTransferListener.dispose(); this.mTransferListener = null; } mTransferListener = new RNRtmpTransferListener(this); String rtmpUrl = this.mUrlString; RtmpDataSourceFactory rtmpDataSourceFactory = new RtmpDataSourceFactory(mTransferListener); MediaSource videoSource = new ExtractorMediaSource.Factory(rtmpDataSourceFactory) .createMediaSource(Uri.parse(rtmpUrl + " live=1")); mPlayer.prepare(videoSource); mPlayer.setPlayWhenReady(true); } else { Log.i(APP_NAME, "Unable to play; not idle"); } }
Example #2
Source File: ExoMediaSourceHelper.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
public MediaSource getMediaSource(String uri, Map<String, String> headers, boolean isCache) { Uri contentUri = Uri.parse(uri); if ("rtmp".equals(contentUri.getScheme())) { return new ProgressiveMediaSource.Factory(new RtmpDataSourceFactory(null)) .createMediaSource(contentUri); } int contentType = inferContentType(uri); DataSource.Factory factory; if (isCache) { factory = getCacheDataSourceFactory(); } else { factory = getDataSourceFactory(); } if (mHttpDataSourceFactory != null) { setHeaders(headers); } switch (contentType) { case C.TYPE_DASH: return new DashMediaSource.Factory(factory).createMediaSource(contentUri); case C.TYPE_SS: return new SsMediaSource.Factory(factory).createMediaSource(contentUri); case C.TYPE_HLS: return new HlsMediaSource.Factory(factory).createMediaSource(contentUri); default: case C.TYPE_OTHER: return new ProgressiveMediaSource.Factory(factory).createMediaSource(contentUri); } }
Example #3
Source File: ExoSourceManager.java From GSYVideoPlayer with Apache License 2.0 | 4 votes |
/** * @param dataSource 链接 * @param preview 是否带上header,默认有header自动设置为true * @param cacheEnable 是否需要缓存 * @param isLooping 是否循环 * @param cacheDir 自定义缓存目录 */ public MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir, @Nullable String overrideExtension) { MediaSource mediaSource = null; if (sExoMediaSourceInterceptListener != null) { mediaSource = sExoMediaSourceInterceptListener.getMediaSource(dataSource, preview, cacheEnable, isLooping, cacheDir); } if (mediaSource != null) { return mediaSource; } mDataSource = dataSource; Uri contentUri = Uri.parse(dataSource); int contentType = inferContentType(dataSource, overrideExtension); String uerAgent = null; if (mMapHeadData != null) { uerAgent = mMapHeadData.get("User-Agent"); } if ("android.resource".equals(contentUri.getScheme())) { DataSpec dataSpec = new DataSpec(contentUri); final RawResourceDataSource rawResourceDataSource = new RawResourceDataSource(mAppContext); try { rawResourceDataSource.open(dataSpec); } catch (RawResourceDataSource.RawResourceDataSourceException e) { e.printStackTrace(); } DataSource.Factory factory = new DataSource.Factory() { @Override public DataSource createDataSource() { return rawResourceDataSource; } }; return new ProgressiveMediaSource.Factory( factory).createMediaSource(contentUri); } switch (contentType) { case C.TYPE_SS: mediaSource = new SsMediaSource.Factory( new DefaultSsChunkSource.Factory(getDataSourceFactoryCache(mAppContext, cacheEnable, preview, cacheDir, uerAgent)), new DefaultDataSourceFactory(mAppContext, null, getHttpDataSourceFactory(mAppContext, preview, uerAgent))).createMediaSource(contentUri); break; case C.TYPE_DASH: mediaSource = new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(getDataSourceFactoryCache(mAppContext, cacheEnable, preview, cacheDir, uerAgent)), new DefaultDataSourceFactory(mAppContext, null, getHttpDataSourceFactory(mAppContext, preview, uerAgent))).createMediaSource(contentUri); break; case C.TYPE_HLS: mediaSource = new HlsMediaSource.Factory(getDataSourceFactoryCache(mAppContext, cacheEnable, preview, cacheDir, uerAgent)).createMediaSource(contentUri); break; case TYPE_RTMP: RtmpDataSourceFactory rtmpDataSourceFactory = new RtmpDataSourceFactory(null); mediaSource = new ProgressiveMediaSource.Factory(rtmpDataSourceFactory, new DefaultExtractorsFactory()) .createMediaSource(contentUri); break; case C.TYPE_OTHER: default: mediaSource = new ProgressiveMediaSource.Factory(getDataSourceFactoryCache(mAppContext, cacheEnable, preview, cacheDir, uerAgent), new DefaultExtractorsFactory()) .createMediaSource(contentUri); break; } if (isLooping) { return new LoopingMediaSource(mediaSource); } return mediaSource; }