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

The following examples show how to use com.google.android.exoplayer2.upstream.DefaultDataSourceFactory. 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: 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 #3
Source File: ExoPlayerFragment.java    From carstream-android-auto with Apache License 2.0 6 votes vote down vote up
private MediaSource buildMediaSource(PlayerQueue playerQueue) {
    ArrayList<MediaSource> mediaSources = new ArrayList<>();
    File[] currentQueue = playerQueue.getCurrentQueue();
    for (File file : currentQueue) {
        Uri fileUri = Uri.fromFile(file);
        String userAgent = Util.getUserAgent(getContext(), "CarStream");
        if (file != null && (file.getName().endsWith(".m3u") || file.getName().endsWith(".m3u8"))) {
            Handler mHandler = new Handler();
            DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), userAgent);
            HlsMediaSource mediaSource = new HlsMediaSource(fileUri, defaultDataSourceFactory, 1800000,
                    mHandler, null);
            mediaSources.add(mediaSource);
        } else {
            ExtractorMediaSource extractorMediaSource = new ExtractorMediaSource(fileUri,
                    new DefaultDataSourceFactory(getContext(), userAgent),
                    new DefaultExtractorsFactory(), null, null);
            mediaSources.add(extractorMediaSource);
        }
    }
    ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(mediaSources.toArray(new MediaSource[mediaSources.size()]));
    return concatenatingMediaSource;
}
 
Example #4
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 #5
Source File: VideoPlayer.java    From media_player with MIT License 6 votes vote down vote up
private MediaSource buildMediaSource(Uri uri, DataSource.Factory mediaDataSourceFactory, Context context) {
    int type = Util.inferContentType(uri.getLastPathSegment());
    switch (type) {
    case C.TYPE_SS:
        return new SsMediaSource.Factory(new DefaultSsChunkSource.Factory(mediaDataSourceFactory),
                new DefaultDataSourceFactory(context, null, mediaDataSourceFactory)).createMediaSource(uri);
    case C.TYPE_DASH:
        return new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
                new DefaultDataSourceFactory(context, null, mediaDataSourceFactory)).createMediaSource(uri);
    case C.TYPE_HLS:
        return new HlsMediaSource.Factory(mediaDataSourceFactory).createMediaSource(uri);
    case C.TYPE_OTHER:
        return new ExtractorMediaSource.Factory(mediaDataSourceFactory)
                .setExtractorsFactory(new DefaultExtractorsFactory()).createMediaSource(uri);
    default: {
        throw new IllegalStateException("Unsupported type: " + type);
    }
    }
}
 
Example #6
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 #7
Source File: VideoPlayerComponent.java    From android-arch-components-lifecycle with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
    if (player == null) {
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
        player.addListener(this);
        DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context,
                Util.getUserAgent(context, "testApp"), bandwidthMeter);

        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        ExtractorMediaSource videoSource = new ExtractorMediaSource(Uri.parse(videoUrl),
                dataSourceFactory, extractorsFactory, null, null);
        simpleExoPlayerView.setPlayer(player);
        player.setPlayWhenReady(true);

        boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
        if (haveResumePosition) {
            Log.d(TAG, "Have Resume position true!" + resumePosition);
            player.seekTo(resumeWindow, resumePosition);
        }

        player.prepare(videoSource, !haveResumePosition, false);

    }
}
 
Example #8
Source File: DefaultPlayerCreator.java    From ARVI with Apache License 2.0 6 votes vote down vote up
public DefaultPlayerCreator(@NonNull PlayerProvider playerProvider, @NonNull Config config) {
    Preconditions.nonNull(playerProvider);
    Preconditions.nonNull(config);

    this.playerProvider = checkNonNull(playerProvider);
    this.trackSelector = new DefaultTrackSelector();
    this.loadControl = config.loadControl;
    this.bandwidthMeter = config.meter;
    this.mediaSourceBuilder = config.mediaSourceBuilder;
    this.renderersFactory = new MultiDrmRendererFactory(
        playerProvider.getContext(),
        config.drmSessionManagers,
        config.extensionMode
    );
    this.mediaDataSourceFactory = createDataSourceFactory(playerProvider, config);
    this.manifestDataSourceFactory = new DefaultDataSourceFactory(playerProvider.getContext(), playerProvider.getLibraryName());
    this.drmSessionManagers = config.drmSessionManagers;
}
 
