2

I am developing an android app to play the HLS radio. I don't want to have a player view since there is no video track for the streaming. I want to control the audio playing by a play/pause button.

I did some google search and I found that there is a google official project called ExoPlayer which seems to have a feature of playing hls. I tried the example but it shows that it does not support the audio codec. Therefore, I wonder if there is any solution of

  1. an example of Exoplayer for playing HLS audio in android app without any player view
  2. any other solution to achieve my goal

Thank you!

Edited on 11th, May

The following part is my code, though it seems to be a deprecated method

DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
                String userAgent = Util.getUserAgent(MainActivity.this, "ExoPlayerDemo");
                DefaultDataSourceFactory mediaDataSourceFactory = new DefaultDataSourceFactory(MainActivity.this, BANDWIDTH_METER,
                        new DefaultHttpDataSourceFactory(userAgent, BANDWIDTH_METER));
                HlsMediaSource mediaSource = new HlsMediaSource.Factory(mediaDataSourceFactory)
                        .createMediaSource(Uri.parse(url), null, null);
                TrackSelection.Factory trackSelectionFactory  = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
                DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);
                DefaultRenderersFactory renderersFactory =
                        new DefaultRenderersFactory(MainActivity.this, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
                ExoPlayer player = ExoPlayerFactory.newSimpleInstance(MainActivity.this, trackSelector);
                player.setPlayWhenReady(true);
                if(mediaSource!=null) {
                    player.prepare(mediaSource);
                }

I will try using the example code from official site with a player ui and I will use a layout to overlap on the ui. I will be grateful if there is any other suggestion.

Jonas
  • 121,568
  • 97
  • 310
  • 388

0 Answers0