com.google.android.exoplayer2.ExoPlayerFactory Java Examples

The following examples show how to use com.google.android.exoplayer2.ExoPlayerFactory. 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: 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 #3
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 #4
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 #5
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 #6
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 #7
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
public ExoMediaPlayer(@NonNull Context context) {
    this.context = context;

    bufferRepeater.setRepeaterDelay(BUFFER_REPEAT_DELAY);
    bufferRepeater.setRepeatListener(new BufferRepeatListener());

    mainHandler = new Handler();

    ComponentListener componentListener = new ComponentListener();
    RendererProvider rendererProvider = new RendererProvider(context, mainHandler, componentListener, componentListener, componentListener, componentListener);
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = generateDrmSessionManager();
    rendererProvider.setDrmSessionManager(drmSessionManager);

    renderers = rendererProvider.generate();

    adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);

    LoadControl loadControl = ExoMedia.Data.loadControl != null ? ExoMedia.Data.loadControl : new DefaultLoadControl();
    player = ExoPlayerFactory.newInstance(renderers.toArray(new Renderer[renderers.size()]), trackSelector, loadControl);
    player.addListener(this);
    analyticsCollector = new AnalyticsCollector.Factory().createAnalyticsCollector(player, Clock.DEFAULT);
    player.addListener(analyticsCollector);
    setupDamSessionManagerAnalytics(drmSessionManager);
}
 
Example #8
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 #9
Source File: DefaultPlayer.java    From ARVI with Apache License 2.0 6 votes vote down vote up
@Override
public final void init() {
    if(isInitialized()) {
        return;
    }

    // initializing the actual ExoPlayer
    this.exoPlayer = ExoPlayerFactory.newSimpleInstance(
        this.context,
        this.renderersFactory,
        this.trackSelector,
        this.loadControl,
        this.drmSessionManager,
        this.bandwidthMeter
    );
    this.exoPlayer.addListener(this.eventHandler);
    this.volumeController = new DefaultVolumeController(this.exoPlayer);
}
 
Example #10
Source File: PlayerActivity.java    From exoplayer-intro with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
  if (player == null) {
    DefaultTrackSelector trackSelector = new DefaultTrackSelector();
    trackSelector.setParameters(
            trackSelector.buildUponParameters().setMaxVideoSizeSd());
    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
  }

  playerView.setPlayer(player);
  Uri uri = Uri.parse(getString(R.string.media_url_dash));
  MediaSource mediaSource = buildMediaSource(uri);

  player.setPlayWhenReady(playWhenReady);
  player.seekTo(currentWindow, playbackPosition);
  player.addListener(playbackStateListener);
  player.prepare(mediaSource, false, false);
}
 
Example #11
Source File: PlayerActivity.java    From exoplayer-intro with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
  if (player == null) {
    DefaultTrackSelector trackSelector = new DefaultTrackSelector();
    trackSelector.setParameters(
            trackSelector.buildUponParameters().setMaxVideoSizeSd());
    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
  }

  playerView.setPlayer(player);
  Uri uri = Uri.parse(getString(R.string.media_url_dash));
  MediaSource mediaSource = buildMediaSource(uri);

  player.setPlayWhenReady(playWhenReady);
  player.seekTo(currentWindow, playbackPosition);
  player.prepare(mediaSource, false, false);
}
 
Example #12
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 #13
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 #14
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 #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: 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 #17
Source File: AudioSlidePlayer.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
public void requestDuration() {
  try {
    LoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE).createDefaultLoadControl();
    durationCalculator = ExoPlayerFactory.newSimpleInstance(context, new DefaultRenderersFactory(context), new DefaultTrackSelector(), loadControl);
    durationCalculator.setPlayWhenReady(false);
    durationCalculator.addListener(new Player.EventListener() {
      @Override
      public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
        if (playbackState == Player.STATE_READY) {
            Util.runOnMain(() -> {
              Log.d(TAG, "request duration " + durationCalculator.getDuration());
              getListener().onReceivedDuration(Long.valueOf(durationCalculator.getDuration()).intValue());
              durationCalculator.release();
              durationCalculator.removeListener(this);
              durationCalculator = null;
            });
        }
      }
    });
    durationCalculator.prepare(createMediaSource(slide.getUri()));
  } catch (Exception e) {
      Log.w(TAG, e);
      getListener().onReceivedDuration(0);
  }
}
 
Example #18
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 #19
Source File: TubiPlayerActivity.java    From TubiPlayer with MIT License 6 votes vote down vote up
protected void initMoviePlayer() {
    // 1. Create a default TrackSelector
    mMainHandler = new Handler();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    mTrackSelector =
            new DefaultTrackSelector(videoTrackSelectionFactory);

    // 3. Create the mMoviePlayer
    mMoviePlayer = ExoPlayerFactory.newSimpleInstance(this, mTrackSelector);

    mEventLogger = new EventLogger(mTrackSelector);
    mMoviePlayer.addAnalyticsListener(mEventLogger);
    mMoviePlayer.addMetadataOutput(mEventLogger);

    mTubiPlayerView.setPlayer(mMoviePlayer, this);
    mTubiPlayerView.setMediaModel(mediaModel);
}
 
