com.google.android.exoplayer2.upstream.DefaultBandwidthMeter Java Examples

The following examples show how to use com.google.android.exoplayer2.upstream.DefaultBandwidthMeter. 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: ExoPlayerFactory.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/** @deprecated Use {@link ExoPlayer.Builder} instead. */
@Deprecated
@SuppressWarnings("deprecation")
public static ExoPlayer newInstance(
    Context context,
    Renderer[] renderers,
    TrackSelector trackSelector,
    LoadControl loadControl,
    Looper looper) {
  return newInstance(
      context,
      renderers,
      trackSelector,
      loadControl,
      DefaultBandwidthMeter.getSingletonInstance(context),
      looper);
}
 
Example #2
Source File: ExoHostedTest.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
@Override
public final void onStart(HostActivity host, Surface surface) {
  // Build the player.
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
  trackSelector = buildTrackSelector(host, bandwidthMeter);
  String userAgent = "ExoPlayerPlaybackTests";
  DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = buildDrmSessionManager(userAgent);
  player = buildExoPlayer(host, surface, trackSelector, drmSessionManager);
  player.prepare(buildSource(host, Util.getUserAgent(host, userAgent), bandwidthMeter));
  player.addListener(this);
  player.setAudioDebugListener(this);
  player.setVideoDebugListener(this);
  player.setPlayWhenReady(true);
  actionHandler = new Handler();
  // Schedule any pending actions.
  if (pendingSchedule != null) {
    pendingSchedule.start(player, trackSelector, actionHandler);
    pendingSchedule = null;
  }
}
 
Example #3
Source File: ExoMediaPlayer.java    From DKVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void initPlayer() {
    mInternalPlayer = new SimpleExoPlayer.Builder(
            mAppContext,
            mRenderersFactory == null ? mRenderersFactory = new DefaultRenderersFactory(mAppContext) : mRenderersFactory,
            mTrackSelector == null ? mTrackSelector = new DefaultTrackSelector(mAppContext) : mTrackSelector,
            mLoadControl == null ? mLoadControl = new DefaultLoadControl() : mLoadControl,
            DefaultBandwidthMeter.getSingletonInstance(mAppContext),
            Util.getLooper(),
            new AnalyticsCollector(Clock.DEFAULT),
            /* useLazyPreparation= */ true,
            Clock.DEFAULT)
            .build();
    setOptions();

    //播放器日志
    if (VideoViewManager.getConfig().mIsEnableLog && mTrackSelector instanceof MappingTrackSelector) {
        mInternalPlayer.addAnalyticsListener(new EventLogger((MappingTrackSelector) mTrackSelector, "ExoPlayer"));
    }

    mInternalPlayer.addListener(this);
    mInternalPlayer.addVideoListener(this);
}
 
Example #4
Source File: ExoPlayerHelper.java    From ExoPlayer-Wrapper with Apache License 2.0 6 votes vote down vote up
private void init() {
    // Measures bandwidth during playback. Can be null if not required.
    DefaultBandwidthMeter bandwidthMeter =
            new DefaultBandwidthMeter.Builder(mContext).build();

    // Produces DataSource instances through which media data is loaded.
    mDataSourceFactory = new DefaultDataSourceFactory(mContext,
            Util.getUserAgent(mContext, mContext.getString(R.string.app_name)), bandwidthMeter);


    // LoadControl that controls when the MediaSource buffers more media, and how much media is buffered.
    // LoadControl is injected when the player is created.
    //removed deprecated DefaultLoadControl creation method
    DefaultLoadControl.Builder builder = new DefaultLoadControl.Builder();
    builder.setAllocator(new DefaultAllocator(true, 2 * 1024 * 1024));
    builder.setBufferDurationsMs(5000, 5000, 5000, 5000);
    builder.setPrioritizeTimeOverSizeThresholds(true);
    mLoadControl = builder.createDefaultLoadControl();
}
 
Example #5
Source File: PlaybackFragment.java    From androidtv-Leanback with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector);
    mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY);
    mPlaylistActionListener = new PlaylistActionListener(mPlaylist);
    mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener);
    mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this));
    mPlayerGlue.playWhenPrepared();

    play(mVideo);

    ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow();
    setAdapter(mRowsAdapter);
}
 
