ExoPlayer - how to play local mp3 file

android, exoplayer

Solution

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);

Problem

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 find an info anywhere how to open a local file through the file path to the file same as MediaPlayer's `.setDataSource(String filepath)` Google doesn't have any example and the official documentation site strangely crash my FireFox browser on both computers

Original source