ExoPlayer-如何播放本地mp3文件 [英] ExoPlayer - how to play local mp3 file

查看:272
本文介绍了ExoPlayer-如何播放本地mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ExoPlayer代替MediaPlayer,因为MediaPlayer返回错误的getCurrentPosition()是一个常见的错误,我需要一个替代品.

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.

但是我在任何地方都找不到信息,该信息如何通过与MediaPlayer的.setDataSource(String filepath)

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没有任何示例,官方文档站点奇怪地在两台计算机上都使我的FireFox浏览器崩溃

Google doesn't have any example and the official documentation site strangely crash my FireFox browser on both computers

推荐答案

可以修改github中的ExoPlayer演示应用程序以播放本地文件. 为此,请编辑 https://github.com/google/ExoPlayer/blob/master/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java 文件以添加新视频集.

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

为此,请编辑 https://github.com/google/ExoPlayer/blob/master/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java 文件添加一个新的样本集.

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

这篇关于ExoPlayer-如何播放本地mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