Does anyone know if it’s possible to play a rtmp stream with exoplayer.
I’ve tried this but didn’t manage to get it working:
ExoPlayer player = new ExoPlayer.Builder(this).build();
playerView.setPlayer(player);
Uri uri = Uri.parse("rtmp://192.168.109.84/live");
MediaItem mediaItem = MediaItem.fromUri(uri);
RtmpDataSource.Factory rtmpDataSourceFactory = new RtmpDataSource.Factory();
MediaSource mediaSource = new ProgressiveMediaSource.Factory(rtmpDataSourceFactory).createMediaSource(mediaItem);
player.setMediaSource(mediaSource);
player.prepare();
player.setPlayWhenReady(true);
Related
In my video player when i try to play 2160p MKV 4k video file in exoplayer. The video is not playing.
Error message is ERROR_CODE_DECODING_FAILED
Error code is 4003.
Exoplayer version is 2.16.1
Same video file is playing using android video library and other video player app that i downloaded from play store.
Code :
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext());
ProgressiveMediaSource.Factory mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory);
trackSelector = new DefaultTrackSelector(this);
builder = new ExoPlayer.Builder(getApplicationContext());
builder.setSeekBackIncrementMs(10000);
builder.setSeekForwardIncrementMs(10000);
player = builder.setMediaSourceFactory(mediaSource).setTrackSelector(trackSelector).build();//new ExoPlayer.Builder(getApplicationContext()).setTrackSelector(trackSelector).build();
playerView.setPlayer(player);
MediaItem mediaItem;
ArrayList<MediaItem> mediaItems = new ArrayList<>();
for (int i = 0; i < vdList.size(); i++) {
Uri uri = Uri.parse(vdList.get(i).path);
mediaItem = new MediaItem.Builder().setUri(uri).build();
mediaItems.add(mediaItem);
}
player.addMediaItems(mediaItems);
playerView.setKeepScreenOn(true);
playerView.requestFocus();
player.prepare();
player.seekTo(position, C.TIME_UNSET);
player.play();
Please help me out.
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);
I am using exoplayer and I noticed when I play a video in one activity and then switch to another by pressing on a button the video itself stops playing in order to switch to the new activity, but the audio keeps playing. If I return to the old activity and play the video again the audio is still going + I hear the audio from playing the video again and hear the audio two times now simulteanously at different times of the song.
String url = model.getVideo();
try {
BandwidthMeter bandwidthMeter= new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory( bandwidthMeter));
holder.exoPlayer= ExoPlayerFactory.newSimpleInstance( LiFit.getContext(),trackSelector );
Uri videouri = Uri.parse(model.getVideo());
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
ExtractorsFactory extractorsFactory= new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(videouri,dataSourceFactory,extractorsFactory,null,null);
holder.videoView.setPlayer(holder.exoPlayer);
holder.exoPlayer.prepare(mediaSource);
//holder.exoPlayer.setPlayWhenReady(true);
} catch (Exception e) {
//Nichts
}
This is the code I am using does somebody know a solution for this problem ?
exoplayer has a method setPlayWhenReady which can be used to play/pause the media, and a release method when the player is no longer needed.
You can use these methods when switching to another activity.
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.
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);