Reputation: 385
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.
Upvotes: 0
Views: 3024
Reputation: 385
The solution was to recreate the the MediaSource as it seems like the same MediaSource can not be reused.
Upvotes: 3