Internet-radio stream using ExoPlayer v2 - android

I used EXOPlayer v1.5.6 to playing Mp3/AAC AudioStream, but this version a has lot of flaws.
I decided to upgrade to v 2.0.2, but I can't find documentation for playing only Audio Stream.
Please, help.

Here is the developer guide for new version of ExoPlayer - link.
You can play stream from URI this way:
TrackSelector trackSelector = new DefaultTrackSelector(
new Handler(),
new AdaptiveVideoTrackSelection.Factory(
new DefaultBandwidthMeter()
)
);
mediaPlayer = ExoPlayerFactory.newSimpleInstance(
getApplicationContext(),
trackSelector,
new DefaultLoadControl()
);
MediaSource source = new ExtractorMediaSource(
yourURI,
new OkHttpDataSourceFactory(
new OkHttpClient(),
userAgent,
null
),
new DefaultExtractorsFactory(),
null,
null
);
mediaPlayer.prepare(source);
mediaPlayer.setPlayWhenReady(true);

Related

Exoplayer can't play only audio for HLS

I have link only audio https://storage.googleapis.com/as-piepme/1465/livestream/1465.fef238cdc9d9eb0b958d4eb23080e28b/index.m3u8 but Exoplayer can't play above link,
it return "source error". But both IOS and Chrome run fine. My code:
SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();
player.setMediaItem(MediaItem.fromUri(Uri.parse(linkPlay)));
player.prepare();
player.setPlayWhenReady(true);
Update my solution:
MediaItem mediaItem = new MediaItem.Builder()
.setUri(Uri.parse("https://storage.googleapis.com/as-piepme/1465/livestream/1465.fef238cdc9d9eb0b958d4eb23080e28b/index.m3u8"))
.build();
DefaultHlsExtractorFactory defaultHlsExtractorFactory = new DefaultHlsExtractorFactory(DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM, false);
MediaSource mediaSource = new HlsMediaSource.Factory(new DefaultHlsDataSourceFactory(new DefaultDataSourceFactory(context)))
.setExtractorFactory(defaultHlsExtractorFactory)
.setAllowChunklessPreparation(true)
.createMediaSource(mediaItem);
player.setMediaSource(mediaSource);
You need to use a Media source.
Try this sample code.
DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory();
// Create a HLS media source pointing to a playlist uri.
HlsMediaSource hlsMediaSource =
new HlsMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(hlsUri));
// Create a player instance.
SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();
// Set the media source to be played.
player.setMediaSource(hlsMediaSource);
// Prepare the player.
player.prepare();
For more details check the documentation.
Update
Use this one.
DefaultTrackSelector trackSelector = new DefaultTrackSelector(this, new AdaptiveTrackSelection.Factory());
DefaultTrackSelector.Parameters trackSelectorParameters = trackSelector.buildUponParameters().setMaxAudioChannelCount(0).build();
trackSelector.setParameters(trackSelectorParameters);
RenderersFactory renderersFactory = new DefaultRenderersFactory(this);
SimpleExoPlayer audioPlayer = = new SimpleExoPlayer.Builder(this, renderersFactory).setTrackSelector(trackSelector).build();
HttpDataSource.Factory factory = new DefaultHttpDataSourceFactory("Online Audio Player", DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
audioPlayer.setMediaSource(new ProgressiveMediaSource.Factory(factory).createMediaSource(MediaItem.fromUri("https://storage.googleapis.com/as-piepme/1465/livestream/1465.fef238cdc9d9eb0b958d4eb23080e28b/index.m3u8")));
audioPlayer.prepare();
audioPlayer.setPlayWhenReady(true);

Android ExoPlayer Can't Play HLS (HTTP Live Streaming)

I want to use ExoPlayer to play HLS (HTTP Live Streaming).
But I got the following error:
E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://my_url/file.m3u8
Below is my setup code:
private fun playTest() {
player = ExoPlayerFactory.newSimpleInstance(
DefaultRenderersFactory(this.requireContext()), DefaultTrackSelector(), DefaultLoadControl())
val uri = Uri.parse("https://my_url/file.m3u8")
ep_video_view.player = player
val dataSourceFactory = DefaultDataSourceFactory(this.requireContext(), "user-agent")
val mediaSource = HlsMediaSource(uri, dataSourceFactory, handler, null)
player?.prepare(mediaSource)
player?.playWhenReady = true
}
Thank you in advance.
in java
TrackSelection.Factory adaptiveTrackSelection = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
player = ExoPlayerFactory.newSimpleInstance(
new DefaultRenderersFactory(mContext),
new DefaultTrackSelector(adaptiveTrackSelection),
new DefaultLoadControl());
playerView.setPlayer(player);
DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(mContext,
Util.getUserAgent(mContext, "Exo2"), defaultBandwidthMeter);
String hls_url = "YOUR STREAMING URL HERE";
Uri uri = Uri.parse(hls_url);
Handler mainHandler = new Handler();
MediaSource mediaSource = new HlsMediaSource(uri,
dataSourceFactory, mainHandler, null);
player.prepare(mediaSource);
player.setPlayWhenReady(true);
https://medium.com/#haxzie/adaptive-hls-streaming-on-android-with-googles-exoplayer-64820017edf0
Total newbie here but hope it'll help. I've been doing the same thing as you and I noticed that unencrypted hls stream works. Try using a link with http. Just to check. I can't get Exoplayer to play https hls stream.

How to play online video using ExoPlayer which is encrypted?

I want to play encrypted videos using ExoPlayer I am very new to ExoPlayer I don't know much about that. I found some links[https://stackoverflow.com/a/54247524/9789670] but those are not working fine.I need some help regrading this issue
Use this code for play video
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(null);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(mContxt, trackSelector);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(mContxt,
Util.getUserAgent(mContxt, "CloudExoplayer"));
Uri videoUri = Uri.parse(url);
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(videoUri);
player.prepare(videoSource);
player.setRepeatMode(Player.REPEAT_MODE_ALL);
exoplayer.setPlayer(player);
exoplayer.requestFocus();
exoplayer.setPlayWhenReady(true);

Android Exoplayer 2 UDP Decoding issue

I'm new on ExoPlayer , i'm currently heading to use it to play Native Udp Stream ( From french digital Television : 1080p 5-10 mbps in Variable bitrate )
I manage to play some udp stream with some tests videos from http://jell.yfish.us/ on different devices .
I have make some different video decoding test with HLS and Udp Streaming with this code for UDP :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myactivity);
sufaceview = (SurfaceView) findViewById(R.id.surfaceView2);
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl(
new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE),
15000, 60000, 2500, 6000);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
Uri uri =
Uri.parse
("udp://#239.192.2.2:1234");
final DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "teveolauncher"), bandwidthMeterA);
extractorsFactory = new DefaultExtractorsFactory();
DataSource.Factory udsf = new UdpDataSource.Factory() {
#Override
public DataSource createDataSource() {
return new UdpDataSource(null, 3000, 100000);
}
};
ExtractorsFactory tsExtractorFactory = new ExtractorsFactory() {
#Override
public Extractor[] createExtractors() {
return new TsExtractor[]{new TsExtractor(MODE_SINGLE_PMT,
new TimestampAdjuster(0), new DefaultTsPayloadReaderFactory())};
}
};
MediaSource videoSource = new ExtractorMediaSource
(uri, udsf, tsExtractorFactory, null, null);
player.setVideoSurfaceView(sufaceview);
player.prepare(videoSource);
player.setPlayWhenReady(true);
}
For HLS I just Change the MediaSource and the datasourceFactory :
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "teveolauncher"), bandwidthMeterA);
MediaSource videoSource = new HlsMediaSource
(uri, dataSourceFactory, null, null);
I Know Udpstreaming is not officialy supported by ExoPlayer but the UdpDataSource class seems to work well.
After all the test , i noticed video with a variable biterate like french DTT can't be decoded correctly but with Constatnt biterate video like Jell yfish the decoding process is perfect .
There is some coding improvement to make VBR video decoded correctly ?
Thank you by advance :)
Sorry for my bad english :)
Uri uri = Uri.parse("udp://#239.192.2.2:1234");
I think UDP is not a protocol - it's a transport, (like TCP). You can't use a tcp://host:port/ URL either.
Or does it work?