Example #9
Source File: ExoMediaPlayer.java    From VideoDemoJava with MIT License 6 votes vote down vote up
private MediaSource getMediaSource(Uri uri){
    int contentType = Util.inferContentType(uri);
    DefaultDataSourceFactory dataSourceFactory =
            new DefaultDataSourceFactory(mAppContext,
                    Util.getUserAgent(mAppContext, mAppContext.getPackageName()), mBandwidthMeter);
    switch (contentType) {
        case C.TYPE_DASH:
            DefaultDashChunkSource.Factory factory = new DefaultDashChunkSource.Factory(dataSourceFactory);
            return new DashMediaSource(uri, dataSourceFactory, factory, null, null);
        case C.TYPE_SS:
            DefaultSsChunkSource.Factory ssFactory = new DefaultSsChunkSource.Factory(dataSourceFactory);
            return new SsMediaSource(uri, dataSourceFactory, ssFactory, null, null);
        case C.TYPE_HLS:
            return new HlsMediaSource(uri, dataSourceFactory, null, null);

        case C.TYPE_OTHER:
        default:
            // This is the MediaSource representing the media to be played.
            ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
            return new ExtractorMediaSource(uri,
                    dataSourceFactory, extractorsFactory, null, null);
    }
}
 
Example #10
Source File: KExoMediaPlayer.java    From K-Sonic with MIT License 6 votes vote down vote up
public KExoMediaPlayer(Context context) {
    this.context = context.getApplicationContext();

    // =========@Init@=========
    TrackSelection.Factory trackSelectionFactory =
            new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);

    player = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector, new DefaultLoadControl(),
            null);
    player.addListener(eventLogger);
    player.addListener(playerListener);
    player.setVideoListener(playerListener);
    player.setPlayWhenReady(false);

    mainHandler = new Handler();
    userAgent = Util.getUserAgent(this.context, "KExoMediaPlayer");
    mediaDataSourceFactory = new DefaultDataSourceFactory(this.context, userAgent, BANDWIDTH_METER);
}
 
Example #11
Source File: KExoMediaPlayer.java    From K-Sonic with MIT License 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, new DefaultDataSourceFactory(context, userAgent),
                    new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
        case C.TYPE_DASH:
            return new DashMediaSource(uri, new DefaultDataSourceFactory(context, userAgent),
                    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 #12
Source File: MediaPlayback21.java    From Melophile with Apache License 2.0 6 votes vote down vote up
@Override
public void startPlayer() {
  if (exoPlayer == null) {
    exoPlayer =
            ExoPlayerFactory.newSimpleInstance(
                    context, new DefaultTrackSelector(), new DefaultLoadControl());
    exoPlayer.addListener(this);
  }
  exoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
          context, Util.getUserAgent(context, "uamp"), null);
  ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
  MediaSource mediaSource = new ExtractorMediaSource(
          Uri.parse(currentUrl), dataSourceFactory, extractorsFactory, null, null);
  exoPlayer.prepare(mediaSource);
  configPlayer();
}
 
Example #13
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 #14
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 #15
Source File: MainActivity.java    From ExoplayerExample with The Unlicense 6 votes vote down vote up
/**
 * Prepares exoplayer for audio playback from a remote URL audiofile. Should work with most
 * popular audiofile types (.mp3, .m4a,...)
 * @param uri Provide a Uri in a form of Uri.parse("http://blabla.bleble.com/blublu.mp3)
 */
