com.google.android.exoplayer2.source.hls.HlsMediaSource Java Examples
The following examples show how to use
com.google.android.exoplayer2.source.hls.HlsMediaSource.
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: MediaSourceCreator.java From ExoVideoView with Apache License 2.0 | 6 votes |
public MediaSource buildMediaSource(Uri uri, String overrideExtension) { @C.ContentType int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension); switch (type) { case C.TYPE_SS: SsMediaSource.Factory factory = new SsMediaSource.Factory(buildDataSourceFactory(false)); factory.createMediaSource(uri); return factory.createMediaSource(uri); case C.TYPE_DASH: DashMediaSource.Factory factory1 = new DashMediaSource.Factory(buildDataSourceFactory(false)); return factory1.createMediaSource(uri); case C.TYPE_HLS: HlsMediaSource.Factory factory2 = new HlsMediaSource.Factory(buildDataSourceFactory(false)); return factory2.createMediaSource(uri); case C.TYPE_OTHER: ProgressiveMediaSource.Factory factory3 = new ProgressiveMediaSource.Factory(buildDataSourceFactory(false)); return factory3.createMediaSource(uri); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #3
Source File: LiveVideoPlayerActivity.java From LiveVideoBroadcaster with Apache License 2.0 | 6 votes |
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger); case C.TYPE_OTHER: if (uri.getScheme().equals("rtmp")) { return new ExtractorMediaSource(uri, rtmpDataSourceFactory, new DefaultExtractorsFactoryForFLV(), mainHandler, eventLogger); } else { return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, eventLogger); } default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #4
Source File: ExoPlayerHelper.java From ExoPlayer-Wrapper with Apache License 2.0 | 6 votes |
private MediaSource buildMediaSource(Uri uri) { int type = Util.inferContentType(uri); switch (type) { case C.TYPE_SS: return new SsMediaSource.Factory(mDataSourceFactory).createMediaSource(uri); case C.TYPE_DASH: return new DashMediaSource.Factory(mDataSourceFactory).createMediaSource(uri); case C.TYPE_HLS: return new HlsMediaSource.Factory(mDataSourceFactory).createMediaSource(uri); case C.TYPE_OTHER: return new ProgressiveMediaSource.Factory(mDataSourceFactory).createMediaSource(uri); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #5
Source File: ExoPlayerMediaSourceBuilder.java From PreviewSeekBar with Apache License 2.0 | 6 votes |
public MediaSource getMediaSource(boolean preview) { switch (streamType) { case C.TYPE_SS: return new SsMediaSource.Factory(new DefaultDataSourceFactory(context, null, getHttpDataSourceFactory(preview))).createMediaSource(uri); case C.TYPE_DASH: return new DashMediaSource.Factory(new DefaultDataSourceFactory(context, null, getHttpDataSourceFactory(preview))).createMediaSource(uri); case C.TYPE_HLS: return new HlsMediaSource.Factory(getDataSourceFactory(preview)).createMediaSource(uri); case C.TYPE_OTHER: return new ProgressiveMediaSource.Factory(getDataSourceFactory(preview)).createMediaSource(uri); default: { throw new IllegalStateException("Unsupported type: " + streamType); } } }
Example #6
Source File: ExoPlayerImpl.java From MediaSDK with Apache License 2.0 | 6 votes |
private MediaSource createMediaSource(Uri uri, String extension) { int type = Util.inferContentType(uri, extension); DataSource.Factory dataSourceFactory = buildDataSourceFactory(); switch (type) { case C.TYPE_DASH: return new DashMediaSource.Factory(dataSourceFactory) .createMediaSource(uri); case C.TYPE_SS: return new SsMediaSource.Factory(dataSourceFactory) .createMediaSource(uri); case C.TYPE_HLS: return new HlsMediaSource.Factory(dataSourceFactory) .createMediaSource(uri); case C.TYPE_OTHER: return new ProgressiveMediaSource.Factory(dataSourceFactory) .createMediaSource(uri); default: throw new IllegalStateException("Unsupported type: " + type); } }
Example #7
Source File: ExoMedia.java From QSVideoPlayer with Apache License 2.0 | 6 votes |
private MediaSource buildMediaSource(Context context, Uri uri) { int type = getUrlType(uri.toString()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, new DefaultDataSourceFactory(context, null, new DefaultHttpDataSourceFactory(USER_AGENT, null)), new DefaultSsChunkSource.Factory(new DefaultDataSourceFactory(context, BANDWIDTH_METER, new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER))), mainThreadHandler, null); case C.TYPE_DASH: return new DashMediaSource(uri, new DefaultDataSourceFactory(context, null, new DefaultHttpDataSourceFactory(USER_AGENT, null)), new DefaultDashChunkSource.Factory(new DefaultDataSourceFactory(context, BANDWIDTH_METER, new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER))), mainThreadHandler, null); case C.TYPE_HLS: return new HlsMediaSource(uri, new DefaultDataSourceFactory(context, BANDWIDTH_METER, new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER)), mainThreadHandler, null); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, new DefaultDataSourceFactory(context, BANDWIDTH_METER, new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER)), new DefaultExtractorsFactory(), mainThreadHandler, null); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #8
Source File: PlayerActivity.java From ExoPlayer-Offline with Apache License 2.0 | 6 votes |
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, eventLogger); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #9
Source File: VideoExoPlayer.java From TigerVideo with Apache License 2.0 | 6 votes |
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mMediaDataSourceFactory), mMainHandler, mEventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mMediaDataSourceFactory), mMainHandler, mEventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mMediaDataSourceFactory, mMainHandler, mEventLogger); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mMediaDataSourceFactory, new DefaultExtractorsFactory(), mMainHandler, mEventLogger); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #10
Source File: ExoMediaPlayer.java From VideoDemoJava with MIT License | 6 votes |
private MediaSource getMediaSource(Uri uri){ int contentType = Util.inferContentType(uri); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(mAppContext, Util.getUserAgent(mAppContext, mAppContext.getPackageName()), mBandwidthMeter); switch (contentType) { case C.TYPE_DASH: DefaultDashChunkSource.Factory factory = new DefaultDashChunkSource.Factory(dataSourceFactory); return new DashMediaSource(uri, dataSourceFactory, factory, null, null); case C.TYPE_SS: DefaultSsChunkSource.Factory ssFactory = new DefaultSsChunkSource.Factory(dataSourceFactory); return new SsMediaSource(uri, dataSourceFactory, ssFactory, null, null); case C.TYPE_HLS: return new HlsMediaSource(uri, dataSourceFactory, null, null); case C.TYPE_OTHER: default: // This is the MediaSource representing the media to be played. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); return new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null); } }
Example #11
Source File: Player.java From zapp with MIT License | 6 votes |
@NonNull private MediaSource getMediaSourceWithoutSubtitles(Uri uri) { int type = Util.inferContentType(uri); switch (type) { case C.TYPE_HLS: return new HlsMediaSource.Factory(dataSourceFactory) .createMediaSource(uri); case C.TYPE_OTHER: return new ExtractorMediaSource.Factory(dataSourceFactory) .createMediaSource(uri); case C.TYPE_DASH: case C.TYPE_SS: default: throw new IllegalStateException("Unsupported type: " + type); } }
Example #12
Source File: MediaPlayerFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, eventLogger); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #13
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 #14
Source File: VideoPlayer.java From media_player with MIT License | 6 votes |
private MediaSource buildMediaSource(Uri uri, DataSource.Factory mediaDataSourceFactory, Context context) { int type = Util.inferContentType(uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource.Factory(new DefaultSsChunkSource.Factory(mediaDataSourceFactory), new DefaultDataSourceFactory(context, null, mediaDataSourceFactory)).createMediaSource(uri); case C.TYPE_DASH: return new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(mediaDataSourceFactory), new DefaultDataSourceFactory(context, null, mediaDataSourceFactory)).createMediaSource(uri); case C.TYPE_HLS: return new HlsMediaSource.Factory(mediaDataSourceFactory).createMediaSource(uri); case C.TYPE_OTHER: return new ExtractorMediaSource.Factory(mediaDataSourceFactory) .setExtractorsFactory(new DefaultExtractorsFactory()).createMediaSource(uri); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #15
Source File: KExoMediaPlayer.java From K-Sonic with MIT License | 6 votes |
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, new DefaultDataSourceFactory(context, userAgent), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_DASH: return new DashMediaSource(uri, new DefaultDataSourceFactory(context, userAgent), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger); case C.TYPE_HLS: return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger); case C.TYPE_OTHER: return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, eventLogger); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #16
Source File: HlsMediaSourceBuilder.java From ExoMedia with Apache License 2.0 | 5 votes |
@NonNull @Override public MediaSource build(@NonNull Context context, @NonNull Uri uri, @NonNull String userAgent, @NonNull Handler handler, @Nullable TransferListener transferListener) { DataSource.Factory dataSourceFactory = buildDataSourceFactory(context, userAgent, transferListener); return new HlsMediaSource.Factory(dataSourceFactory) .createMediaSource(uri); }
Example #17
Source File: MediaSourceFactory.java From CumulusTV with MIT License | 5 votes |
public static MediaSource getMediaSourceFor(Context context, Uri mediaUri, String overrideExtension) { // Measures bandwidth during playback. Can be null if not required. DataSource.Factory mediaDataSourceFactory = buildDataSourceFactory(context, true); int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : mediaUri.getLastPathSegment()); Handler mainHandler = new Handler(); switch (type) { case C.TYPE_SS: return new SsMediaSource(mediaUri, buildDataSourceFactory(context, false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); case C.TYPE_DASH: return new DashMediaSource(mediaUri, buildDataSourceFactory(context, false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null); case C.TYPE_HLS: return new HlsMediaSource(mediaUri, mediaDataSourceFactory, mainHandler, null); case C.TYPE_OTHER: return new ExtractorMediaSource(mediaUri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null); default: { throw new NotMediaException("Unsupported type: " + type); } } }
Example #18
Source File: VideoPlayer.java From edx-app-android with Apache License 2.0 | 5 votes |
/** * Function that provides the media source played by ExoPlayer based on media type. * * @param videoUrl Video URL * @return The {@link MediaSource} to play. */ private MediaSource getMediaSource(String videoUrl) { final String userAgent = Util.getUserAgent(this.context, this.context.getString(R.string.app_name)); final DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this.context, userAgent); final MediaSource mediaSource; if (VideoUtil.videoHasFormat(videoUrl, VIDEO_FORMAT_M3U8)) { mediaSource = new HlsMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(videoUrl)); } else { mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(videoUrl)); } return mediaSource; }
Example #19
Source File: MediaSourceFactory.java From no-player with Apache License 2.0 | 5 votes |
private MediaSource createHlsMediaSource(DefaultDataSourceFactory defaultDataSourceFactory, Uri uri, MediaSourceEventListener mediaSourceEventListener) { HlsMediaSource.Factory factory = new HlsMediaSource.Factory(defaultDataSourceFactory); HlsMediaSource hlsMediaSource = factory.createMediaSource(uri); hlsMediaSource.addEventListener(handler, mediaSourceEventListener); return hlsMediaSource; }
Example #20
Source File: ReactExoplayerView.java From react-native-video with MIT License | 5 votes |
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension : uri.getLastPathSegment()); switch (type) { case C.TYPE_SS: return new SsMediaSource.Factory( new DefaultSsChunkSource.Factory(mediaDataSourceFactory), buildDataSourceFactory(false) ).setLoadErrorHandlingPolicy( config.buildLoadErrorHandlingPolicy(minLoadRetryCount) ).createMediaSource(uri); case C.TYPE_DASH: return new DashMediaSource.Factory( new DefaultDashChunkSource.Factory(mediaDataSourceFactory), buildDataSourceFactory(false) ).setLoadErrorHandlingPolicy( config.buildLoadErrorHandlingPolicy(minLoadRetryCount) ).createMediaSource(uri); case C.TYPE_HLS: return new HlsMediaSource.Factory( mediaDataSourceFactory ).setLoadErrorHandlingPolicy( config.buildLoadErrorHandlingPolicy(minLoadRetryCount) ).createMediaSource(uri); case C.TYPE_OTHER: return new ProgressiveMediaSource.Factory( mediaDataSourceFactory ).setLoadErrorHandlingPolicy( config.buildLoadErrorHandlingPolicy(minLoadRetryCount) ).createMediaSource(uri); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
Example #21
Source File: Alarmio.java From Alarmio with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); DebugUtils.setup(this); prefs = PreferenceManager.getDefaultSharedPreferences(this); listeners = new ArrayList<>(); alarms = new ArrayList<>(); timers = new ArrayList<>(); player = new SimpleExoPlayer.Builder(this).build(); player.addListener(this); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), null); hlsMediaSourceFactory = new HlsMediaSource.Factory(dataSourceFactory); progressiveMediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory); int alarmLength = PreferenceData.ALARM_LENGTH.getValue(this); for (int id = 0; id < alarmLength; id++) { alarms.add(new AlarmData(id, this)); } int timerLength = PreferenceData.TIMER_LENGTH.getValue(this); for (int id = 0; id < timerLength; id++) { TimerData timer = new TimerData(id, this); if (timer.isSet()) timers.add(timer); } if (timerLength > 0) startService(new Intent(this, TimerService.class)); SleepReminderService.refreshSleepTime(this); }
Example #22
Source File: ExoMediaPlayer.java From PlayerBase with Apache License 2.0 | 5 votes |
private MediaSource getMediaSource(Uri uri, com.google.android.exoplayer2.upstream.DataSource.Factory dataSourceFactory){ int contentType = Util.inferContentType(uri); switch (contentType) { case C.TYPE_DASH: return new DashMediaSource.Factory(dataSourceFactory).createMediaSource(uri); case C.TYPE_SS: return new SsMediaSource.Factory(dataSourceFactory).createMediaSource(uri); case C.TYPE_HLS: return new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri); case C.TYPE_OTHER: default: // This is the MediaSource representing the media to be played. return new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(uri); } }
Example #23
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 #24
Source File: StreamFragment.java From Twire with GNU General Public License v3.0 | 5 votes |
/** * Sets the URL to the VideoView and ChromeCast and starts playback. * * @param url */ private void playUrl(String url) { DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), getString(R.string.app_name)); MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url)); currentMediaSource = mediaSource; player.prepare(mediaSource); checkVodProgress(); resumeStream(); }
Example #25
Source File: VideoDialogFragment.java From TDTChannels-APP with MIT License | 5 votes |
public void loadVideo(String streamURL) { channelVideoView.setPlayer(player); // Add listener for onPlayerError player.addListener(this); // This is the MediaSource representing the media to be played. MediaSource videoSource = new HlsMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(streamURL)); // Prepare the player with the source. player.prepare(videoSource); player.setPlayWhenReady(true); }
Example #26
Source File: VideoPlayer.java From bcm-android with GNU General Public License v3.0 | 5 votes |
/** * Set m3u8 video source * * @param streamUrl M3U8 video url * @param playWhenReady Auto play when video is ready */ public void setM3U8VideoSource(String streamUrl, boolean playWhenReady) { DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null); MediaSource mediaSource = new HlsMediaSource.Factory(defaultDataSourceFactory).createMediaSource(Uri.parse(streamUrl)); setExoViewSource(mediaSource, playWhenReady); }
Example #27
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; }
Example #28
Source File: MediaSourceBuilder.java From ARVI with Apache License 2.0 | 4 votes |
@NonNull @Override public MediaSource buildMediaSource(@NonNull Context context, @NonNull Uri fileUri, @Nullable String fileExtension, @Nullable Handler handler, @NonNull DataSource.Factory manifestDataSourceFactory, @NonNull DataSource.Factory mediaDataSourceFactory, @Nullable MediaSourceEventListener eventListener) { @C.ContentType final int type = TextUtils.isEmpty(fileExtension) ? inferContentType(fileUri) : inferContentType("." + fileExtension); switch(type) { case C.TYPE_SS: final SsMediaSource ssMediaSource = new SsMediaSource.Factory( new DefaultSsChunkSource.Factory(mediaDataSourceFactory), manifestDataSourceFactory ).createMediaSource(fileUri); addEventListenerIfNonNull( ssMediaSource, handler, eventListener ); return ssMediaSource; case C.TYPE_DASH: final DashMediaSource dashMediaSource = new DashMediaSource.Factory( new DefaultDashChunkSource.Factory(mediaDataSourceFactory), manifestDataSourceFactory ).createMediaSource(fileUri); addEventListenerIfNonNull( dashMediaSource, handler, eventListener ); return dashMediaSource; case C.TYPE_HLS: final HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(mediaDataSourceFactory).createMediaSource(fileUri); addEventListenerIfNonNull( hlsMediaSource, handler, eventListener ); return hlsMediaSource; case C.TYPE_OTHER: final ExtractorMediaSource extractorMediaSource = new ExtractorMediaSource.Factory(mediaDataSourceFactory).createMediaSource(fileUri); addEventListenerIfNonNull( extractorMediaSource, handler, eventListener ); return extractorMediaSource; default: throw new IllegalStateException("Unsupported type: " + type); } }
Example #29
Source File: PlayerActivity.java From alltv with MIT License | 4 votes |
private void openPlayer(String videoUrl) { ChannelData chData = mChannels.get(mCurrentChannel); if ( chData.isAudioChannel() ) { Picasso.get().load(chData.getStillImageUrl()).into(this); } if(videoUrl == null) return; Uri uriLive = Uri.parse(videoUrl); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, getStringById(R.string.USERAGENT)); HlsMediaSource mediaSourceLive = new HlsMediaSource.Factory(dataSourceFactory) .setAllowChunklessPreparation(true) .createMediaSource(uriLive); mPlayer.prepare(mediaSourceLive); }
Example #30
Source File: VideoActivity.java From evercam-android with GNU Affero General Public License v3.0 | 4 votes |
private void preparePlayer() { if (player == null){ DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null; @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = ((EvercamPlayApplication) getApplication()).useExtensionRenderers() ? (false ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF; TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(), drmSessionManager, extensionRendererMode); player.addListener(this); eventLogger = new EventLogger(trackSelector); eventLogger.addListener(this); player.addListener(eventLogger); // player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); Uri hlsUrl = Uri.parse(evercamCamera.getHlsUrl()); MediaSource mediaSource = new HlsMediaSource(hlsUrl, mediaDataSourceFactory, mainHandler, eventLogger); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { player.seekTo(resumeWindow, resumePosition); } player.prepare(mediaSource, !haveResumePosition, false); player.setPlayWhenReady(true); player.setVideoSurface(surface); }else{ releasePlayer(); preparePlayer(); } /*DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null; @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = ((EvercamPlayApplication) getApplication()).useExtensionRenderers() ? (false ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON) : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF; TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(), drmSessionManager, extensionRendererMode); player.addListener(this); eventLogger = new EventLogger(trackSelector); eventLogger.addListener(this); player.addListener(eventLogger); // player.setAudioDebugListener(eventLogger); player.setVideoDebugListener(eventLogger); player.setMetadataOutput(eventLogger); Uri hlsUrl = Uri.parse(evercamCamera.getHlsUrl()); MediaSource mediaSource = new HlsMediaSource(hlsUrl, mediaDataSourceFactory, mainHandler, eventLogger); player.prepare(mediaSource); player.setPlayWhenReady(true); player.setVideoSurface(surface);*/ }