ExoPlayer - play local mp4 file in SD card

后端 未结 8 510
囚心锁ツ
囚心锁ツ 2021-02-04 03:49

I am using the Exoplayer Demo app and want to preload a MP4 video from SD card. I have tried out the implementation from this post, but it does not work. There is no such class

8条回答
  •  失恋的感觉
    2021-02-04 04:31

    This worked for me.Try these steps:

    Get path of the file and start the player

    File myFile = new File(extStore.getAbsolutePath() + "/folder/videos/" + video_name);  
    videoUrl= String.valueOf(Uri.fromFile(myFile));  
    initializePlayer(videoUrl);
    

    Initializing player

    private void initializePlayer(String videoUrl) {
        player = ExoPlayerFactory.newSimpleInstance(
                new DefaultRenderersFactory(getActivity()),
                new DefaultTrackSelector(), new DefaultLoadControl());
    
        playerView.setPlayer(player);
    
        player.setPlayWhenReady(playWhenReady);
        player.seekTo(currentWindow, playbackPosition);
    
        Uri uri = Uri.parse(videoUrl);
        MediaSource mediaSource = buildMediaSource(uri);
        player.prepare(mediaSource, resetPositionBoolean, false);
    }   
    

    Building media source

      private MediaSource buildMediaSource(Uri uri) {
        return new ExtractorMediaSource.Factory(
                new DefaultDataSourceFactory(getActivity(),"Exoplayer-local")).
                createMediaSource(uri);
    }
    

提交回复
热议问题