Example #6
Source File: ExoPlayer2Helper.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
public ExoPlayer2Helper(Context context) {
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    dataSourceFactory = new FileDataSourceFactory(this);
    extractorsFactory = new DefaultExtractorsFactory();

    DefaultTrackSelector trackSelector = new DefaultTrackSelector(bandwidthMeter);
    DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context);
    EventLogger eventLogger = new EventLogger(trackSelector);

    player = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector);
    player.addListener(this);
    player.addListener(eventLogger);
    player.setAudioDebugListener(eventLogger);
    player.setVideoDebugListener(eventLogger);
    player.setMetadataOutput(eventLogger);
    player.setVideoListener(this);
}
 
Example #7
Source File: AndExoPlayerView.java    From MagicalExoPlayer with MIT License 6 votes vote down vote up
private void initializePlayer() {

        if (simpleExoPlayer == null) {

            bandwidthMeter = new DefaultBandwidthMeter();
            extractorsFactory = new DefaultExtractorsFactory();
            trackSelectionFactory = new AdaptiveTrackSelection.Factory();
            trackSelector = new DefaultTrackSelector();

            simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector);

            playerView.setPlayer(simpleExoPlayer);
            simpleExoPlayer.setPlayWhenReady(currPlayWhenReady);
            simpleExoPlayer.seekTo(currentWindow, playbackPosition);
            simpleExoPlayer.addListener(componentListener);
        }
    }
 
Example #8
Source File: VideoPlayer.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
private void setExoViewSource(@NonNull VideoSlide videoSource, boolean autoplay)
    throws IOException
{
  BandwidthMeter         bandwidthMeter             = new DefaultBandwidthMeter();
  TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
  TrackSelector          trackSelector              = new DefaultTrackSelector(videoTrackSelectionFactory);
  LoadControl            loadControl                = new DefaultLoadControl();

  exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
  exoPlayer.addListener(new ExoPlayerListener(window));
  //noinspection ConstantConditions
  exoView.setPlayer(exoPlayer);

  DefaultDataSourceFactory    defaultDataSourceFactory    = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null);
  AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), defaultDataSourceFactory, null);
  ExtractorsFactory           extractorsFactory           = new DefaultExtractorsFactory();

  MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null);

  exoPlayer.prepare(mediaSource);
  exoPlayer.setPlayWhenReady(autoplay);
}
 
Example #9
Source File: PlaybackFragment.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector);
    mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY);
    mPlaylistActionListener = new PlaylistActionListener(mPlaylist);
    mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener);
    mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this));
    mPlayerGlue.playWhenPrepared();

    play(mVideo);

    ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow();
    setAdapter(mRowsAdapter);
}
 
Example #10
Source File: CompositeTrackSelectorCreator.java    From no-player with Apache License 2.0 6 votes vote down vote up
CompositeTrackSelector create(Options options, DefaultBandwidthMeter bandwidthMeter) {
    TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(
            bandwidthMeter,
            options.minDurationBeforeQualityIncreaseInMillis(),
            AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
            AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
            AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION,
            AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
            AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
            Clock.DEFAULT
    );
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
    DefaultTrackSelector.Parameters trackSelectorParameters = trackSelector.buildUponParameters()
            .setMaxVideoBitrate(options.maxVideoBitrate())
            .build();
    trackSelector.setParameters(trackSelectorParameters);

    ExoPlayerTrackSelector exoPlayerTrackSelector = ExoPlayerTrackSelector.newInstance(trackSelector);
    ExoPlayerAudioTrackSelector audioTrackSelector = new ExoPlayerAudioTrackSelector(exoPlayerTrackSelector);
    ExoPlayerVideoTrackSelector videoTrackSelector = new ExoPlayerVideoTrackSelector(exoPlayerTrackSelector);
    ExoPlayerSubtitleTrackSelector subtitleTrackSelector = new ExoPlayerSubtitleTrackSelector(exoPlayerTrackSelector);
    return new CompositeTrackSelector(trackSelector, audioTrackSelector, videoTrackSelector, subtitleTrackSelector);
}
 
Example #11
Source File: PlayerActivity.java    From GPUVideo-android with MIT License 6 votes vote down vote up
private void setUpSimpleExoPlayer() {

        TrackSelector trackSelector = new DefaultTrackSelector();

        // Measures bandwidth during playback. Can be null if not required.
        DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
        // Produces DataSource instances through which media data is loaded.
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "yourApplicationName"), defaultBandwidthMeter);
        MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(STREAM_URL_MP4_VOD_LONG));

        // SimpleExoPlayer
        player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
        // Prepare the player with the source.
        player.prepare(mediaSource);
        player.setPlayWhenReady(true);

    }
 
