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

The following examples show how to use com.google.android.exoplayer2.source.MediaSource. 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 vote down vote up
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: ReactExoplayerView.java    From react-native-video with MIT License 6 votes vote down vote up
private ArrayList<MediaSource> buildTextSources() {
    ArrayList<MediaSource> textSources = new ArrayList<>();
    if (textTracks == null) {
        return textSources;
    }

    for (int i = 0; i < textTracks.size(); ++i) {
        ReadableMap textTrack = textTracks.getMap(i);
        String language = textTrack.getString("language");
        String title = textTrack.hasKey("title")
                ? textTrack.getString("title") : language + " " + i;
        Uri uri = Uri.parse(textTrack.getString("uri"));
        MediaSource textSource = buildTextSource(title, uri, textTrack.getString("type"),
                language);
        if (textSource != null) {
            textSources.add(textSource);
        }
    }
    return textSources;
}
 
Example #3
Source File: AdsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void onAdSourceInfoRefreshed(MediaSource mediaSource, int adGroupIndex,
    int adIndexInAdGroup, Timeline timeline) {
  Assertions.checkArgument(timeline.getPeriodCount() == 1);
  adGroupTimelines[adGroupIndex][adIndexInAdGroup] = timeline;
  List<MaskingMediaPeriod> mediaPeriods = maskingMediaPeriodByAdMediaSource.remove(mediaSource);
  if (mediaPeriods != null) {
    Object periodUid = timeline.getUidOfPeriod(/* periodIndex= */ 0);
    for (int i = 0; i < mediaPeriods.size(); i++) {
      MaskingMediaPeriod mediaPeriod = mediaPeriods.get(i);
      MediaPeriodId adSourceMediaPeriodId =
          new MediaPeriodId(periodUid, mediaPeriod.id.windowSequenceNumber);
      mediaPeriod.createPeriod(adSourceMediaPeriodId);
    }
  }
  maybeUpdateSourceInfo();
}
 
Example #4
Source File: DownloadHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates download helper.
 *
 * @param downloadType A download type. This value will be used as {@link DownloadRequest#type}.
 * @param uri A {@link Uri}.
 * @param cacheKey An optional cache key.
 * @param mediaSource A {@link MediaSource} for which tracks are selected, or null if no track
 *     selection needs to be made.
 * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for
 *     downloading.
 * @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which tracks
 *     are selected.
 */
public DownloadHelper(
    String downloadType,
    Uri uri,
    @Nullable String cacheKey,
    @Nullable MediaSource mediaSource,
    DefaultTrackSelector.Parameters trackSelectorParameters,
    RendererCapabilities[] rendererCapabilities) {
  this.downloadType = downloadType;
  this.uri = uri;
  this.cacheKey = cacheKey;
  this.mediaSource = mediaSource;
  this.trackSelector = new DefaultTrackSelector(new DownloadTrackSelection.Factory());
  this.rendererCapabilities = rendererCapabilities;
  this.scratchSet = new SparseIntArray();
  trackSelector.setParameters(trackSelectorParameters);
  trackSelector.init(/* listener= */ () -> {}, new DummyBandwidthMeter());
  callbackHandler = new Handler(Util.getLooper());
}
 
Example #5
Source File: BitrateForwarder.java    From no-player with Apache License 2.0 6 votes vote down vote up
@Override
public void onDownstreamFormatChanged(int windowIndex,
                                      @Nullable MediaSource.MediaPeriodId mediaPeriodId,
                                      MediaLoadData mediaLoadData) {
    if (mediaLoadData.trackFormat == null) {
        return;
    }

    if (mediaLoadData.trackType == C.TRACK_TYPE_VIDEO) {
        videoBitrate = Bitrate.fromBitsPerSecond(mediaLoadData.trackFormat.bitrate);
        bitrateChangedListener.onBitrateChanged(audioBitrate, videoBitrate);
    } else if (mediaLoadData.trackType == C.TRACK_TYPE_AUDIO) {
        audioBitrate = Bitrate.fromBitsPerSecond(mediaLoadData.trackFormat.bitrate);
        bitrateChangedListener.onBitrateChanged(audioBitrate, videoBitrate);
    }
}
 
Example #6
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 #7
Source File: ExoMedia.java    From QSVideoPlayer with Apache License 2.0 6 votes vote down vote up
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: ExoPlayerAdapter.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
private void prepareMediaForPlaying() {
    reset();
    if (mMediaSourceUri != null) {
        MediaSource mediaSource = onCreateMediaSource(mMediaSourceUri);
        mPlayer.prepare(mediaSource);
    } else {
        return;
    }

    mPlayer.setAudioStreamType(mAudioStreamType);
    mPlayer.setVideoListener(new SimpleExoPlayer.VideoListener() {
        @Override
        public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
                float pixelWidthHeightRatio) {
            getCallback().onVideoSizeChanged(ExoPlayerAdapter.this, width, height);
        }

        @Override
        public void onRenderedFirstFrame() {
        }
    });
    notifyBufferingStartEnd();
    getCallback().onPlayStateChanged(ExoPlayerAdapter.this);
}
 