private void prepareExoPlayerFromURL(Uri uri){

    TrackSelector trackSelector = new DefaultTrackSelector();

    LoadControl loadControl = new DefaultLoadControl();

    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

    DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), null);
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    MediaSource audioSource = new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null);
    exoPlayer.addListener(eventListener);

    exoPlayer.prepare(audioSource);
    initMediaControls();
}
 
Example #16
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 #17
Source File: ExoPlayerMediaSourceBuilder.java    From PreviewSeekBar with Apache License 2.0 6 votes vote down vote up
public MediaSource getMediaSource(boolean preview) {
    switch (streamType) {
        case C.TYPE_SS:
            return new SsMediaSource.Factory(new DefaultDataSourceFactory(context, null,
                    getHttpDataSourceFactory(preview))).createMediaSource(uri);
        case C.TYPE_DASH:
            return new DashMediaSource.Factory(new DefaultDataSourceFactory(context, null,
                    getHttpDataSourceFactory(preview))).createMediaSource(uri);
        case C.TYPE_HLS:
            return new HlsMediaSource.Factory(getDataSourceFactory(preview)).createMediaSource(uri);
        case C.TYPE_OTHER:
            return new ProgressiveMediaSource.Factory(getDataSourceFactory(preview)).createMediaSource(uri);
        default: {
            throw new IllegalStateException("Unsupported type: " + streamType);
        }
    }
}
 
Example #18
Source File: PlayerActivity.java    From exoplayer-intro with Apache License 2.0 6 votes vote down vote up
private MediaSource buildMediaSource(Uri uri) {
  // These factories are used to construct two media sources below
  DataSource.Factory dataSourceFactory =
          new DefaultDataSourceFactory(this, "exoplayer-codelab");
  ProgressiveMediaSource.Factory mediaSourceFactory =
          new ProgressiveMediaSource.Factory(dataSourceFactory);

  // Create a media source using the supplied URI
  MediaSource mediaSource1 = mediaSourceFactory.createMediaSource(uri);

  // Additionally create a media source using an MP3
  Uri audioUri = Uri.parse(getString(R.string.media_url_mp3));
  MediaSource mediaSource2 = mediaSourceFactory.createMediaSource(audioUri);

  return new ConcatenatingMediaSource(mediaSource1, mediaSource2);
}
 
Example #19
Source File: MediaSourceFactory.java    From no-player with Apache License 2.0 5 votes vote down vote up
private MediaSource createHlsMediaSource(DefaultDataSourceFactory defaultDataSourceFactory,
                                         Uri uri,
                                         MediaSourceEventListener mediaSourceEventListener) {
    HlsMediaSource.Factory factory = new HlsMediaSource.Factory(defaultDataSourceFactory);
    HlsMediaSource hlsMediaSource = factory.createMediaSource(uri);
    hlsMediaSource.addEventListener(handler, mediaSourceEventListener);
    return hlsMediaSource;
}
 
Example #20
Source File: MediaPlayerSingleton.java    From dtube-mobile-unofficial with Apache License 2.0 5 votes vote down vote up
private MediaSource getMediaSource(String url){
    Uri uri = Uri.parse(url);

    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(c,
            Util.getUserAgent(c, "DtubeClient"));
    // This is the MediaSource representing the media to be played.
    return new ExtractorMediaSource.Factory(dataSourceFactory)
            .createMediaSource(uri);
}
 
Example #21
Source File: ExoMediaPlayer.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void init(@NonNull final Context context) {
    final TrackSelector trackSelector = new DefaultTrackSelector();

    exoPlayer = ExoPlayerFactory.newSimpleInstance(
            new DefaultRenderersFactory(context), trackSelector, new DefaultLoadControl());
    exoPlayer.addListener(mEventListener);
    exoPlayer.addAudioDebugListener(mAudioRendererEventListener);

    dataSourceFactory = new DefaultDataSourceFactory(context,
            Util.getUserAgent(context, "Painless Music Player"));
}
 
