ExoPlayer - how to play local mp3 file

前端 未结 4 589
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 13:37

I\'m trying to use ExoPlayer instead of MediaPlayer because it\'s a common bug that MediaPlayer returns wrong getCurrentPosition() and I need a substitute.

But I can\'t

4条回答
  •  温柔的废话
    2021-02-07 13:50

    The ExoPlayer demo app in github can be modified to play local files. To do that, edit https://github.com/google/ExoPlayer/blob/master/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java file to add a new video set.

    public static final Sample[] LOCAL_VIDEOS = new Sample[] {
       new Sample("Some User friendly name of video 1",
         "/mnt/sdcard/video1.mp4", DemoUtil.TYPE_OTHER),
      new Sample("Some User friendly name of video 2",
        "/mnt/sdcard/video2.mp4", DemoUtil.TYPE_OTHER),
    };
    

    To do that, edit https://github.com/google/ExoPlayer/blob/master/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java file to add a new sample set.

    sampleAdapter.add(new Header("Local Videos"));
    sampleAdapter.addAll((Object[]) Samples.LOCAL_VIDEOS);
    

提交回复
热议问题