Example #9
Source File: DownloadHelper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates download helper.
 *
 * @param downloadType A download type. This value will be used as {@link DownloadRequest#type}.
 * @param uri A {@link Uri}.
 * @param cacheKey An optional cache key.
 * @param mediaSource A {@link MediaSource} for which tracks are selected, or null if no track
 *     selection needs to be made.
 * @param trackSelectorParameters {@link DefaultTrackSelector.Parameters} for selecting tracks for
 *     downloading.
 * @param rendererCapabilities The {@link RendererCapabilities} of the renderers for which tracks
 *     are selected.
 */
public DownloadHelper(
    String downloadType,
    Uri uri,
    @Nullable String cacheKey,
    @Nullable MediaSource mediaSource,
    DefaultTrackSelector.Parameters trackSelectorParameters,
    RendererCapabilities[] rendererCapabilities) {
  this.downloadType = downloadType;
  this.uri = uri;
  this.cacheKey = cacheKey;
  this.mediaSource = mediaSource;
  this.trackSelector = new DefaultTrackSelector(new DownloadTrackSelection.Factory());
  this.rendererCapabilities = rendererCapabilities;
  this.scratchSet = new SparseIntArray();
  trackSelector.setParameters(trackSelectorParameters);
  trackSelector.init(/* listener= */ () -> {}, new DummyBandwidthMeter());
  callbackHandler = new Handler(Util.getLooper());
}
 
Example #10
Source File: ExoPlayerFacadeTest.java    From no-player with Apache License 2.0 5 votes vote down vote up
MediaSource givenMediaSource(Options options) {
    MediaSource mediaSource = mock(MediaSource.class);
    given(
            mediaSourceFactory.create(
                    options,
                    uri,
                    mediaSourceEventListener,
                    defaultBandwidthMeter
            )
    ).willReturn(mediaSource);

    return mediaSource;
}
 
Example #11
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 #12
Source File: DownloadHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public MediaPreparer(MediaSource mediaSource, DownloadHelper downloadHelper) {
  this.mediaSource = mediaSource;
  this.downloadHelper = downloadHelper;
  allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
  pendingMediaPeriods = new ArrayList<>();
  @SuppressWarnings("methodref.receiver.bound.invalid")
  Handler downloadThreadHandler = Util.createHandler(this::handleDownloadHelperCallbackMessage);
  this.downloadHelperHandler = downloadThreadHandler;
  mediaSourceThread = new HandlerThread("DownloadHelper");
  mediaSourceThread.start();
  mediaSourceHandler = Util.createHandler(mediaSourceThread.getLooper(), /* callback= */ this);
  mediaSourceHandler.sendEmptyMessage(MESSAGE_PREPARE_SOURCE);
}
 
Example #13
Source File: PlayerActivity.java    From exoplayer-intro with Apache License 2.0 5 votes vote down vote up
private void initializePlayer() {
  player = ExoPlayerFactory.newSimpleInstance(this);
  playerView.setPlayer(player);

  Uri uri = Uri.parse(getString(R.string.media_url_mp4));
  MediaSource mediaSource = buildMediaSource(uri);

  player.setPlayWhenReady(playWhenReady);
  player.seekTo(currentWindow, playbackPosition);
  player.prepare(mediaSource, false, false);
}
 
Example #14
Source File: VideoPlayer.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #15
Source File: SimpleExoPlayer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState) {
  verifyApplicationThread();
  if (this.mediaSource != null) {
    this.mediaSource.removeEventListener(analyticsCollector);
    analyticsCollector.resetForNewMediaSource();
  }
  this.mediaSource = mediaSource;
  mediaSource.addEventListener(eventHandler, analyticsCollector);
  @AudioFocusManager.PlayerCommand
  int playerCommand = audioFocusManager.handlePrepare(getPlayWhenReady());
  updatePlayWhenReady(getPlayWhenReady(), playerCommand);
  player.prepare(mediaSource, resetPosition, resetState);
}
 