Example #12
Source File: ExoPlayerFactory.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link SimpleExoPlayer.Builder} instead. The {@link DrmSessionManager} cannot
 *     be passed to {@link SimpleExoPlayer.Builder} and should instead be injected into the {@link
 *     MediaSource} factories.
 */
@Deprecated
@SuppressWarnings("deprecation")
public static SimpleExoPlayer newSimpleInstance(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    LoadControl loadControl,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    AnalyticsCollector analyticsCollector,
    Looper looper) {
  return newSimpleInstance(
      context,
      renderersFactory,
      trackSelector,
      loadControl,
      drmSessionManager,
      DefaultBandwidthMeter.getSingletonInstance(context),
      analyticsCollector,
      looper);
}
 
Example #13
Source File: MediaSourceFactory.java    From no-player with Apache License 2.0 6 votes vote down vote up
public MediaSource create(Options options,
                          Uri uri,
                          MediaSourceEventListener mediaSourceEventListener,
                          DefaultBandwidthMeter bandwidthMeter) {
    DefaultDataSourceFactory defaultDataSourceFactory = createDataSourceFactory(bandwidthMeter);
    switch (options.contentType()) {
        case HLS:
            return createHlsMediaSource(defaultDataSourceFactory, uri, mediaSourceEventListener);
        case H264:
            return createH264MediaSource(defaultDataSourceFactory, uri, mediaSourceEventListener);
        case DASH:
            return createDashMediaSource(defaultDataSourceFactory, uri, mediaSourceEventListener);
        default:
            throw new UnsupportedOperationException("Content type: " + options + " is not supported.");
    }
}
 
Example #14
Source File: VideoViewActivity.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
private void initializePlayer() {


        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); //test

        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);

        // 2. Create the player
        mExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);

        ////Set media controller
        mPlayerView.setUseController(true);//set to true or false to see controllers
        mPlayerView.requestFocus();
        // Bind the player to the view.
        mPlayerView.setPlayer(mExoPlayer);

        DataSpec dataSpec = new DataSpec(mMediaUri);
        final InputStreamDataSource inputStreamDataSource = new InputStreamDataSource(this, dataSpec);
        try {
            inputStreamDataSource.open(dataSpec);
        } catch (IOException e) {
            e.printStackTrace();
        }

        DataSource.Factory factory = new DataSource.Factory() {

            @Override
            public DataSource createDataSource() {
                return inputStreamDataSource;
            }
        };
        MediaSource audioSource = new ExtractorMediaSource(inputStreamDataSource.getUri(),
                factory, new DefaultExtractorsFactory(), null, null);

        mExoPlayer.prepare(audioSource);
        mExoPlayer.setPlayWhenReady(true); //run file/link when ready to play.

    }
 
Example #15
Source File: DataSourceUtil.java    From react-native-video with MIT License 5 votes vote down vote up
private static HttpDataSource.Factory buildHttpDataSourceFactory(ReactContext context, DefaultBandwidthMeter bandwidthMeter, Map<String, String> requestHeaders) {
    OkHttpClient client = OkHttpClientProvider.getOkHttpClient();
    CookieJarContainer container = (CookieJarContainer) client.cookieJar();
    ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
    container.setCookieJar(new JavaNetCookieJar(handler));
    OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(client, getUserAgent(context), bandwidthMeter);

    if (requestHeaders != null)
        okHttpDataSourceFactory.getDefaultRequestProperties().set(requestHeaders);

    return okHttpDataSourceFactory;
}
 
Example #16
Source File: MediaSourceFactory.java    From no-player with Apache License 2.0 5 votes vote down vote up
private DefaultDataSourceFactory createDataSourceFactory(DefaultBandwidthMeter bandwidthMeter) {
    if (dataSourceFactory.isPresent()) {
        return new DefaultDataSourceFactory(context, bandwidthMeter, dataSourceFactory.get());
    } else {
        DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
                userAgent,
                bandwidthMeter,
                DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
                allowCrossProtocolRedirects
        );

        return new DefaultDataSourceFactory(context, bandwidthMeter, httpDataSourceFactory);
    }
}
 
