com.google.android.exoplayer2.extractor.DefaultExtractorsFactory Java Examples

The following examples show how to use com.google.android.exoplayer2.extractor.DefaultExtractorsFactory. 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: 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 #2
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 #3
Source File: MainActivity.java    From ExoplayerExample with The Unlicense 6 votes vote down vote up
private void prepareExoPlayerFromRawResourceUri(Uri uri){
    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(null), new DefaultLoadControl());
    exoPlayer.addListener(eventListener);

    DataSpec dataSpec = new DataSpec(uri);
    final RawResourceDataSource rawResourceDataSource = new RawResourceDataSource(this);
    try {
        rawResourceDataSource.open(dataSpec);
    } catch (RawResourceDataSource.RawResourceDataSourceException e) {
        e.printStackTrace();
    }

    DataSource.Factory factory = new DataSource.Factory() {
        @Override
        public DataSource createDataSource() {
            return rawResourceDataSource;
        }
    };

    MediaSource audioSource = new ExtractorMediaSource(rawResourceDataSource.getUri(),
            factory, new DefaultExtractorsFactory(), null, null);

    exoPlayer.prepare(audioSource);
    initMediaControls();
}
 
Example #4
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 #5
Source File: MainActivity.java    From ExoplayerExample with The Unlicense 6 votes vote down vote up
/**
 * Prepares exoplayer for audio playback from a local file
 * @param uri
 */
private void prepareExoPlayerFromFileUri(Uri uri){
    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector(null), new DefaultLoadControl());
    exoPlayer.addListener(eventListener);

    DataSpec dataSpec = new DataSpec(uri);
    final FileDataSource fileDataSource = new FileDataSource();
    try {
        fileDataSource.open(dataSpec);
    } catch (FileDataSource.FileDataSourceException e) {
        e.printStackTrace();
    }

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

    exoPlayer.prepare(audioSource);
    initMediaControls();
}
 
Example #6
Source File: LiveVideoPlayerActivity.java    From LiveVideoBroadcaster with Apache License 2.0 6 votes vote down vote up
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
  int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri)
          : Util.inferContentType("." + overrideExtension);
  switch (type) {
    case C.TYPE_SS:
      return new SsMediaSource(uri, buildDataSourceFactory(false),
              new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
    case C.TYPE_DASH:
      return new DashMediaSource(uri, buildDataSourceFactory(false),
              new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
    case C.TYPE_HLS:
      return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger);
    case C.TYPE_OTHER:
      if (uri.getScheme().equals("rtmp")) {
        return new ExtractorMediaSource(uri, rtmpDataSourceFactory, new DefaultExtractorsFactoryForFLV(),
                mainHandler, eventLogger);
      }
      else {
        return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
                mainHandler, eventLogger);
      }
    default: {
      throw new IllegalStateException("Unsupported type: " + type);
    }
  }
}
 
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: 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 #9
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 #10
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 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, buildDataSourceFactory(false),
                    new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
        case C.TYPE_DASH:
            return new DashMediaSource(uri, buildDataSourceFactory(false),
                    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 #11
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 #12
Source File: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
	int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri)
		: Util.inferContentType("." + overrideExtension);
	switch (type) {
		case C.TYPE_SS:
			return new SsMediaSource(uri, buildDataSourceFactory(false),
									 new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
		case C.TYPE_DASH:
			return new DashMediaSource(uri, buildDataSourceFactory(false),
									   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 #13
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 #14
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 #15
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 #16
Source File: VideoExoPlayer.java    From TigerVideo with Apache License 2.0 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, buildDataSourceFactory(false),
                        new DefaultSsChunkSource.Factory(mMediaDataSourceFactory), mMainHandler, mEventLogger);
            case C.TYPE_DASH:
                return new DashMediaSource(uri, buildDataSourceFactory(false),
                        new DefaultDashChunkSource.Factory(mMediaDataSourceFactory), mMainHandler, mEventLogger);
            case C.TYPE_HLS:
                return new HlsMediaSource(uri, mMediaDataSourceFactory, mMainHandler, mEventLogger);
            case C.TYPE_OTHER:
                return new ExtractorMediaSource(uri, mMediaDataSourceFactory, new DefaultExtractorsFactory(),
                        mMainHandler, mEventLogger);
            default: {
                throw new IllegalStateException("Unsupported type: " + type);
            }
        }
    }
 
Example #17
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 #18
Source File: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 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, buildDataSourceFactory(false), new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
            case C.TYPE_OTHER:
                return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(), mainHandler, null);
            case C.TYPE_DASH:
                return new DashMediaSource(uri, buildDataSourceFactory(false), new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
//            case C.TYPE_HLS:return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
            case C.TYPE_HLS:
                throw new IllegalStateException("Unsupported type: " + type);
            default:
                throw new IllegalStateException("Unsupported type: " + type);
        }
    }
 