Example #16
Source File: AdsMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void onAdPlaybackState(AdPlaybackState adPlaybackState) {
  if (this.adPlaybackState == null) {
    adGroupMediaSources = new MediaSource[adPlaybackState.adGroupCount][];
    Arrays.fill(adGroupMediaSources, new MediaSource[0]);
    adGroupTimelines = new Timeline[adPlaybackState.adGroupCount][];
    Arrays.fill(adGroupTimelines, new Timeline[0]);
  }
  this.adPlaybackState = adPlaybackState;
  maybeUpdateSourceInfo();
}
 
Example #17
Source File: AdsMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void releaseSourceInternal() {
  super.releaseSourceInternal();
  componentListener.release();
  componentListener = null;
  deferredMediaPeriodByAdMediaSource.clear();
  contentTimeline = null;
  contentManifest = null;
  adPlaybackState = null;
  adGroupMediaSources = new MediaSource[0][];
  adGroupTimelines = new Timeline[0][];
  mainHandler.post(adsLoader::stop);
}
 
Example #18
Source File: VideoPlayer.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * 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: AdsMediaSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void releaseSourceInternal() {
  super.releaseSourceInternal();
  componentListener.release();
  componentListener = null;
  deferredMediaPeriodByAdMediaSource.clear();
  contentTimeline = null;
  contentManifest = null;
  adPlaybackState = null;
  adGroupMediaSources = new MediaSource[0][];
  adGroupTimelines = new Timeline[0][];
  mainHandler.post(adsLoader::stop);
}
 
Example #20
Source File: BitrateForwarder.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadStarted(int windowIndex,
                          @Nullable MediaSource.MediaPeriodId mediaPeriodId,
                          LoadEventInfo loadEventInfo,
                          MediaLoadData mediaLoadData) {
    // TODO: should we send?
}
 
Example #21
Source File: AudioSlidePlayer.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private MediaSource createMediaSource(@NonNull Uri uri) {
  DefaultDataSourceFactory    defaultDataSourceFactory    = new DefaultDataSourceFactory(context, "GenericUserAgent", null);
  AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(context, defaultDataSourceFactory, null);
  ExtractorsFactory           extractorsFactory           = new DefaultExtractorsFactory().setConstantBitrateSeekingEnabled(true);

  return new ExtractorMediaSource.Factory(attachmentDataSourceFactory)
          .setExtractorsFactory(extractorsFactory)
          .createMediaSource(uri);
}
 
Example #22
Source File: ExoPlayerAdapter.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
private void prepareMediaForPlaying() {
    reset();
    if (mMediaSourceUri != null) {
        MediaSource mediaSource = onCreateMediaSource(mMediaSourceUri);
        mPlayer.prepare(mediaSource);
    } else {
        return;
    }

    mPlayer.setAudioStreamType(mAudioStreamType);
    mPlayer.setVideoListener(new SimpleExoPlayer.VideoListener() {
        @Override
        public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
                float pixelWidthHeightRatio) {
            getCallback().onVideoSizeChanged(ExoPlayerAdapter.this, width, height);
        }

        @Override
        public void onRenderedFirstFrame() {
        }
    });
    notifyBufferingStartEnd();
    getCallback().onPlayStateChanged(ExoPlayerAdapter.this);
}
 
Example #23
Source File: AdsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new source that inserts ads linearly with the content specified by {@code
 * contentMediaSource}. Ad media is loaded using {@link ExtractorMediaSource}.
 *
 * @param contentMediaSource The {@link MediaSource} providing the content to play.
 * @param dataSourceFactory Factory for data sources used to load ad media.
 * @param adsLoader The loader for ads.
 * @param adUiViewGroup A {@link ViewGroup} on top of the player that will show any ad UI.
 */
public AdsMediaSource(
    MediaSource contentMediaSource,
    DataSource.Factory dataSourceFactory,
    AdsLoader adsLoader,
    ViewGroup adUiViewGroup) {
  this(
      contentMediaSource,
      new ExtractorMediaSource.Factory(dataSourceFactory),
      adsLoader,
      adUiViewGroup,
      /* eventHandler= */ null,
      /* eventListener= */ null);
}
 
