Exoplayer 2 change media source to clip video












0















I am trying to implement exoplayer 2 for one of our applications.



Seems like the documentation and examples for something more complicated than automatic playback is very poor.



My problem is I create a mediasource and set it to the player, after that I have a custom icon that plays the video and on finish I seek back to 0.



Also I have a custom dual seekbar that when moved it will seek to a position and clip the video between the selected start and end time.



I am not sure if changing source of the player without recreating the whole thing is even possible.



I init my player as:



@AfterViews
protected void init() {
TrackSelector trackSelector = new DefaultTrackSelector();
mPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector);
mVideoView.setPlayer(mPlayer);
mPlayer.addListener(this);
}


After that I prepare the player like this:



public void setVideoPath(final String videoPath) {
mVideoPath = videoPath;
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "yourApplicationName"));
// This is the MediaSource representing the media to be played.
videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(videoPath));
mPlayer.prepare(videoSource);
}


When my play icon is clicked it runs:



@Click(R.id.view_video_preview_container_play)
void onPlayClicked() {
mPlayButton.setVisibility(GONE);
mPlayer.setPlayWhenReady(true);
}


When the playback is finished I do:



@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

if (playbackState == STATE_ENDED) {
mPlayButton.setVisibility(VISIBLE);
mPlayer.seekTo(0);
mPlayer.setPlayWhenReady(false);
}
}


No when I seek I do:



disposable = source
.debounce(500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(range -> {
mPlayer.stop();
mPlayButton.setVisibility(VISIBLE);
clippingSource = new ClippingMediaSource(videoSource, 2000000, 5000000);
mPlayer.prepare(clippingSource);
}
);


Now when the source emits to my observable I get back:



2018-11-16 12:48:16.463 28090-28209/nl.dtt.vormats E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.source.ClippingMediaSource$IllegalClippingException: Illegal clipping: not seekable to start
at com.google.android.exoplayer2.source.ClippingMediaSource$ClippingTimeline.<init>(ClippingMediaSource.java:350)
at com.google.android.exoplayer2.source.ClippingMediaSource.refreshClippedTimeline(ClippingMediaSource.java:296)
at com.google.android.exoplayer2.source.ClippingMediaSource.onChildSourceInfoRefreshed(ClippingMediaSource.java:262)
at com.google.android.exoplayer2.source.ClippingMediaSource.onChildSourceInfoRefreshed(ClippingMediaSource.java:34)
at com.google.android.exoplayer2.source.CompositeMediaSource$1.onSourceInfoRefreshed(CompositeMediaSource.java:103)
at com.google.android.exoplayer2.source.BaseMediaSource.refreshSourceInfo(BaseMediaSource.java:73)
at com.google.android.exoplayer2.source.ExtractorMediaSource.notifySourceInfoRefreshed(ExtractorMediaSource.java:400)
at com.google.android.exoplayer2.source.ExtractorMediaSource.prepareSourceInternal(ExtractorMediaSource.java:348)
at com.google.android.exoplayer2.source.BaseMediaSource.prepareSource(BaseMediaSource.java:137)
at com.google.android.exoplayer2.source.CompositeMediaSource.prepareChildSource(CompositeMediaSource.java:109)
at com.google.android.exoplayer2.source.ClippingMediaSource.prepareSourceInternal(ClippingMediaSource.java:216)
at com.google.android.exoplayer2.source.BaseMediaSource.prepareSource(BaseMediaSource.java:137)
at com.google.android.exoplayer2.ExoPlayerImplInternal.prepareInternal(ExoPlayerImplInternal.java:396)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:286)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:166)
at android.os.HandlerThread.run(HandlerThread.java:65)


Unfortunately as I stated before the documentation if very poor and I managed only to find out that the exceptions is thrown at:



