Exoplayer video stop when audio is muted (encoder is flash) - android

Hi I am creating an app that will broadcast live and another user can view it
I am currently using flash to push it into WOWZA and I am using exoplayer for viewing it
I am using RTMP because it's the only one supported by exoplayer which has low latency
everything works perfect however when I mute the microphone in the live side the video in exoplayer will freeze and will go to status
STATE_BUFFERING but it will not proceed to STATE_READY
and if I unmute it will go back to normal and can view it again from
STATE_BUFFERING to STATE_READY
And anyway I tried the stream to view in VLC and it does work it doesn't freeze
I tried other solution but doesn't work
my code is this
//initiate Player
//Create a default TrackSelector
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
//Create the player
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
PlayerView playerView = findViewById(R.id.simple_player);
playerView.setPlayer(player);
RtmpDataSourceFactory rtmpDataSourceFactory = new RtmpDataSourceFactory();
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource.Factory(rtmpDataSourceFactory)
.createMediaSource(Uri.parse(URL));
player.prepare(videoSource);
//auto start playing
player.setPlayWhenReady(true);
I hope someone helps me!!!
thank you in advance

Related

Exoplayer keeps playing the audio even when video is stopped after

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.

exoplayer- automatic change of quality is not working (hls)

i have little problem with exoplayer. almost everything works fine when i try to play video from hls stream. hls stream contains 3 different sets of chunklists each for different bandwidth.
but hls adaptive streaming is not working and player works only with one chunklist and with slow internet connection is this solution unusable.
source code:
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
this.simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), trackSelector);
this.videoPlayer.setPlayer(this.simpleExoPlayer);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this.getActivity(), Util.getUserAgent(this.getActivity(), "appName"));
MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(hlsUrl));
this.simpleExoPlayer.prepare(mediaSource);
this.simpleExoPlayer.setPlayWhenReady(true);
i tried to implement MediaSourceEventListener too and onDownstreamFormatChanged is called only once in the moment of player initialization.
thanks for any advices
The key here is you need to pass the same "bandwidthMeter" you passed in to AdaptiveTrackSelection.Factory to the dataSourceFactory too.
Only after these changes the Exoplayer does adaptive streaming as expected.
String userAgent = "XYZPLAYER";
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, bandwidthMeter, httpDataSourceFactory);

How to implement seekTo() when using HLS with the ExoPlayer

I am trying to implement a basic radio player that can pause the live stream, rewind it and then fast forward it again.
I think that this functionality should be natively supported from version 2.1 of the ExoPlayer.
However, the rewind and fast-forward controls are grayed out when streaming even though they work when playing local content.
Here is how I am creating the player:
private void initExoPlayer(){
Handler mHandler = new Handler();
String userAgent = "userAgent";
Uri uri = Uri.parse(urlSourceOfStream);
dataSourceFactory = new DefaultHttpDataSourceFactory(
userAgent, null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
1800000,
true);
mediaSource = new ExtractorMediaSource(uri,dataSourceFactory, Mp3Extractor.FACTORY,
mHandler, null);
bandwidthMeter = new DefaultBandwidthMeter();
trackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(trackSelectionFactory);
loadControl = new DefaultLoadControl();
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
exoPlayer.prepare(mediaSource);
((SimpleExoPlayerView) findViewById(R.id.exoPlayer)).setPlayer(exoPlayer);
}
The player can pause successfully, and it seems to be caching the content as I can resume the player after it has been paused for minutes. This also indicates that there should be some cache that can allow me to rewind the content.
I've also tried using the OkHttpDataSourceFactory :
OkHttpClient client = new OkHttpClient.Builder().cache(new Cache(getFilesDir() , 1000)).build();
OkHttpDataSourceFactory okHttpDataSourceFactory = new OkHttpDataSourceFactory(client, userAgent, null);
Trying to rewind the player like this makes the player play from the live stream position and does not rewind the content:
exoPlayer.seekTo(Math.max(exoPlayer.getCurrentPosition() - 1000, 0));
My question in a nutshell: How can I rewind and fast-forward an HLS with the ExoPlayer?
Thanks in advance.
It looks like there is a bug, https://github.com/google/ExoPlayer/issues/87 discussing this, and it's been closed. But I'm not sure if its reached the v2 release, and rather it might be in the dev release, here

Exoplayer doesnt play any video

Have a problem getting Exoplayer to work. I managed to load the video from a url. But it only plays the audio. So i am doing something wrong.
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
SimpleExoPlayer exoPlayer = ExoPlayerFactory.newSimpleInstance(simpleExoPlayerView.getContext(), trackSelector, loadControl);
Uri mp4VideoUri = Uri.parse(videoUri);
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("ExoPlayerDemo");
ExtractorsFactory extractor = new DefaultExtractorsFactory();
MediaSource videoSource = new ExtractorMediaSource(mp4VideoUri, dataSourceFactory, extractor, null, null);
exoPlayer.prepare(videoSource);
exoPlayer.setPlayWhenReady(true);
This is how i where able to only play the audio. Not sure what i should change.
Looks like you miss to bind player to player view
Attaching player to view
The ExoPlayer library provides a SimpleExoPlayerView, which encapsulates a PlaybackControlView and a Surface onto which video is rendered. A SimpleExoPlayerView can be included in your application’s layout xml. Binding the player to the view is as simple as:
// Bind the player to the view.
simpleExoPlayerView.setPlayer(player);
If you require fine-grained control over the player controls and the Surface onto which video is rendered, you can set the player’s target SurfaceView, TextureView, SurfaceHolder or Surface directly using SimpleExoPlayer’s setVideoSurfaceView, setVideoTextureView, setVideoSurfaceHolder and setVideoSurface methods respectively. You can use PlaybackControlView as a standalone component, or implement your own playback controls that interact directly with the player. setTextOutput and setId3Output can be used to receive caption and ID3 metadata output during playback.

How to detect HLS video is for Live, VOD or Event in Exoplayer android

I have integrated android exoplayer in my application. I have to detect the HLS (.m3u8) stream received is for Live or VOD or Event, so depending on that controller has to be modified for the player. I have only one instance of player so that should handle all the supported media like vod or live or event.
I am looking for some debug points to know working of m3u8 parser in exoplayer so that I can able to receive this parameters.
You can use below code to play .m3u8 file:-
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
//Create the player using ExoPlayerFactory
videoPlayer = ExoPlayerFactory.newSimpleInstance(context,trackSelector);
Handler mHandler = new Handler();
String userAgent = Util.getUserAgent(context, "Exo Player");
DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
userAgent, null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
1800000,
true);
HlsMediaSource mediaSource = new HlsMediaSource(Uri.parse(mediaUrl),dataSourceFactory, 1800000,mHandler, null);
if (mediaUrl != null) {
videoPlayer.prepare(mediaSource);
videoPlayer.setPlayWhenReady(true);
}
Live vs Event differentiation is not supported, yet. For Live vs Event you can check the current Timeline, but that's not HLS specific. For distinguish a live stream from a vod one by querying the player's duration after it is prepared. Live streams will return UNKNOWN_TIME, where-as vod streams will return the known duration of the stream.

Categories

Resources