com.google.android.exoplayer2.source.LoopingMediaSource Java Examples

The following examples show how to use com.google.android.exoplayer2.source.LoopingMediaSource. 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: AndExoPlayerView.java    From MagicalExoPlayer with MIT License 6 votes vote down vote up
public void setSource(String source) {
    MediaSource mediaSource = buildMediaSource(source, null);
    if (mediaSource != null) {
        if (simpleExoPlayer != null) {
            showProgress();

            switch (currLoop) {
                case INFINITE: {
                    LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
                    simpleExoPlayer.prepare(loopingSource, true, false);
                    break;
                }

                case Finite:
                default: {
                    simpleExoPlayer.prepare(mediaSource, true, false);
                    break;
                }
            }
        }
    }
}
 
Example #2
Source File: AndExoPlayerView.java    From MagicalExoPlayer with MIT License 6 votes vote down vote up
public void setSource(String source, HashMap<String, String> extraHeaders) {
    MediaSource mediaSource = buildMediaSource(source, extraHeaders);
    if (mediaSource != null) {
        if (simpleExoPlayer != null) {
            showProgress();

            switch (currLoop) {
                case INFINITE: {
                    LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
                    simpleExoPlayer.prepare(loopingSource, true, false);
                    break;
                }

                case Finite:
                default: {
                    simpleExoPlayer.prepare(mediaSource, true, false);
                    break;
                }
            }
        }
    }
}
 
Example #3
Source File: PlayerTextureView.java    From Mp4Composer-android with MIT License 6 votes vote down vote up
public PlayerTextureView(Context context, String path) {
    super(context, null, 0);

    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "yourApplicationName"));

    // This is the MediaSource representing the media to be played.
    MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
            .createMediaSource(Uri.parse(path));

    LoopingMediaSource loopingMediaSource = new LoopingMediaSource(videoSource);


    // SimpleExoPlayer
    player = ExoPlayerFactory.newSimpleInstance(context);
    // Prepare the player with the source.
    player.prepare(loopingMediaSource);
    player.addVideoListener(this);

    setSurfaceTextureListener(this);
}
 
Example #4
Source File: MediaSourceBuilder.java    From ARVI with Apache License 2.0 6 votes vote down vote up
@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) {
    return new LoopingMediaSource(DEFAULT.buildMediaSource(
        context,
        fileUri,
        fileExtension,
        handler,
        manifestDataSourceFactory,
        mediaDataSourceFactory,
        eventListener
    ));
}
 
Example #5
Source File: PlayerProviderImpl.java    From ARVI with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public final MediaSource createMediaSource(@NonNull Config config,
                                           @NonNull Uri uri,
                                           boolean isLooping) {
    Preconditions.nonNull(config);
    Preconditions.nonNull(uri);

    final PlayerCreator creator = getOrInitCreator(config);
    final MediaSource mediaSource = creator.createMediaSource(uri);

    return (isLooping ? new LoopingMediaSource(mediaSource) : mediaSource);
}
 
Example #6
Source File: PlayerContainerView.java    From Anecdote with Apache License 2.0 5 votes vote down vote up
public void setVideoUrl(String url) {
    mVideoUrl = url;
    boolean needNewPlayer = mPlayer == null;
    if (needNewPlayer) {
        TrackSelection.Factory trackSelectionFactory = new FixedTrackSelection.Factory();
        mTrackSelector = new DefaultTrackSelector(trackSelectionFactory);

        mPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), mTrackSelector);
        mPlayer.addListener(this);

        mPlayerView.setPlayer(mPlayer);
        mPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
    }

    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(),
            Util.getUserAgent(getContext(), "unknown"), null);
    // Produces Extractor instances for parsing the media data.
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    // This is the MediaSource representing the media to be played.
    MediaSource videoSource = new ExtractorMediaSource(Uri.parse(url),
            dataSourceFactory, extractorsFactory, null, null);
    LoopingMediaSource loopingMediaSource = new LoopingMediaSource(videoSource);
    // Prepare the player with the source.
    mPlayer.prepare(loopingMediaSource);
    mPlayer.setVolume(0);
    mPlayerView.requestFocus();
    mPlayer.setPlayWhenReady(true); // autoplay
}
 
Example #7
Source File: ExoPlayer2Helper.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
public void initVideo(Uri videoUrl) {
    ExtractorMediaSource mediaSource = new ExtractorMediaSource(videoUrl, dataSourceFactory, extractorsFactory, handler, this);
    LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource);

    player.prepare(loopingMediaSource);
}
 
Example #8
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 #9
Source File: ExoPlayerUtils.java    From ARVI with Apache License 2.0 2 votes vote down vote up
/**
 * Determines whether the specified {@link MediaSource} is a looping one ({@link LoopingMediaSource}).
 *
 * @param mediaSource the media source
 * @return <strong>true</strong> if the specified media source is not null and is a looping one, <strong>false</strong> otherwise
 */
public static boolean isLooping(@Nullable MediaSource mediaSource) {
    return (mediaSource instanceof LoopingMediaSource);
}