if (startUs != 0 && !window.isSeekable) {
throw new IllegalClippingException(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
}


Specifically window.isSeekable is false.










share|improve this question



























    0















    I am trying to implement exoplayer 2 for one of our applications.



    Seems like the documentation and examples for something more complicated than automatic playback is very poor.



    My problem is I create a mediasource and set it to the player, after that I have a custom icon that plays the video and on finish I seek back to 0.



    Also I have a custom dual seekbar that when moved it will seek to a position and clip the video between the selected start and end time.



    I am not sure if changing source of the player without recreating the whole thing is even possible.



    I init my player as:



    @AfterViews
    protected void init() {
    TrackSelector trackSelector = new DefaultTrackSelector();
    mPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector);
    mVideoView.setPlayer(mPlayer);
    mPlayer.addListener(this);
    }


    After that I prepare the player like this:



    public void setVideoPath(final String videoPath) {
    mVideoPath = videoPath;
    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "yourApplicationName"));
    // This is the MediaSource representing the media to be played.
    videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(videoPath));
    mPlayer.prepare(videoSource);
    }


    When my play icon is clicked it runs:



    @Click(R.id.view_video_preview_container_play)
    void onPlayClicked() {
    mPlayButton.setVisibility(GONE);
    mPlayer.setPlayWhenReady(true);
    }


    When the playback is finished I do:



    @Override
    public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

    if (playbackState == STATE_ENDED) {
    mPlayButton.setVisibility(VISIBLE);
    mPlayer.seekTo(0);
    mPlayer.setPlayWhenReady(false);
    }
    }


    No when I seek I do:



    disposable = source
    .debounce(500, TimeUnit.MILLISECONDS)
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(range -> {
    mPlayer.stop();
    mPlayButton.setVisibility(VISIBLE);
    clippingSource = new ClippingMediaSource(videoSource, 2000000, 5000000);
    mPlayer.prepare(clippingSource);
    }
    );


    Now when the source emits to my observable I get back:



    2018-11-16 12:48:16.463 28090-28209/nl.dtt.vormats E/ExoPlayerImplInternal: Source error.
    com.google.android.exoplayer2.source.ClippingMediaSource$IllegalClippingException: Illegal clipping: not seekable to start
    at com.google.android.exoplayer2.source.ClippingMediaSource$ClippingTimeline.<init>(ClippingMediaSource.java:350)
    at com.google.android.exoplayer2.source.ClippingMediaSource.refreshClippedTimeline(ClippingMediaSource.java:296)
    at com.google.android.exoplayer2.source.ClippingMediaSource.onChildSourceInfoRefreshed(ClippingMediaSource.java:262)
    at com.google.android.exoplayer2.source.ClippingMediaSource.onChildSourceInfoRefreshed(ClippingMediaSource.java:34)
    at com.google.android.exoplayer2.source.CompositeMediaSource$1.onSourceInfoRefreshed(CompositeMediaSource.java:103)
    at com.google.android.exoplayer2.source.BaseMediaSource.refreshSourceInfo(BaseMediaSource.java:73)
    at com.google.android.exoplayer2.source.ExtractorMediaSource.notifySourceInfoRefreshed(ExtractorMediaSource.java:400)
    at com.google.android.exoplayer2.source.ExtractorMediaSource.prepareSourceInternal(ExtractorMediaSource.java:348)
    at com.google.android.exoplayer2.source.BaseMediaSource.prepareSource(BaseMediaSource.java:137)
    at com.google.android.exoplayer2.source.CompositeMediaSource.prepareChildSource(CompositeMediaSource.java:109)
    at com.google.android.exoplayer2.source.ClippingMediaSource.prepareSourceInternal(ClippingMediaSource.java:216)
    at com.google.android.exoplayer2.source.BaseMediaSource.prepareSource(BaseMediaSource.java:137)
    at com.google.android.exoplayer2.ExoPlayerImplInternal.prepareInternal(ExoPlayerImplInternal.java:396)
    at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:286)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:166)
    at android.os.HandlerThread.run(HandlerThread.java:65)


    Unfortunately as I stated before the documentation if very poor and I managed only to find out that the exceptions is thrown at:



    if (startUs != 0 && !window.isSeekable) {
    throw new IllegalClippingException(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
    }


    Specifically window.isSeekable is false.










    share|improve this question

























      0












      0








      0








      I am trying to implement exoplayer 2 for one of our applications.



      Seems like the documentation and examples for something more complicated than automatic playback is very poor.



      My problem is I create a mediasource and set it to the player, after that I have a custom icon that plays the video and on finish I seek back to 0.



      Also I have a custom dual seekbar that when moved it will seek to a position and clip the video between the selected start and end time.



      I am not sure if changing source of the player without recreating the whole thing is even possible.



      I init my player as:



      @AfterViews
      protected void init() {
      TrackSelector trackSelector = new DefaultTrackSelector();
      mPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector);
      mVideoView.setPlayer(mPlayer);
      mPlayer.addListener(this);
      }


      After that I prepare the player like this:



      public void setVideoPath(final String videoPath) {
      mVideoPath = videoPath;
      // Produces DataSource instances through which media data is loaded.
      DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "yourApplicationName"));
      // This is the MediaSource representing the media to be played.
      videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(videoPath));
      mPlayer.prepare(videoSource);
      }


      When my play icon is clicked it runs:



      @Click(R.id.view_video_preview_container_play)
      void onPlayClicked() {
      mPlayButton.setVisibility(GONE);
      mPlayer.setPlayWhenReady(true);
      }


      When the playback is finished I do:



      @Override
      public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

      if (playbackState == STATE_ENDED) {
      mPlayButton.setVisibility(VISIBLE);
      mPlayer.seekTo(0);
      mPlayer.setPlayWhenReady(false);
      }
      }


      No when I seek I do:



      disposable = source
      .debounce(500, TimeUnit.MILLISECONDS)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(range -> {
      mPlayer.stop();
      mPlayButton.setVisibility(VISIBLE);
      clippingSource = new ClippingMediaSource(videoSource, 2000000, 5000000);
      mPlayer.prepare(clippingSource);
      }
      );


      Now when the source emits to my observable I get back:



      2018-11-16 12:48:16.463 28090-28209/nl.dtt.vormats E/ExoPlayerImplInternal: Source error.
      com.google.android.exoplayer2.source.ClippingMediaSource$IllegalClippingException: Illegal clipping: not seekable to start
      at com.google.android.exoplayer2.source.ClippingMediaSource$ClippingTimeline.<init>(ClippingMediaSource.java:350)
      at com.google.android.exoplayer2.source.ClippingMediaSource.refreshClippedTimeline(ClippingMediaSource.java:296)
      at com.google.android.exoplayer2.source.ClippingMediaSource.onChildSourceInfoRefreshed(ClippingMediaSource.java:262)
      at com.google.android.exoplayer2.source.ClippingMediaSource.onChildSourceInfoRefreshed(ClippingMediaSource.java:34)
      at com.google.android.exoplayer2.source.CompositeMediaSource$1.onSourceInfoRefreshed(CompositeMediaSource.java:103)
      at com.google.android.exoplayer2.source.BaseMediaSource.refreshSourceInfo(BaseMediaSource.java:73)
      at com.google.android.exoplayer2.source.ExtractorMediaSource.notifySourceInfoRefreshed(ExtractorMediaSource.java:400)
      at com.google.android.exoplayer2.source.ExtractorMediaSource.prepareSourceInternal(ExtractorMediaSource.java:348)
      at com.google.android.exoplayer2.source.BaseMediaSource.prepareSource(BaseMediaSource.java:137)
      at com.google.android.exoplayer2.source.CompositeMediaSource.prepareChildSource(CompositeMediaSource.java:109)
      at com.google.android.exoplayer2.source.ClippingMediaSource.prepareSourceInternal(ClippingMediaSource.java:216)
      at com.google.android.exoplayer2.source.BaseMediaSource.prepareSource(BaseMediaSource.java:137)
      at com.google.android.exoplayer2.ExoPlayerImplInternal.prepareInternal(ExoPlayerImplInternal.java:396)
      at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:286)
      at android.os.Handler.dispatchMessage(Handler.java:104)
      at android.os.Looper.loop(Looper.java:166)
      at android.os.HandlerThread.run(HandlerThread.java:65)


      Unfortunately as I stated before the documentation if very poor and I managed only to find out that the exceptions is thrown at:



      if (startUs != 0 && !window.isSeekable) {
      throw new IllegalClippingException(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
      }


      Specifically window.isSeekable is false.










      share|improve this question














      I am trying to implement exoplayer 2 for one of our applications.



      Seems like the documentation and examples for something more complicated than automatic playback is very poor.



      My problem is I create a mediasource and set it to the player, after that I have a custom icon that plays the video and on finish I seek back to 0.



      Also I have a custom dual seekbar that when moved it will seek to a position and clip the video between the selected start and end time.



      I am not sure if changing source of the player without recreating the whole thing is even possible.



      I init my player as:



      @AfterViews
      protected void init() {
      TrackSelector trackSelector = new DefaultTrackSelector();
      mPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector);
      mVideoView.setPlayer(mPlayer);
      mPlayer.addListener(this);
      }


      After that I prepare the player like this:



      public void setVideoPath(final String videoPath) {
      mVideoPath = videoPath;
      // Produces DataSource instances through which media data is loaded.
      DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "yourApplicationName"));
      // This is the MediaSource representing the media to be played.
      videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(videoPath));
      mPlayer.prepare(videoSource);
      }


      When my play icon is clicked it runs:



      @Click(R.id.view_video_preview_container_play)
      void onPlayClicked() {
      mPlayButton.setVisibility(GONE);
      mPlayer.setPlayWhenReady(true);
      }


      When the playback is finished I do:



      @Override
      public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

      if (playbackState == STATE_ENDED) {
      mPlayButton.setVisibility(VISIBLE);
      mPlayer.seekTo(0);
      mPlayer.setPlayWhenReady(false);
      }
      }


      No when I seek I do:



      disposable = source
      .debounce(500, TimeUnit.MILLISECONDS)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(range -> {
      mPlayer.stop();
      mPlayButton.setVisibility(VISIBLE);
      clippingSource = new ClippingMediaSource(videoSource, 2000000, 5000000);
      mPlayer.prepare(clippingSource);
      }
      );


      Now when the source emits to my observable I get back:



      2018-11-16 12:48:16.463 28090-28209/nl.dtt.vormats E/ExoPlayerImplInternal: Source error.
      com.google.android.exoplayer2.source.ClippingMediaSource$IllegalClippingException: Illegal clipping: not seekable to start
      at com.google.android.exoplayer2.source.ClippingMediaSource$ClippingTimeline.<init>(ClippingMediaSource.java:350)
      at com.google.android.exoplayer2.source.ClippingMediaSource.refreshClippedTimeline(ClippingMediaSource.java:296)
      at com.google.android.exoplayer2.source.ClippingMediaSource.onChildSourceInfoRefreshed(ClippingMediaSource.java:262)
      at com.google.android.exoplayer2.source.ClippingMediaSource.onChildSourceInfoRefreshed(ClippingMediaSource.java:34)
      at com.google.android.exoplayer2.source.CompositeMediaSource$1.onSourceInfoRefreshed(CompositeMediaSource.java:103)
      at com.google.android.exoplayer2.source.BaseMediaSource.refreshSourceInfo(BaseMediaSource.java:73)
      at com.google.android.exoplayer2.source.ExtractorMediaSource.notifySourceInfoRefreshed(ExtractorMediaSource.java:400)
      at com.google.android.exoplayer2.source.ExtractorMediaSource.prepareSourceInternal(ExtractorMediaSource.java:348)
      at com.google.android.exoplayer2.source.BaseMediaSource.prepareSource(BaseMediaSource.java:137)
      at com.google.android.exoplayer2.source.CompositeMediaSource.prepareChildSource(CompositeMediaSource.java:109)
      at com.google.android.exoplayer2.source.ClippingMediaSource.prepareSourceInternal(ClippingMediaSource.java:216)
      at com.google.android.exoplayer2.source.BaseMediaSource.prepareSource(BaseMediaSource.java:137)
      at com.google.android.exoplayer2.ExoPlayerImplInternal.prepareInternal(ExoPlayerImplInternal.java:396)
      at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:286)
      at android.os.Handler.dispatchMessage(Handler.java:104)
      at android.os.Looper.loop(Looper.java:166)
      at android.os.HandlerThread.run(HandlerThread.java:65)


      Unfortunately as I stated before the documentation if very poor and I managed only to find out that the exceptions is thrown at:



      if (startUs != 0 && !window.isSeekable) {
      throw new IllegalClippingException(IllegalClippingException.REASON_NOT_SEEKABLE_TO_START);
      }


      Specifically window.isSeekable is false.







      android exoplayer exoplayer2.x






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 11:53









      A.ButakidisA.Butakidis

      55211




      55211
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The solution was to recreate the the MediaSource as it seems like the same MediaSource can not be reused.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337365%2fexoplayer-2-change-media-source-to-clip-video%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The solution was to recreate the the MediaSource as it seems like the same MediaSource can not be reused.






            share|improve this answer




























              1














              The solution was to recreate the the MediaSource as it seems like the same MediaSource can not be reused.






              share|improve this answer


























                1












                1








                1







                The solution was to recreate the the MediaSource as it seems like the same MediaSource can not be reused.






                share|improve this answer













                The solution was to recreate the the MediaSource as it seems like the same MediaSource can not be reused.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 11:26









                A.ButakidisA.Butakidis

                55211




                55211
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337365%2fexoplayer-2-change-media-source-to-clip-video%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown