im currently doing a streaming app but i got an issue with exployer, some of my video link are playing fine with sound, but some is not, here is the sample streaming link i have
http://202.57.43.60:8443/live/5748aabe4c9d661afbd7f4068248f664/99.m3u8
and here is my code:
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
playerView = findViewById(R.id.movie_exo_player);
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
simpleExoPlayer.setAudioAttributes(new AudioAttributes
.Builder().build());
playerView.setPlayer(simpleExoPlayer);
DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "Exo2"), defaultBandwidthMeter);
DefaultHlsExtractorFactory defaultHlsExtractorFactory = new DefaultHlsExtractorFactory(FLAG_ALLOW_NON_IDR_KEYFRAMES);
MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory)
.setExtractorFactory(defaultHlsExtractorFactory)
.createMediaSource(Uri.parse(VIDEO_TEST_URL));
LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
simpleExoPlayer.prepare(loopingSource);
if(VIDEO_TEST_URL != null){
simpleExoPlayer.prepare(mediaSource);
simpleExoPlayer.setPlayWhenReady(true);
}
any form of help is much appreciated
Related
I am playing video on Android using ExoPlayer. But " DefaultBandwidthMeter();" is deprecated.
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
//DefaultTrackSelector chooses tracks in the media item
DefaultTrackSelector trackSelector = new DefaultTrackSelector(this);
trackSelector.setParameters(trackSelector.buildUponParameters().setMaxVideoSizeSd());
mPlayer = new SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).build();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayerapp"), bandwidthMeter);
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url));
mPlayer.prepare(mediaSource);
playerView.setKeepScreenOn(true);
playerView.requestFocus();
playerView.setPlayer(mPlayer);
mPlayer.setPlayWhenReady(true);
playBackStateListener = new PlayBackStateListener();
mPlayer.addListener(playBackStateListener);
What should I use insead of this and according to that with what I should replace the following line which is using theis bandwidthMeter?
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayerapp"), bandwidthMeter);
You should use DefaultBandwidthMeter.Builder. Source from ExoPlayer documentation.
If you use HLS Media Type you should this:
val defaultHttpDataSourceFactory = DefaultHttpDataSource.Factory()
Note: It worked this version: implementation 'com.google.android.exoplayer:exoplayer:2.18.2'
I'm using Exoplayer version 2 for playing Video from Internal Storage and it works fine but whenever video contains ac3 type audio,exoplayer not plays audio,it only display video.
please help me
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), bandwidthMeter);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory().setConstantBitrateSeekingEnabled(true);
videoSource = new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null);
player.prepare(videoSource);
Same Problem also Occurring with Android Media player
I am using ExoPlayer to play videos from URL. For some reason, my video keeps on buffering even it is low size video also. Please find the code snippet below which I have used to build ExoPlayer.
private MediaSource buildMediaStore(String mediaUrl) {
Uri videoUri = Uri.parse(mediaUrl);
DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, getApplicationInfo().packageName), defaultBandwidthMeter);
DefaultExtractorsFactory extractorFactory = new DefaultExtractorsFactory();
return new ExtractorMediaSource(videoUri, dataSourceFactory, extractorFactory, null, null);
}
defaultBandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(ViewVideoNewPotriateFullScreen.this),
new DefaultTrackSelector(trackSelectionFactory), new DefaultLoadControl());
MediaSource datasource = buildMediaStore(url);
exoPlayer.prepare(datasource, true, true);
simpleExoPlayer.setPlayer(exoPlayer);
simpleExoPlayer.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
exoPlayer.setRepeatMode(Player.REPEAT_MODE_OFF);
exoPlayer.setPlayWhenReady(true);
exoPlayer.seekTo(getIntent().getLongExtra("position", 0));
//updateTimers();
exoPlayer.addListener(this);
My video player is not playing on Asus Zenfone 2 running Android Marshmallow. I don't know if it's a problem with the caching library or ExoPlayer.
My code is as follows -
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelectorvideoTrackSelectionFactory);
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
mBetterVideoPlayer.setKeepScreenOn(true);
mBetterVideoPlayer.setPlayer(exoPlayer);
mBetterVideoPlayer.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
HttpProxyCacheServer proxy = AppBaseApplication.getProxy(NewWorkoutVideoActivity.this);
proxy.registerCacheListener(NewWorkoutVideoActivity.this, current.getVideo());
proxyUrl = proxy.getProxyUrl(current.getVideo());
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),Util.getUserAgent(this, "yourApplicationName"));
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(proxyUrl));
exoPlayer.prepare(videoSource);
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?