Example #22
Source File: LocalPlayback.java    From klingar with Apache License 2.0 5 votes vote down vote up
LocalPlayback(Context context, MusicController musicController, AudioManager audioManager,
              WifiManager wifiManager, Call.Factory callFactory) {
  this.context = context;
  this.musicController = musicController;
  this.audioManager = audioManager;
  this.wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "klingar");
  String agent = Util.getUserAgent(context, context.getResources().getString(R.string.app_name));
  this.mediaSourceFactory = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(
      context, null, new OkHttpDataSourceFactory(callFactory, agent)));
}
 
Example #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
Source File: Alarmio.java    From Alarmio with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    DebugUtils.setup(this);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    listeners = new ArrayList<>();
    alarms = new ArrayList<>();
    timers = new ArrayList<>();

    player = new SimpleExoPlayer.Builder(this).build();
    player.addListener(this);

    DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), null);
    hlsMediaSourceFactory = new HlsMediaSource.Factory(dataSourceFactory);
    progressiveMediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory);

    int alarmLength = PreferenceData.ALARM_LENGTH.getValue(this);
    for (int id = 0; id < alarmLength; id++) {
        alarms.add(new AlarmData(id, this));
    }

    int timerLength = PreferenceData.TIMER_LENGTH.getValue(this);
    for (int id = 0; id < timerLength; id++) {
        TimerData timer = new TimerData(id, this);
        if (timer.isSet())
            timers.add(timer);
    }

    if (timerLength > 0)
        startService(new Intent(this, TimerService.class));

    SleepReminderService.refreshSleepTime(this);
}
 
Example #30
Source File: VodPlaybackFragment.java    From xipl with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the usage of the internal player used by the library.
 */
protected void configureInternalPlayer() {
    Bundle arguments = getArguments();
    String url = arguments.getString(VodTvSectionFragment.AV_CONTENT_LINK_BUNDLE);

    // Configure the ExoPlayer instance that will be used to play the media
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getActivity(), Util.getUserAgent(getActivity(), getActivity().getApplicationInfo().loadLabel(getActivity().getPackageManager()).toString()));
    mSimpleExoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getActivity()), new DefaultTrackSelector(), new DefaultLoadControl());
    ExtractorMediaSource.Factory factory = new ExtractorMediaSource.Factory(dataSourceFactory);
    Uri uri = Uri.parse(url);
    mSimpleExoPlayer.prepare(factory.createMediaSource(uri));
    mSimpleExoPlayer.addListener(new Player.DefaultEventListener() {
        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            super.onPlayerStateChanged(playWhenReady, playbackState);
            if (playbackState == Player.STATE_READY && mPlayerGlue.getSeekProvider() == null) {
                mPlayerGlue.setSeekProvider(new ProviderPlaybackSeekDataProvider(mPlayerGlue.getDuration()));

                // Force content to fit to screen if wanted.
                if (getVodProperties().isVideoFitToScreen()) {
                    DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
                    mPlayerGlue.getPlayerAdapter().getCallback().onVideoSizeChanged(mPlayerGlue.getPlayerAdapter(), displayMetrics.widthPixels, displayMetrics.heightPixels);
                }
            }
        }
    });

    // Configure Leanback for playback. Use the updatePeriodMs used before in ExoPlayerAdapter
    LeanbackPlayerAdapter playerAdapter = new LeanbackPlayerAdapter(getActivity(), mSimpleExoPlayer, 16);
    mPlayerGlue = new PlaybackTransportControlGlue<>(getActivity(), playerAdapter);
    mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this));
    mPlayerGlue.setTitle(arguments.getString(VodTvSectionFragment.AV_CONTENT_TITLE_BUNDLE));
    mPlayerGlue.setSubtitle(arguments.getString(VodTvSectionFragment.AV_CONTENT_GROUP_BUNDLE));

    setBackgroundType(BG_LIGHT);
    mPlayerGlue.playWhenPrepared();
}