Example #17
Source File: MediaVideoView.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
CacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) {
    super();
    this.context = context;
    this.maxCacheSize = maxCacheSize;
    this.maxFileSize = maxFileSize;
    String userAgent = Util.getUserAgent(context, context.getString(R.string.app_name));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    defaultDatasourceFactory = new DefaultDataSourceFactory(this.context, bandwidthMeter,
            new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter));
}
 
Example #18
Source File: ExoFFmpegPlayer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
public ExoFFmpegPlayer(Context context) {

        super(context,
                new SimpleRendersFactory(context),
                new DefaultTrackSelector(),
                new DefaultLoadControl(),
                null,
                new DefaultBandwidthMeter.Builder().build(),
                new AnalyticsCollector.Factory(),
                Clock.DEFAULT,
                Util.getLooper());
    }
 
Example #19
Source File: ExoFFmpegPlayer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
public ExoFFmpegPlayer(Context context, TrackSelector trackSelector) {

        super(context,
                new SimpleRendersFactory(context),
                trackSelector,
                new DefaultLoadControl(),
                null,
                new DefaultBandwidthMeter.Builder().build(),
                new AnalyticsCollector.Factory(),
                Clock.DEFAULT,
                Util.getLooper());
    }
 
Example #20
Source File: ExoMediaPlayer.java    From VideoDemoJava with MIT License 5 votes vote down vote up
public ExoMediaPlayer(){
    mAppContext = AppContextAttach.getApplicationContext();
    RenderersFactory renderersFactory = new DefaultRenderersFactory(mAppContext);
    DefaultTrackSelector trackSelector =
            new DefaultTrackSelector();
    mInternalPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector);

    // Measures bandwidth during playback. Can be null if not required.
    mBandwidthMeter = new DefaultBandwidthMeter();

    mInternalPlayer.addListener(mEventListener);

}
 
Example #21
Source File: StoryAudioPlayer.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
private SimpleExoPlayer getOrCreatePlayer() {
    if (player == null) {
        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
        DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);

        concatenatingMediaSource = new ConcatenatingMediaSource();
        player.prepare(concatenatingMediaSource);

    }
    return player;
}
 
Example #22
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
private MediaSource getMediaSource(String videoUrl){
        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        // Produces DataSource instances through which media data is loaded.
//        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "Loop"), bandwidthMeter);
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(LoopApplication.getInstance().getApplicationContext(), Util.getUserAgent(LoopApplication.getInstance().getApplicationContext(), "Loop"), bandwidthMeter);
        // Produces Extractor instances for parsing the media data.
        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        // This is the MediaSource representing the media to be played.
        MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(videoUrl),
                dataSourceFactory, extractorsFactory, null, null);
        // Loops the video indefinitely.
//        LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
        return mediaSource;
    }
 
Example #23
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 5 votes vote down vote up
private TrackSelector createTrackSelector(){
    // Create a default TrackSelector
    // Measures bandwidth during playback. Can be null if not required.
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector =
            new DefaultTrackSelector(videoTrackSelectionFactory);
    return trackSelector;
}
 
Example #24
Source File: ExoMediaPlayer.java    From PlayerBase with Apache License 2.0 5 votes vote down vote up
public ExoMediaPlayer(){
    mAppContext = AppContextAttach.getApplicationContext();
    RenderersFactory renderersFactory = new DefaultRenderersFactory(mAppContext);
    DefaultTrackSelector trackSelector =
            new DefaultTrackSelector(mAppContext);
    mInternalPlayer = new SimpleExoPlayer.Builder(mAppContext, renderersFactory)
            .setTrackSelector(trackSelector).build();

    // Measures bandwidth during playback. Can be null if not required.
    mBandwidthMeter = new DefaultBandwidthMeter.Builder(mAppContext).build();

    mInternalPlayer.addListener(mEventListener);

}
 
Example #25
Source File: ProviderTvPlayer.java    From xipl with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes and prepares the player but doesn't make it play the content.
 *
 * @param context the context needed to initialize the player.
 */
private void init(Context context) {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
    player.prepare(getMediaSource(context));
}
 
Example #26
Source File: YouTubePlayerV2Fragment.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Play video.
 *
 * @param videoUri  The Uri of the video that is going to be played.
 */
