Java Code Examples for com.google.android.exoplayer2.C#TYPE_OTHER

The following examples show how to use com.google.android.exoplayer2.C#TYPE_OTHER . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: Util.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Makes a best guess to infer the type from a file name.
 *
 * @param fileName Name of the file. It can include the path of the file.
 * @return The content type.
 */
@C.ContentType
public static int inferContentType(String fileName) {
  fileName = toLowerInvariant(fileName);
  if (fileName.endsWith(".mpd")) {
    return C.TYPE_DASH;
  } else if (fileName.endsWith(".m3u8")) {
    return C.TYPE_HLS;
  } else if (fileName.matches(".*\\.ism(l)?(/manifest(\\(.+\\))?)?")) {
    return C.TYPE_SS;
  } else {
    return C.TYPE_OTHER;
  }
}
 
Example 8
Source File: Util.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes a best guess to infer the type from a file name.
 *
 * @param fileName Name of the file. It can include the path of the file.
 * @return The content type.
 */
@C.ContentType
public static int inferContentType(String fileName) {
  fileName = toLowerInvariant(fileName);
  if (fileName.endsWith(".mpd")) {
    return C.TYPE_DASH;
  } else if (fileName.endsWith(".m3u8")) {
    return C.TYPE_HLS;
  } else if (fileName.matches(".*\\.ism(l)?(/manifest(\\(.+\\))?)?")) {
    return C.TYPE_SS;
  } else {
    return C.TYPE_OTHER;
  }
}
 
Example 9
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 10
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes a best guess to infer the type from a file name.
 *
 * @param fileName Name of the file. It can include the path of the file.
 * @return The content type.
 */
@C.ContentType
public static int inferContentType(String fileName) {
  fileName = toLowerInvariant(fileName);
  if (fileName.endsWith(".mpd")) {
    return C.TYPE_DASH;
  } else if (fileName.endsWith(".m3u8")) {
    return C.TYPE_HLS;
  } else if (fileName.matches(".*\\.ism(l)?(/manifest(\\(.+\\))?)?")) {
    return C.TYPE_SS;
  } else {
    return C.TYPE_OTHER;
  }
}
 
Example 11
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes a best guess to infer the type from a file name.
 *
 * @param fileName Name of the file. It can include the path of the file.
 * @return The content type.
 */
@C.ContentType
public static int inferContentType(String fileName) {
  fileName = Util.toLowerInvariant(fileName);
  if (fileName.endsWith(".mpd")) {
    return C.TYPE_DASH;
  } else if (fileName.endsWith(".m3u8")) {
    return C.TYPE_HLS;
  } else if (fileName.matches(".*\\.ism(l)?(/manifest(\\(.+\\))?)?")) {
    return C.TYPE_SS;
  } else {
    return C.TYPE_OTHER;
  }
}
 
Example 12
Source File: ExoMediaSourceHelper.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
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 13
Source File: ExoPlayerHelper.java    From ExoPlayer-Wrapper with Apache License 2.0 4 votes vote down vote up
@Override
public int[] getSupportedTypes() {
    return new int[]{C.TYPE_DASH, C.TYPE_HLS, C.TYPE_OTHER};
}
 
Example 14
Source File: ExtractorMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int[] getSupportedTypes() {
  return new int[] {C.TYPE_OTHER};
}
 
Example 15
Source File: ExtractorMediaSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int[] getSupportedTypes() {
  return new int[] {C.TYPE_OTHER};
}
 
Example 16
Source File: ExoSourceManager.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * @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 17
Source File: ExtractorMediaSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public int[] getSupportedTypes() {
  return new int[] {C.TYPE_OTHER};
}
 
Example 18
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Makes a best guess to infer the type from a {@link Uri}.
 *
 * @param uri The {@link Uri}.
 * @return The content type.
 */
@C.ContentType
public static int inferContentType(Uri uri) {
  String path = uri.getPath();
  return path == null ? C.TYPE_OTHER : inferContentType(path);
}
 
Example 19
Source File: Util.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Makes a best guess to infer the type from a {@link Uri}.
 *
 * @param uri The {@link Uri}.
 * @return The content type.
 */
@C.ContentType
public static int inferContentType(Uri uri) {
  String path = uri.getPath();
  return path == null ? C.TYPE_OTHER : inferContentType(path);
}
 
Example 20
Source File: Util.java    From K-Sonic with MIT License 2 votes vote down vote up
/**
 * Makes a best guess to infer the type from a {@link Uri}.
 *
 * @param uri The {@link Uri}.
 * @return The content type.
 */
@C.ContentType
public static int inferContentType(Uri uri) {
  String path = uri.getPath();
  return path == null ? C.TYPE_OTHER : inferContentType(path);
}