Java Code Examples for com.google.android.exoplayer2.util.Util#inferContentType()

The following examples show how to use com.google.android.exoplayer2.util.Util#inferContentType() . 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: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
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, null);
            case C.TYPE_OTHER:
                return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null);
            case C.TYPE_DASH:
                return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
//            case C.TYPE_HLS:return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
            case C.TYPE_HLS:
                throw new IllegalStateException("Unsupported type: " + type);
            default:
                throw new IllegalStateException("Unsupported type: " + type);
        }
    }
 
Example 2
Source File: VideoPlayer.java    From media_player with MIT License 6 votes vote down vote up
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 3
Source File: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
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 4
Source File: ExoMediaPlayer.java    From VideoDemoJava with MIT License 6 votes vote down vote up
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 5
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
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 6
Source File: ExoPlayerImpl.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
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: ExoPlayerHelper.java    From ExoPlayer-Wrapper with Apache License 2.0 6 votes vote down vote up
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 8
Source File: LiveVideoPlayerActivity.java    From LiveVideoBroadcaster with Apache License 2.0 6 votes vote down vote up
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 9
Source File: MediaSourceCreator.java    From ExoVideoView with Apache License 2.0 6 votes vote down vote up
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 10
Source File: KExoMediaPlayer.java    From K-Sonic with MIT License 6 votes vote down vote up
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 11
Source File: VideoExoPlayer.java    From TigerVideo with Apache License 2.0 6 votes vote down vote up
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 12
Source File: Player.java    From zapp with MIT License 6 votes vote down vote up
@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 13
Source File: ReactExoplayerView.java    From react-native-video with MIT License 5 votes vote down vote up
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 14
Source File: MediaSourceFactory.java    From CumulusTV with MIT License 5 votes vote down vote up
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 15
Source File: ExoMediaPlayer.java    From PlayerBase with Apache License 2.0 5 votes vote down vote up
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 16
Source File: ExoSourceManager.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
@C.ContentType
public static int inferContentType(Uri uri, @Nullable String overrideExtension) {
    return Util.inferContentType(uri, overrideExtension);
}
 
Example 17
Source File: ExoPlayerMediaSourceBuilder.java    From PreviewSeekBar with Apache License 2.0 4 votes vote down vote up
public void setUri(Uri uri) {
    this.uri = uri;
    this.streamType = Util.inferContentType(uri.getLastPathSegment());
}