ExoPlayer从原始文件夹中读取mp3文件 [英] ExoPlayer reading mp3 file from raw folder

查看:203
本文介绍了ExoPlayer从原始文件夹中读取mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将应用程序原始文件夹中的mp3文件设置为ExoPlayer?

Is there any possibility to set an mp3 file that's located in the app's raw folder to ExoPlayer?

不幸的是,我尝试使用以下代码片段来实现它:

I tried to achieve it with the following code snippet without success unfortunately:

mMediaPath = "android.resource://" + getPackageName() + File.separator + R.raw.ringtone;

任何帮助将不胜感激!

推荐答案

可以从原始文件夹加载文件,关键是使用RawSourceDataSource.

It's possible to load files from the raw folder, the key is to use RawSourceDataSource.

这是一个示例(在Kotlin中),用于在原始目录中为mp3文件创建LoopingMediaSource:

Here's an example(in Kotlin) to create a LoopingMediaSource for an mp3file in the raw directory:


val uri = RawResourceDataSource.buildRawResourceUri(R.raw.mp3file)
val dataSource = RawResourceDataSource(this)
dataSource.open(DataSpec(uri))

val source = ExtractorMediaSource(uri, DataSource.Factory { dataSource }, Mp3Extractor.FACTORY, null, null)

LoopingMediaSource(source)

这篇关于ExoPlayer从原始文件夹中读取mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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