Exoplayer m3u8 and mp3 run with a single code error - android

if i use the first one from the following codes,
the 1.m3u8 type songs are running.
if i use the second one, mp3 and the other songs are running.
Is there one code series that can run these formats in one? Maybe it is a simple coding but i couldn t do that. Please help me.
#Override
protected String doInBackground(String... a) {
String s = Constant.arrayList_play.get(Constant.playPos).getMp3Url().replace(" ","%20");
try {
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory((MainActivity)Constant.context,
Util.getUserAgent((MainActivity)Constant.context, "onlinemp3"), bandwidthMeter);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource videoSource = new ExtractorMediaSource(Uri.parse(s),
dataSourceFactory, extractorsFactory, null, null);
Constant.exoPlayer.prepare(videoSource);
Constant.exoPlayer.setPlayWhenReady(true);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

May be you need to read here about exoplayer's supported formats.

Related

I am trying To play video using Firebase but it show me DefaultHttpDataSourceFactory is Deprecated

[I provided image link please see image i got so many errors1 private void initializeExoplayerView(String videoUrl) {
try{
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(this).build();
TrackSelector trackSelector = new DefaultTrackSelector(this,newAdaptiveTrackSelection.Factory(bandwidthMeter));
exoPlayer = (SimpleExoPlayer) ExoPlayerFactory.newSimpleInstance(this, trackSelector);
Uri videouri = Uri.parse(videoUrl);
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory("exoplayer_video");
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(videouri, dataSourceFactory, extractorsFactory, null, null);
exoPlayerView.setPlayer(exoPlayer);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);
} catch (Exception e){
Log.e("TAG", "Error : " + e.toString());
}
}
You should use the new Factory for HTTP Data source instead 'DefaultHttpDataSource.Factory'.
https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.Factory.html
You can find examples of it's use in the ExoPlayer GitHub repository in the test and demo code - for example, if you look at the extract below and follow the calls its makes:
public void start_playlistCanBlockReloadLowLatencyFullSegment_correctMsnAndPartParams()
throws IOException, TimeoutException, InterruptedException {
List<HttpUrl> httpUrls =
enqueueWebServerResponses(
new String[] {
"/master.m3u8",
"/media0/playlist.m3u8",
"/media0/playlist.m3u8?_HLS_msn=14&_HLS_part=0"
},
getMockResponse(SAMPLE_M3U8_LIVE_MASTER),
getMockResponse(SAMPLE_M3U8_LIVE_MEDIA_CAN_BLOCK_RELOAD_LOW_LATENCY_FULL_SEGMENT),
getMockResponse(SAMPLE_M3U8_LIVE_MEDIA_CAN_BLOCK_RELOAD_LOW_LATENCY_FULL_SEGMENT_NEXT));
List<HlsMediaPlaylist> mediaPlaylists =
runPlaylistTrackerAndCollectMediaPlaylists(
new DefaultHttpDataSource.Factory(),
Uri.parse(mockWebServer.url("/master.m3u8").toString()),
/* awaitedMediaPlaylistCount= */ 2);
from: https://github.com/google/ExoPlayer/blob/0ba317b1337eaa789f05dd6c5241246478a3d1e5/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/playlist/DefaultHlsPlaylistTrackerTest.java

How to display video in full screen mode using ExoPlayer?

I am using Customised ExoPlayer to display videos in my project. I set some fixed height for ExoPlayer view let say 300dp the video is playing without any issues. But the problem is if I set the height of ExoPlayer view to match parent and change the screen orientation to landscape the video is playing but it keeps on buffering. The state of the video most of the time is reaming in the buffering state. Please help me to solve the issue and I am posting the code snippet of my data source below.
public void play(String url) {
defaultBandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(VideoNewFullScreenMode.this),
new DefaultTrackSelector(trackSelectionFactory), new DefaultLoadControl());
MediaSource datasource = buildMediaStore(url);
exoPlayer.prepare(datasource, true, true);
simpleExoPlayer.setPlayer(exoPlayer);
exoPlayer.setPlayWhenReady(true);
simpleExoPlayer.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
exoPlayer.seekTo(getIntent().getLongExtra("position", 0));
//updateTimers();
exoPlayer.addListener(this);
}
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);
}

How to create a dialog with available qualities of DASH content in ExoPlayer?

I am using Exoplayer in my application and I want to show DashMediaSource.
I did it and the video will play this Code:
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "ExoPlayer"));
Uri uri = Uri.parse(videoUrl);
DashMediaSource dashMediaSource = new DashMediaSource(uri, dataSourceFactory,
new DefaultDashChunkSource.Factory(dataSourceFactory), null, null);
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
simpleExoPlayerView.setPlayer(player);
player.prepare(dashMediaSource);
But I need to show the user a selector for the quality of this vide0.
I just want to get all available qualities from my dash file and show it to the use.
In ExoPlayer 1.5.8, I used getTrackCount() to get all available qualities but in ExoPlayer 2.5.3 it is not available anymore.
How can I do that?
I really appreciate your help.
Have you tried using AnalyticsListener?
player.addAnalyticsListener(new AnalyticsListener() {
#Override
public void onBandwidthEstimate(EventTime eventTime, int totalLoadTimeMs, long totalBytesLoaded, long bitrateEstimate) {
}
});

Cannot Play Exoplayer video with assets folder

I want to play Video with ExoPlayer, but unfortunately I cannot find any solution.Please help me I've been scratching my head for two days but can't find anything.
This is my code when preparing and setting exoPlayer properties.
String path = "asset:///splash_video.mp4";
Uri uri = Uri.parse(path);
player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
DataSource.Factory factory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, getPackageName()));
simpleExoPlayerView.setPlayer(player);
ExtractorMediaSource extractorMediaSource = new ExtractorMediaSource(uri, factory, new DefaultExtractorsFactory(), new Handler(), null);
player.prepare(extractorMediaSource);
player.setPlayWhenReady(true);
Also I've been following this link from youtube.
https://www.youtube.com/watch?v=vwImlEfitQU
Here is my code is working for audio files,working fine and tested ok:
You just pass file name which should be like 001 is the file in assets\001.mp3
you should call the function like this:
prepareExoPlayerFromAssetResourceFile(001);
the code is:
private void prepareExoPlayerFromAssetResourceFile(int current_file) {
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector((TrackSelection.Factory) null), new DefaultLoadControl());
exoPlayer.addListener(eventListener);
//DataSpec dataSpec = new DataSpec(Uri.parse("asset:///001.mp3"));
DataSpec dataSpec = new DataSpec(Uri.parse("asset:///" + (current_file))+".mp3");
final AssetDataSource assetDataSource = new AssetDataSource(this);
try {
assetDataSource.open(dataSpec);
} catch (AssetDataSource.AssetDataSourceException e) {
e.printStackTrace();
}
DataSource.Factory factory = new DataSource.Factory() {
#Override
public DataSource createDataSource() {
//return rawResourceDataSource;
return assetDataSource;
}
};
MediaSource audioSource = new ExtractorMediaSource(assetDataSource.getUri(),
factory, new DefaultExtractorsFactory(), null, null);
/*
MediaSource audioSource1 = new ExtractorMediaSource(
Uri.parse("asset:///" + getfileName(current_file)), // file audio ada di folder assets
new DefaultDataSourceFactory(this, userAgent),
new DefaultExtractorsFactory (),
null,
null
);
*/
exoPlayer.prepare(audioSource);
}
You may also need to set appt compress config in build.gradle(app).
android {
...
aaptOptions{
noCompress "mp4" // file extesion
}
}
You should use a DefaultDataSourceFactory instead of a DefaultHttpDataSourcFactory:
new ExtractorMediaSource(
Uri.parse("asset://splash_video.mp4"),
new DefaultDataSourceFactory(context, userAgent),
new DefaultExtractorsFactory(),
null,
null);
Create a folder "raw" inside your application's "res" folder and copy the file to the newly created folder and replace,
ExtractorMediaSource audioSource = new ExtractorMediaSource(
Uri.parse("asset:///" + current_file), // file audio ada di folder assets
new DefaultDataSourceFactory(this, userAgent),
new DefaultExtractorsFactory(),
null,
null
);
this code with,
Uri uri = Uri.parse("android.resource://Your Package Name/" + R.raw.welcome_video);
ExtractorMediaSource audioSource = new ExtractorMediaSource(
Uri.parse("uri ), // file audio ada di folder assets
new DefaultDataSourceFactory(this, userAgent),
new DefaultExtractorsFactory(),
null,
null
);

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?

Categories

Resources