How to load mp3 url using exoplayer?

The exoplayer library seems so complicated to me. Can someone help me how to pass url radio station using exoplayer library? I tried with MediaPlayer, it works great, but it takes so much time to prepare. Here is what I have tried.

exoPlayer = ExoPlayer.Factory.newInstance(RENDERER_COUNT); Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE); DataSource dataSource = new DefaultUriDataSource(getApplicationContext(), null, userAgent); Mp3Extractor extractor = new Mp3Extractor(); ExtractorSampleSource sampleSource = new ExtractorSampleSource( uri, dataSource, extractor, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE); MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource); exoPlayer.prepare(audioRenderer); exoPlayer.setPlayWhenReady(true); 

I do not understand how to get userAgent and what does it mean?

+7
android exoplayer
source share
3 answers

Here is a good description of what a user agent is: a user agent It should also indicate what a user agent should look like: user agent header structure Here you can see what your browser user agent looks like: http://whatsmyuseragent.com/

Simply put, you can create your user agent as follows:

"YourAppName / VersionCode"

Finally, a description of how to use ExoPlayer to stream mp3: Stream mp3 with ExoPlayer In this example, this is a local mp3, but the only difference should be the mp3 url and the missing user agent. Hope this helps!

+5
source share

This is the easiest way to stream m3u8 files using ExoPlayer Lib. check this code and do not forget to change the URL to your own, as well as change the type of content as a code with a purge hope to help https://github.com/karim23/SimpleStreamPlayer/tree/master

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getApplicationContext(); setContentView(R.layout.activity_main); //change the live streaming URL with yours. contentUri = /*"Your mp3 URL.."*/; // contentType = DemoUtil.TYPE_MP3; final Intent intent = new Intent(context, VideoPlayerActivity.class).setData(Uri.parse(contentUri)) .putExtra(VideoPlayerActivity.CONTENT_ID_EXTRA, -1) //Change the type according to the live streaming extension. .putExtra(VideoPlayerActivity.CONTENT_TYPE_EXTRA, DemoUtil.TYPE_MP3); liveStreamingTv =(TextView)findViewById(R.id.mainActivity_liveStreamingTv); liveStreamingTv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(intent); } }); } 
+1
source share

This was a problem with the codec, exoPlayer does not support aac +

0
source share

All Articles