ExoPlayer сразу переходит к концу при воспроизведении локального файла - PullRequest
0 голосов
/ 14 октября 2019

Мой код уже может воспроизводить локальные видеофайлы раньше. Теперь иногда ExoPlayer воспроизводит видео только один раз или не воспроизводит видео каждый раз. Я воспроизводил каждое видео с помощью встроенного видеопроигрывателя, и каждое из видео воспроизводилось нормально. В моих журналах кажется, что ExoPlayer иногда даже не достигает состояния готовности, а затем немедленно останавливает видео или воспроизводит только новые секунды видео до его окончания. Код ниже, как я играю видео.

public class VideoPlayer {
    public static final int STREAM = 1;
    public static final int LOCAL_FILE = 2;

    private int playMode;
    private Video currentVideo;

    public int getPlayMode() {
        return playMode;
    }

    public void setPlayMode(int playMode) {
        this.playMode = playMode;
    }

    public VideoAd getCurrentVideo() {
        return currentVideo;
    }

    public void setCurrentVideoAd(Video currentVideo) {
        this.currentVideo = currentVideo;
    }
}

private VideoPlayer vp;

public void initializePlayer() {
    if (exoPlayer == null) {
        bandwidthMeter = new DefaultBandwidthMeter();
        trackSelectionFactory = new AdaptiveTrackSelection.Factory();
        trackSelector = new DefaultTrackSelector(trackSelectionFactory);
        LoadControl loadControl = new DefaultLoadControl();

        exoPlayer = ExoPlayerFactory.newSimpleInstance(ctx, trackSelector, loadControl);
        mPlayerView.setPlayer(exoPlayer);
        mPlayerView.setShutterBackgroundColor(Color.TRANSPARENT);

        exoPlayer.addListener(exoPlayEventListener);

        vp = new VideoPlayer();
    }
}

public void startPlayFromFile(Video vid){
    vp.setCurrentVideo(vid);
    vp.setPlayMode(VideoPlayer.LOCAL_FILE);

    if(((MainActivity) ctx).indicatorVisible){
        ((MainActivity) ctx).vIndicator.setVisibility(View.VISIBLE);
        ((MainActivity) ctx).runOnUiThread(new Runnable() {

            @Override
            public void run() {
                ((MainActivity) ctx).vIndicator.setBackgroundColor(ctx.getResources().getColor(R.color.deep_orange_600));
            }
        });
    }else{
        ((MainActivity) ctx).vIndicator.setVisibility(View.GONE);
    }

    Uri uri = Uri.fromFile(new File(vid.getLocalPath()));

    if(uri == null){
        if(!((MainActivity) ctx).isDownloading(ctx, vid.getDownloadId())){
            ((MainActivity) ctx).startDownload(vid);
        }
        startStream(vid);
        return;
    }

    defaultBandwidthMeter = new DefaultBandwidthMeter();

    DataSpec dataSpec = new DataSpec(uri);
    final FileDataSource fileDataSource = new FileDataSource();
    try {
        fileDataSource.open(dataSpec);

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

        MediaSource mSource = new ExtractorMediaSource(fileDataSource.getUri(),
                factory, new DefaultExtractorsFactory(), null, null);

        exoPlayer.setPlayWhenReady(true);
        exoPlayer.prepare(mSource, false, false);
    } catch (FileDataSource.FileDataSourceException e) {
        e.printStackTrace();
        startStream(vid);

        if(!((MainActivity) ctx).isDownloading(ctx, vid.getDownloadId())){
            ((MainActivity) ctx).startDownload(vid);
        }

    }

}

Это мой вопрос на github Google / ExoPlayer. https://github.com/google/ExoPlayer/issues/6539

...