创建一个ExoPlayer的简单实例 [英] Creating a simple instance of ExoPlayer

查看:558
本文介绍了创建一个ExoPlayer的简单实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在寻找一个通过Android中的ExoPlayer利用Dash的应用程序.

I am currently looking to develop an application that utilises Dash through the ExoPlayer in Android.

首先,我要进行演示项目,但是即使创建一个简单的ExoPlayer工作实例也可以流mp3或类似内容时,却遇到了麻烦.

To begin with I am going through the demo project however am having trouble with even creating a simple working instance of ExoPlayer that can stream mp3 or similar.

非常感谢任何人提供的与获得非常简单的exoplayer实例有关的帮助,我可以根据这些实例进行改编和构建,或者如果有人有任何线索可以得到更多参考或指南,我可以遵循,因为似乎很少可用的文档.

Would really appreciate any help anyone can give relating to getting a very simple exoplayer instance working from which i can adapt and build upon or if anyone has any leads for more references or guides which I can follow as there seems to be very little documentation available.

非常感谢所有帮助!

推荐答案

首先,使用以下代码行实例化您的ExoPlayer:

First of all instantiate your ExoPlayer with this line:

exoPlayer = ExoPlayer.Factory.newInstance(RENDERER_COUNT, minBufferMs, minRebufferMs);

如果您只想播放音频,则可以使用以下值:

If you want to play audio only you can use these values:

RENDERER_COUNT = 1 //since you want to render simple audio
minBufferMs = 1000 
minRebufferMs = 5000

两个缓冲区的值都可以根据您的要求进行调整

Both buffer values can be tweaked according to your requirements

现在,您必须创建一个数据源.当您要流mp3时,可以使用DefaultUriDataSource.您必须传递上下文和UserAgent.为了简单起见,请播放一个本地文件,并以userAgent的形式传递null:

Now you have to create a DataSource. When you want to stream mp3 you can use the DefaultUriDataSource. You have to pass the Context and a UserAgent. To keep it simple play a local file and pass null as userAgent:

DataSource dataSource = new DefaultUriDataSource(context, null);

然后创建sampleSource:

Then create the sampleSource:

ExtractorSampleSource sampleSource = new ExtractorSampleSource(
                    uri, dataSource, new Mp3Extractor(), RENDERER_COUNT, requestedBufferSize);

uri指向您的文件,如果要播放mp3,则作为提取器,您可以使用简单的默认Mp3Extractor.可以根据您的要求再次调整requestedBufferSize.例如使用5000.

uri points to your file, as an Extractor you can use a simple default Mp3Extractor if you want to play mp3. requestedBufferSize can be tweaked again according to your requirements. Use 5000 for example.

现在,您可以使用示例源创建音频轨道渲染器,如下所示:

Now you can create your audio track renderer using the sample source as follows:

MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);

最后在exoPlayer实例上调用准备":

Finally call prepare on your exoPlayer instance:

exoPlayer.prepare(audioRenderer);

开始播放通话:

exoPlayer.setPlayWhenReady(true);

这篇关于创建一个ExoPlayer的简单实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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