Java 类com.google.android.exoplayer2.source.ConcatenatingMediaSource 实例源码

项目:ExoPlayerSample    文件:PlayListActivity.java   
private void initializePlayer() {
    simpleExoPlayerView.requestFocus();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
    simpleExoPlayerView.setPlayer(player);

    MediaSource[] mediaSources = new MediaSource[videos.size()];
    for (int i = 0; i < videos.size(); i++) {
        mediaSources[i] = buildMediaSource(Uri.parse(videos.get(i).videoUrl));
    }
    MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
            : new ConcatenatingMediaSource(mediaSources);
    player.prepare(mediaSource);
}
项目:transistor    文件:ExoPlayerTest.java   
public void testShuffleModeEnabledChanges() throws Exception {
  Timeline fakeTimeline = new FakeTimeline(/* windowCount= */ 1);
  MediaSource[] fakeMediaSources = {
      new FakeMediaSource(fakeTimeline, null, Builder.VIDEO_FORMAT),
      new FakeMediaSource(fakeTimeline, null, Builder.VIDEO_FORMAT),
      new FakeMediaSource(fakeTimeline, null, Builder.VIDEO_FORMAT)
  };
  ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(false,
      new FakeShuffleOrder(3), fakeMediaSources);
  FakeRenderer renderer = new FakeRenderer(Builder.VIDEO_FORMAT);
  ActionSchedule actionSchedule = new ActionSchedule.Builder("testShuffleModeEnabled")
      .setRepeatMode(Player.REPEAT_MODE_ALL).waitForPositionDiscontinuity() // 0 -> 1
      .setShuffleModeEnabled(true).waitForPositionDiscontinuity()           // 1 -> 0
      .waitForPositionDiscontinuity().waitForPositionDiscontinuity()        // 0 -> 2 -> 1
      .setShuffleModeEnabled(false).setRepeatMode(Player.REPEAT_MODE_OFF)   // 1 -> 2 -> end
      .build();
  ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder()
      .setMediaSource(mediaSource).setRenderers(renderer).setActionSchedule(actionSchedule)
      .build().start().blockUntilEnded(TIMEOUT_MS);
  testRunner.assertPlayedPeriodIndices(0, 1, 0, 2, 1, 2);
  assertTrue(renderer.isEnded);
}
项目:yjPlay    文件:MediaSourceBuilder.java   
/****
 * 初始化
 *
 * @param uris 视频的地址列表
 */
public void setMediaUri(@NonNull Uri... uris) {
    MediaSource[] firstSources = new MediaSource[uris.length];
    int i = 0;
    for (Uri item : uris) {
        firstSources[i] = initMediaSource(item);
        i++;
    }
    mediaSource = new ConcatenatingMediaSource(firstSources);
}
项目:yjPlay    文件:MediaSourceBuilder.java   
/****
 * 初始化
 *
 * @param <T>     你的实体类
 * @param uris 视频的地址列表\
 */
public <T extends ItemVideo> void setMediaUri(@NonNull List<T> uris) {
    MediaSource[] firstSources = new MediaSource[uris.size()];
    int i = 0;
    for (T item : uris) {
        if (item.getVideoUri() != null) {
            firstSources[i] = initMediaSource(Uri.parse(item.getVideoUri()));
        }
        i++;
    }
    mediaSource = new ConcatenatingMediaSource(firstSources);
}
项目:B4A_ExoPlayer    文件:SimpleExoPlayerWrapper.java   
/**
 * Concatenates multiple sources.
 */
public Object CreateListSource (List Sources) {
    MediaSource[] sources = new MediaSource[Sources.getSize()];
    for (int i = 0;i < Sources.getSize();i++)
        sources[i] = (MediaSource)Sources.Get(i);
    return new ConcatenatingMediaSource(sources);
}
项目:Jockey    文件:QueuedExoPlayer.java   
private MediaSource buildRepeatOneMediaSource(DataSource.Factory srcFactory,
                                              ExtractorsFactory extFactory) {

    if (mQueue.isEmpty()) {
        // We need to return an empty MediaSource (can't be null), so return a
        // ConcatenatingMediaSource with nothing to concatenate
        return new ConcatenatingMediaSource();
    }

    Uri uri = mQueue.get(mQueueIndex).getLocation();
    MediaSource source = new ExtractorMediaSource(uri, srcFactory, extFactory, null, null);
    return new LoopingMediaSource(source);
}
项目:Jockey    文件:QueuedExoPlayer.java   
private MediaSource buildNoRepeatMediaSource(DataSource.Factory srcFactory,
                                             ExtractorsFactory extFactory) {

    MediaSource[] queue = new MediaSource[mQueue.size()];

    for (int i = 0; i < queue.length; i++) {
        Uri uri = mQueue.get(i).getLocation();
        queue[i] = new ExtractorMediaSource(uri, srcFactory, extFactory, null, null);
    }

    return new ConcatenatingMediaSource(queue);
}
项目:AesExoPlayer    文件:TestPlayerActivity.java   
private void initPlayer(String url) {
        // 1.创建一个默认TrackSelector,测量播放过程中的带宽。 如果不需要,可以为null。
        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        //从MediaSource中选出media提供给可用的Render S来渲染,在创建播放器时被注入
        TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);
        // 2.创建一个默认的LoadControl
        //Create a default LoadControl 控制MediaSource缓存media
        DefaultLoadControl loadControl = new DefaultLoadControl();
//        BufferingLoadControl bufferingLoadControl = new BufferingLoadControl();
        //生成加载媒体数据的DataSource实例。
//        dataSourceFactory = new DefaultDataSourceFactory(this,
//                Util.getUserAgent(this, "aitrip"), bandwidthMeter);
        //自定义解密工厂
        aitripFactory = new AitripDataSourceFactory(this,
                Util.getUserAgent(this, "aitrip"), bandwidthMeter);
        extractorsFactory = new DefaultExtractorsFactory();
//        factory = new DiyExtractorsFactory();
        FileDataSource fileDataSource = new FileDataSource();
        //test mp3
//        url = "https://storage.googleapis.com/exoplayer-test-media-0/play.mp3";
        // MediaSource代表要播放的媒体。
        videoSource = new ExtractorMediaSource(Uri.parse(url),
                aitripFactory, extractorsFactory, null, null);
        // 3.创建播放器
        player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

        //SimpleExoPlayerView simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.exo_player);
        //设置监听器
        player.addListener(eventListener);
        //装载多个资源
        MediaSource[] mediaSources = new MediaSource[1];
//        mediaSources[0] = buildMediaSource(Uri.parse(huai), "");
//        mediaSources[1] = buildMediaSource(Uri.parse(deng), "");
        mediaSources[0] = buildMediaSource(Uri.parse(deng), "");
//        mediaSources[2] = buildMediaSource(playerUri, "");
//        mediaSources[3] = buildMediaSource(Uri.parse(deng), "");
        ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(mediaSources);

        //设置资源
        player.prepare(mediaSource);
        window = new Timeline.Window();
    }