Android : How to use exoplayer 2.x.x to stream a radio link

I want to stream for an online radio with exoplayer version rc2.x.x though an android service.
I have been trying to learn from all tutorials online I could but they are all prior to the 2.x.x version and a lot of them are video streaming related as well (which I don't need).
Does anyone has a very nice tutorial?
I don't have deep knowledge of ExoPlayer but I have prepared this code snippet which can stream mp3 link.
EXO Player Verison : r2.0.4
private void initMediaPlayer() {
Handler mHandler = new Handler();
String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:40.0) Gecko/20100101 Firefox/40.0";
Uri uri = Uri.parse("http://feedproxy.google.com/~r/TheCombatJackShow/~5/s_9fWPxLDu0/188058705-thecombatjackshow-the-j-cole-episode.mp3");
DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
userAgent, null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
true);
MediaSource mediaSource = new ExtractorMediaSource(uri, dataSourceFactory, Mp3Extractor.FACTORY,
mHandler, null);
TrackSelector trackSelector = new DefaultTrackSelector(mHandler);
DefaultLoadControl loadControl = new DefaultLoadControl();
ExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
//exoPlayer.addListener(this);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);
}
This link may also help you :
https://medium.com/#emuneee/migrating-from-exoplayer-1-x-to-2-0-58fbda36b46c#.b8joifc36

Categories

Resources