ExoPlayer - how to play local mp3 file

前端 未结 4 587
佛祖请我去吃肉
佛祖请我去吃肉 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:52

    Google changed some variable name and class definition these days! Below differ works for me.

    --- a/demo/src/main/java/com/google/android/exoplayer/demo/SampleChooserActivity.java
    +++ b/demo/src/main/java/com/google/android/exoplayer/demo/SampleChooserActivity.java
    @@ -30,6 +28,8 @@ import android.widget.ExpandableListView;
     import android.widget.ExpandableListView.OnChildClickListener;
     import android.widget.TextView;
    
     import java.util.ArrayList;
     import java.util.Collections;
     import java.util.List;
    @@ -44,7 +44,12 @@ public class SampleChooserActivity extends Activity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.sample_chooser_activity);
         final List sampleGroups = new ArrayList<>();
    -    SampleGroup group = new SampleGroup("YouTube DASH");
    +
    +    SampleGroup group = new SampleGroup("test videos");
    +    group.addAll(Samples.LOCAL_VIDEOS);
    +    sampleGroups.add(group);
    +
    +    group = new SampleGroup("YouTube DASH");
         group.addAll(Samples.YOUTUBE_DASH_MP4);
         group.addAll(Samples.YOUTUBE_DASH_WEBM);
         sampleGroups.add(group);
    diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java b/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java
    index 9f58528..9e86f99 100644
    --- a/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java
    +++ b/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java
    @@ -248,6 +248,13 @@ import java.util.Locale;
             "http://vod.leasewebcdn.com/bbb.flv?ri=1024&rs=150&start=0", Util.TYPE_OTHER),
       };
    
    +  public static final Sample[] LOCAL_VIDEOS = new Sample[] {
    +          new Sample("Some User friendly name of video 1",
    +                  "file:///mnt/sdcard/test1.mp4", Util.TYPE_OTHER),
    +          new Sample("Some User friendly name of video 2",
    +                  "file:///mnt/sdcard/test2.mp4", Util.TYPE_OTHER),
    +  };
    +
       private Samples() {}
    
     }
    

提交回复
热议问题