Example #19
Source File: AudioSlidePlayer.java    From mollyim-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 #20
Source File: MediaSourceFactory.java    From no-player with Apache License 2.0 5 votes vote down vote up
private MediaSource createH264MediaSource(DefaultDataSourceFactory defaultDataSourceFactory,
                                          Uri uri,
                                          MediaSourceEventListener mediaSourceEventListener) {
    ExtractorMediaSource.Factory factory = new ExtractorMediaSource.Factory(defaultDataSourceFactory);
    ExtractorMediaSource extractorMediaSource = factory
            .setExtractorsFactory(new DefaultExtractorsFactory())
            .createMediaSource(uri);
    extractorMediaSource.addEventListener(handler, mediaSourceEventListener);
    return extractorMediaSource;
}
 
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: 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 #23
Source File: ExoPlayerAdapter.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
/**
 * Set {@link MediaSource} for {@link SimpleExoPlayer}. An app may override this method in order
 * to use different {@link MediaSource}.
 * @param uri The url of media source
 * @return MediaSource for the player
 */
public MediaSource onCreateMediaSource(Uri uri) {
    String userAgent = Util.getUserAgent(mContext, "ExoPlayerAdapter");
    return new ExtractorMediaSource(uri,
            new DefaultDataSourceFactory(mContext, userAgent),
            new DefaultExtractorsFactory(),
            null,
            null);
}
 
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: 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 #26
Source File: DefaultMediaSourceBuilder.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public MediaSource build(@NonNull Context context, @NonNull Uri uri, @NonNull String userAgent, @NonNull Handler handler, @Nullable TransferListener transferListener) {
    DataSource.Factory dataSourceFactory = buildDataSourceFactory(context, userAgent, transferListener);

    return new ExtractorMediaSource.Factory(dataSourceFactory)
            .setExtractorsFactory(new DefaultExtractorsFactory())
            .createMediaSource(uri);
}
 
Example #27
Source File: StoryAudioPlayer.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
public void updateCursor(Cursor cursor, int mimeTypeColumn, int uriColumn) {
    if (this.cursor != null) {
        this.cursor.close();
    }
    this.cursor = cursor;
    if (this.cursor != null) {
        getOrCreatePlayer();
        for (int index = (currentPosition + 1); index < this.cursor.getCount(); index++) {
            cursor.moveToPosition(index);
            String mime = cursor.getString(mimeTypeColumn);
            Uri uri = Uri.parse(cursor.getString(uriColumn));

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

            DataSource.Factory factory = new DataSource.Factory() {
                @Override
                public DataSource createDataSource() {
                    return inputStreamDataSource;
                }
            };
            MediaSource mediaSource = new ExtractorMediaSource(inputStreamDataSource.getUri(),
                    factory, new DefaultExtractorsFactory(), null, null);
            Log.d("AudioPlayer", "Add media source " + uri);
            concatenatingMediaSource.addMediaSource(mediaSource);
        }
        currentPosition = this.cursor.getCount() - 1;
    }

    player.setPlayWhenReady(true);
    player.prepare(concatenatingMediaSource);

}
 
Example #28
Source File: MediaSourceFactory.java    From CumulusTV with MIT License 5 votes vote down vote up
public static MediaSource getMediaSourceFor(Context context, Uri mediaUri,
        String overrideExtension) {
    // Measures bandwidth during playback. Can be null if not required.
    DataSource.Factory mediaDataSourceFactory = buildDataSourceFactory(context, true);

    int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ?
            "." + overrideExtension
            : mediaUri.getLastPathSegment());
    Handler mainHandler = new Handler();
    switch (type) {
        case C.TYPE_SS:
            return new SsMediaSource(mediaUri, buildDataSourceFactory(context, false),
                    new DefaultSsChunkSource.Factory(mediaDataSourceFactory),
                    mainHandler, null);
        case C.TYPE_DASH:
            return new DashMediaSource(mediaUri, buildDataSourceFactory(context, false),
                    new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler,
                    null);
        case C.TYPE_HLS:
            return new HlsMediaSource(mediaUri, mediaDataSourceFactory, mainHandler,
                    null);
        case C.TYPE_OTHER:
            return new ExtractorMediaSource(mediaUri, mediaDataSourceFactory,
                    new DefaultExtractorsFactory(), mainHandler, null);
        default: {
            throw new NotMediaException("Unsupported type: " + type);
        }
    }
}
 
Example #29
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 #30
Source File: PlaybackFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
private void prepareMediaForPlaying(Uri mediaSourceUri) {
    String userAgent = Util.getUserAgent(getActivity(), "VideoPlayerGlue");
    MediaSource mediaSource =
            new ExtractorMediaSource(
                    mediaSourceUri,
                    new DefaultDataSourceFactory(getActivity(), userAgent),
                    new DefaultExtractorsFactory(),
                    null,
                    null);

    mPlayer.prepare(mediaSource);
}