我正在使用exoplayer播放sd卡中的视频。出现问题。看来exoplayer正在缓冲sd卡中的视频,如果我使用音轨选择器向前移动到未缓冲的部分,则视频会停止缓冲并抛出异常:
这是我的代码
PlayerView playerView;
SimpleExoPlayer simpleExoPlayer;
@Override
protected void onStart() {
super.onStart();x
playerView=(PlayerView)findViewById(R.id.ff);
simpleExoPlayer= ExoPlayerFactory.newSimpleInstance(this,new DefaultTrackSelector());
playerView.setPlayer(simpleExoPlayer);
/*DefaultDataSourceFactory defaultDataSourceFactory=new DefaultDataSourceFactory(this, Util.getUserAgent(this,"ExoPlayer"))
ExtractorMediaSource extractorMediaSource=new ExtractorMediaSource(defaultDataSourceFactory)
.creatMediaSource(Uri.parse());*/
String playerInfo = Util.getUserAgent(this, "ExoPlayerInfo");
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(
this, playerInfo
);
MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.setExtractorsFactory(new DefaultExtractorsFactory())
.createMediaSource(Uri.parse(Environment.getExternalStorageDirectory().toString()+"/gfdf2.mp4"));
simpleExoPlayer.prepare(mediaSource);
//simpleExoPlayer.setPlayWhenReady(true);
}
@Override
protected void onStop() {
super.onStop();
playerView.setPlayer(null);
simpleExoPlayer.release();
simpleExoPlayer=null;
}
}
这是我的日志
E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.EOFException
at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:70)
at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:147)
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:844)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:320)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
Caused by: java.io.EOFException
at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:67)
at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:147)
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:844)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:320)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:784)
我是exoplayer的新手,所以请回答尽可能简单:)