private void playVideo(Uri videoUri) {
	DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(getContext(), "ST. Agent", new DefaultBandwidthMeter());
	ExtractorMediaSource.Factory extMediaSourceFactory = new ExtractorMediaSource.Factory(dataSourceFactory);
	ExtractorMediaSource mediaSource = extMediaSourceFactory.createMediaSource(videoUri);
	player.prepare(mediaSource);

	if (playerInitialPosition > 0)
		player.seekTo(playerInitialPosition);
}
 
Example #27
Source File: YouTubePlayerV2Fragment.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
private SimpleExoPlayer createExoPlayer() {
	DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

	TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
	DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
	Context context = getContext();
	DefaultRenderersFactory defaultRenderersFactory = new DefaultRenderersFactory(context);

	return ExoPlayerFactory.newSimpleInstance(getContext(), defaultRenderersFactory, trackSelector, new DefaultLoadControl(), null, bandwidthMeter);
}
 
Example #28
Source File: ExoVideoView.java    From ExoVideoView with Apache License 2.0 5 votes vote down vote up
private void createExoPlayer(MediaSourceCreator creator) {
    if (player != null) {
        releasePlayer();
    }

    DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext());
    renderersFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
    SimpleExoPlayer.Builder builder = new SimpleExoPlayer.Builder(getContext(), renderersFactory);
    TrackSelection.Factory adaptiveTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory();
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(getContext(),new AdaptiveTrackSelection.Factory());
    builder.setTrackSelector(new DefaultTrackSelector(getContext(),adaptiveTrackSelectionFactory));
    builder.setTrackSelector(trackSelector);
    builder.setBandwidthMeter(new DefaultBandwidthMeter.Builder(getContext()).build());
    SimpleExoPlayer internalPlayer = builder.build();
    internalPlayer.addListener(componentListener);
    internalPlayer.addListener(creator.getEventLogger());
    internalPlayer.addMetadataOutput(creator.getEventLogger());
    setPlayer(internalPlayer);
}
 
Example #29
Source File: GSYExoSubTitlePlayer.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
public MediaSource getTextSource(Uri subTitle) {
    //todo C.SELECTION_FLAG_AUTOSELECT language MimeTypes
    Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, C.SELECTION_FLAG_FORCED, "en");

    DefaultHttpDataSourceFactory factory = new DefaultHttpDataSourceFactory(Util.getUserAgent(mAppContext,
            "GSYExoSubTitlePlayer"), new DefaultBandwidthMeter.Builder(mAppContext).build(),
            50000,
            50000, true);

    MediaSource textMediaSource = new SingleSampleMediaSource.Factory(new DefaultDataSourceFactory(mAppContext, null,
            factory))
            .createMediaSource(subTitle, textFormat, C.TIME_UNSET);
    return textMediaSource;

}
 
Example #30
Source File: ExoPlayerFacade.java    From no-player with Apache License 2.0 5 votes vote down vote up
void loadVideo(PlayerSurfaceHolder playerSurfaceHolder,
               DrmSessionCreator drmSessionCreator,
               Uri uri,
               Options options,
               ExoPlayerForwarder forwarder,
               MediaCodecSelector mediaCodecSelector) {
    this.options = options;

    DefaultBandwidthMeter bandwidthMeter = bandwidthMeterCreator.create(options.maxInitialBitrate());

    compositeTrackSelector = trackSelectorCreator.create(options, bandwidthMeter);
    exoPlayer = exoPlayerCreator.create(
            drmSessionCreator,
            forwarder.drmSessionEventListener(),
            mediaCodecSelector,
            compositeTrackSelector.trackSelector()
    );
    rendererTypeRequester = rendererTypeRequesterCreator.createfrom(exoPlayer);
    exoPlayer.addListener(forwarder.exoPlayerEventListener());
    exoPlayer.addAnalyticsListener(forwarder.analyticsListener());
    exoPlayer.addVideoListener(forwarder.videoListener());

    setMovieAudioAttributes(exoPlayer);

    MediaSource mediaSource = mediaSourceFactory.create(
            options,
            uri,
            forwarder.mediaSourceEventListener(),
            bandwidthMeter
    );
    attachToSurface(playerSurfaceHolder);

    boolean hasInitialPosition = options.getInitialPositionInMillis().isPresent();
    if (hasInitialPosition) {
        Long initialPositionInMillis = options.getInitialPositionInMillis().get();
        exoPlayer.seekTo(initialPositionInMillis);
    }

    exoPlayer.prepare(mediaSource, !hasInitialPosition, DO_NOT_RESET_STATE);
}