Example #20
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 #21
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 #22
Source File: ExoPlayerCreator.java    From no-player with Apache License 2.0 5 votes vote down vote up
@NonNull
public SimpleExoPlayer create(DrmSessionCreator drmSessionCreator,
                              DefaultDrmSessionEventListener drmSessionEventListener,
                              MediaCodecSelector mediaCodecSelector,
                              TrackSelector trackSelector) {
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = drmSessionCreator.create(drmSessionEventListener);
    SubtitleDecoderFactory subtitleDecoderFactory = new NoPlayerSubtitleDecoderFactory();
    RenderersFactory renderersFactory = new SimpleRenderersFactory(
            context,
            EXTENSION_RENDERER_MODE_OFF,
            DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS,
            mediaCodecSelector,
            subtitleDecoderFactory
    );

    DefaultLoadControl loadControl = new DefaultLoadControl();
    return ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector, loadControl, drmSessionManager);
}
 
Example #23
Source File: VideoExoPlayer.java    From TigerVideo with Apache License 2.0 5 votes vote down vote up
/**--------------------- 创建SimpleExoPlayer ----------------------------**/

    private void initExoPlayer() {

        mMediaDataSourceFactory = buildDataSourceFactory(true);

        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
        mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        mEventLogger = new EventLogger(mTrackSelector);
        mMainHandler = new Handler(Looper.getMainLooper());

        DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext,
                null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);

        mExoPlayer =  ExoPlayerFactory.newSimpleInstance(renderersFactory, mTrackSelector);
        mExoPlayer.addListener(mEventLogger);
        mExoPlayer.setAudioDebugListener(mEventLogger);
        mExoPlayer.setVideoDebugListener(mEventLogger);
        mExoPlayer.setMetadataOutput(mEventLogger);

        mExoPlayer.setTextOutput(null);
        mExoPlayer.setVideoListener(null);
        mExoPlayer.removeListener(this);
        mExoPlayer.setVideoTextureView(null);

        mExoPlayer.setVideoListener(this);
        mExoPlayer.addListener(this);
        mExoPlayer.setTextOutput(this);
    }
 
Example #24
Source File: ExoPlayerAdapter.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 */
public ExoPlayerAdapter(Context context) {
    mContext = context;
    mPlayer = ExoPlayerFactory.newSimpleInstance(mContext,
            new DefaultTrackSelector(),
            new DefaultLoadControl());
    mPlayer.addListener(this);
}
 
Example #25
Source File: ExoPlayerHelper.java    From ExoPlayer-Wrapper with Apache License 2.0 5 votes vote down vote up
@Override
public void createPlayer(boolean isToPrepare) {
    if (mExoPlayerListener != null) {
        mExoPlayerListener.createExoPlayerCalled(isToPrepare);
    }
    if (mPlayer != null) {
        return;
    }

    if (isThumbImageViewEnabled) {
        addThumbImageView();
    }

    mPlayer = ExoPlayerFactory.newSimpleInstance(
            mContext,
            new DefaultRenderersFactory(mContext),
            new DefaultTrackSelector(),
            mLoadControl);

    mExoPlayerView.setPlayer(mPlayer);
    mExoPlayerView.setControllerShowTimeoutMs(1500);
    mExoPlayerView.setControllerHideOnTouch(false);

    mTempCurrentVolume = mPlayer.getVolume();

    mPlayer.setRepeatMode(isRepeatModeOn ? Player.REPEAT_MODE_ALL : Player.REPEAT_MODE_OFF);
    mPlayer.setPlayWhenReady(isAutoPlayOn);
    mPlayer.addListener(this);

    createMediaSource();

    if (isToPrepare) {
        preparePlayer();
    }
}
 
Example #26
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 #27
Source File: ExoPlayerView.java    From AerialDream with GNU General Public License v3.0 5 votes vote down vote up
public ExoPlayerView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (isInEditMode()) {
        return;
    }

    player = ExoPlayerFactory.newSimpleInstance(context);

    player.setVideoTextureView(this);
    player.addVideoListener(this);
    player.addListener(this);
}
 
Example #28
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 #29
Source File: JerryAudioController.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
public JerryAudioController(Context context) {
    this.mExoPlayer = ExoPlayerFactory.newSimpleInstance(context);
    this.mHandler = new Handler(Looper.getMainLooper());
    this.mRunnable = new UpdateRunnable();

    this.mMediaInfo = null;

    this.isFinish = false;

    initPlayer(mExoPlayer);
}
 
Example #30
Source File: TokPlayer.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
public TokPlayer(boolean isAudio) {
    if (isAudio) {
        //audio
        DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext,
            DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
        DefaultTrackSelector trackSelector = new DefaultTrackSelector();
        mPlayer = ExoPlayerFactory.newSimpleInstance(mContext, renderersFactory, trackSelector);
        mPlayer.addListener(this);
        mPlayer.addVideoListener(this);
    } else {
        //video TODO
    }
}