Example #24
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@Override
protected MediaSource buildSource(HostActivity host, String userAgent,
    TransferListener<? super DataSource> mediaTransferListener) {
  DataSource.Factory manifestDataSourceFactory = new DefaultDataSourceFactory(host, userAgent);
  DataSource.Factory mediaDataSourceFactory = new DefaultDataSourceFactory(host, userAgent,
      mediaTransferListener);
  Uri manifestUri = Uri.parse(parameters.manifestUrl);
  DefaultDashChunkSource.Factory chunkSourceFactory = new DefaultDashChunkSource.Factory(
      mediaDataSourceFactory);
  return new DashMediaSource(manifestUri, manifestDataSourceFactory, chunkSourceFactory,
      MIN_LOADABLE_RETRY_COUNT, 0 /* livePresentationDelayMs */, null, null);
}
 
Example #25
Source File: NoPlayerMediaSourceEventListener.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadCanceled(int windowIndex,
                           @Nullable MediaSource.MediaPeriodId mediaPeriodId,
                           LoadEventInfo loadEventInfo,
                           MediaLoadData mediaLoadData) {
    for (MediaSourceEventListener listener : listeners) {
        listener.onLoadCanceled(windowIndex, mediaPeriodId, loadEventInfo, mediaLoadData);
    }
}
 
Example #26
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState) {
  if (this.mediaSource != mediaSource) {
    if (this.mediaSource != null) {
      this.mediaSource.removeEventListener(analyticsCollector);
      analyticsCollector.resetForNewMediaSource();
    }
    mediaSource.addEventListener(eventHandler, analyticsCollector);
    this.mediaSource = mediaSource;
  }
  player.prepare(mediaSource, resetPosition, resetState);
}
 
Example #27
Source File: MainActivity.java    From ExoplayerExample with The Unlicense 5 votes vote down vote up
private void prepareExoPlayerFromByteArray(byte[] data){
    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(null), new DefaultLoadControl());
    exoPlayer.addListener(eventListener);

    final MByteArrayDataSource byteArrayDataSource = new MByteArrayDataSource(data);
    Log.i(TAG,"ByteArrayDataSource constructed.");
    /*
    DataSpec dataSpec = new DataSpec(byteArrayDataSource.getUri());
    try {
        byteArrayDataSource.open(dataSpec);
    } catch (IOException e) {
        e.printStackTrace();
    }
    */

    DataSource.Factory factory = new DataSource.Factory() {
        @Override
        public DataSource createDataSource() {
            return byteArrayDataSource;
        }
    };
    Log.i(TAG,"DataSource.Factory constructed.");

    MediaSource audioSource = new ExtractorMediaSource(byteArrayDataSource.getUri(),
            factory, new DefaultExtractorsFactory(),null,null);
    Log.i(TAG,"Audio source constructed.");
    exoPlayer.prepare(audioSource);
    initMediaControls();
}
 
Example #28
Source File: ExoVideoView.java    From v9porn with MIT License 5 votes vote down vote up
/**
 * Sets the Uri location for the video to play
 *
 * @param uri         The video's Uri
 * @param mediaSource MediaSource that should be used
 */
public void setVideoURI(@Nullable Uri uri, @Nullable MediaSource mediaSource) {
    videoUri = uri;
    videoViewImpl.setVideoUri(uri, mediaSource);

    if (videoControls != null) {
        videoControls.showLoading(true);
    }
}
 
Example #29
Source File: NoPlayerMediaSourceEventListener.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpstreamDiscarded(int windowIndex,
                                MediaSource.MediaPeriodId mediaPeriodId,
                                MediaLoadData mediaLoadData) {
    for (MediaSourceEventListener listener : listeners) {
        listener.onUpstreamDiscarded(windowIndex, mediaPeriodId, mediaLoadData);
    }
}
 
Example #30
Source File: AdsMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new source that inserts ads linearly with the content specified by {@code
 * contentMediaSource}. Ad media is loaded using {@link ProgressiveMediaSource}.
 *
 * @param contentMediaSource The {@link MediaSource} providing the content to play.
 * @param dataSourceFactory Factory for data sources used to load ad media.
 * @param adsLoader The loader for ads.
 * @param adViewProvider Provider of views for the ad UI.
 */
public AdsMediaSource(
    MediaSource contentMediaSource,
    DataSource.Factory dataSourceFactory,
    AdsLoader adsLoader,
    AdsLoader.AdViewProvider adViewProvider) {
  this(
      contentMediaSource,
      new ProgressiveMediaSource.Factory(dataSourceFactory),
      adsLoader,
      adViewProvider);
}