Play multiple URL at once in Android - android

How to play multiple URLs sequentially in android? I have a small streaming url 10s/each of one complete song. I need to play it one after another. Is there any way doing it so the music don't get lagged?

https://exoplayer.dev/media-sources.html read Advanced composition
MediaSource firstSource =
new ProgressiveMediaSource.Factory(...).createMediaSource(firstVideoUri);
MediaSource secondSource =
new ProgressiveMediaSource.Factory(...).createMediaSource(secondVideoUri);
// Plays the first video twice, then the second video.
ConcatenatingMediaSource concatenatedSource =
new ConcatenatingMediaSource(firstSource, firstSource, secondSource);

It looks like you are using the m3u8 playlist to play with MediaPlayer. However, you wouldn't able to do it. You can use ExoPlayer to play m3u8 list. Check this link
https://github.com/google/ExoPlayer

simpleExoPlayerView.setShowMultiWindowTimeBar(true);

Related

How to download and add subtitles to video using Exoplayer

I have a video player app which used the Exoplayer library to play videos but I want to be able to download and add subtitles dynamically using something like OpenSubtitles and then add them to the currently playing video.
Video players with similar features are MX Player and X Player.
How can I be able to achieve a similar functionality. Your answers are highly appreciated!
Yes, actually. OpenSubtitles.org has a nice API for searching and downloading.
Here you go
https://opensubtitles.stoplight.io/docs/opensubtitles-api/e3750fd63a100-getting-started
You can download subtitles separately or checking downloading media and add them using sideloading subtitles or you can use SingleSampleMediaSource like the following:
MediaSource[] mediaSources = new MediaSource[subtitlesCount + videoTrack];
mediaSources[0] = new ProgressiveMediaSource.Factory(new FileDataSource.Factory())
.createMediaSource(MediaItem.fromUri(videoPath));
//add subtitles tracks, and use correct format
SingleSampleMediaSource.Factory singleSampleSourceFactory = new SingleSampleMediaSource.Factory(new DefaultDataSourceFactory(context));
for (int i = 0; i < videoInfo.getSubtitlePaths().size(); i++) {
mediaSources[i + videoTrack] = singleSampleSourceFactory.createMediaSource(
new MediaItem.Subtitle(Uri.parse(subtitlePath), MimeTypes.TEXT_VTT, language), C.TIME_UNSET);
}
//use MergingMediaSource to combine the media sources
MergingMediaSource mergedSource = new MergingMediaSource(mediaSources);
....init player
mPlayer.addMediaSource(mergedSource);
mPlayer.prepare();

Android Exo Player - Trouble playing Video on Demand from API

I'm working with the Pac-12 API (college sports data) and trying to make a streaming video player.
The Pac-12 API (http://api.pac-12.com/v3/vod?page=0") gives back a list of video objects with urls for their Video's on Demand (VODs).
I have exo player set up in Android and it's working for videos with urls that end in .mp4.
But when I try to plug in the VOD urls it's giving an error that it cannot extract the file type.
I'm using exo player 2.8.4 which may or may not be the problem. But the newer version of exo player ( 2.9.0 and above ) has min sdk 26 (which my testing phone doesn't run).
I'm working on checking if that's the problem, but in the mean time I wanted to post this question in case anyone can help.
Here is my exo player set up. mediaUrl is the varaible that works with .mp4 but not the VOD url.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
context, Util.getUserAgent(context, "RecyclerView VideoPlayer"));
String mediaUrl = mediaObjects.get(targetPosition).getMedia_url();
if (mediaUrl != null) {
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(mediaUrl));
videoPlayer.prepare(videoSource);
videoPlayer.setPlayWhenReady(true);
}
The VOD urls give no file type extension at the end, so I tried concatenating '.vod' onto the mediaUrl varaible, but no luck with that.
From reading around online it seems like VODs are supported by exo player, but I can't find much about how the setup might be different.
Heres a direct link to one of the Pac-12 VODs. This is the same url as what the API returns.
https://pac-12.com/videos/oregons-dana-altman-talks-andy-katz-about-recruitment-getting-fans-back-and-more

seekTo(mTimeMilis) won't work properly when using ConcatenatingMediaSource in ExoPlayer

I have more than one video to play one by one. After Creating MediaSource of each video, All these are going to ConcatenatingMediaSource(mediaSources[]). Normally it play one by one. But when video is fast forward using seekTo(), 1st video is ok but other videos do not follow seekTo().
Suppose 1st video is 10s, 2nd 12s, 3rd 10s.
If I call seekTo((long)12*1000) it should play 2nd video with 2s forward. But it plays from the beginning of 2nd video.
Setting VideoSources
DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),Util.getUserAgent(getApplicationContext(), "ExoPlayer"));
MediaSource mediaSource = new ExtractorMediaSource.Factory(defaultDataSourceFactory).createMediaSource(videoItem.getVideoUri());
videoItemArrayList.get(k).setVideoSource(mediaSource);
Concatenate Sources
MediaSource[] mediaSources = new MediaSource[videoItemArrayList.size()];
int j=0;
for(VideoItem item : videoItemArrayList){
mediaSources[j] = item.getVideoSource();
++j;
}
concatenatedSource = new ConcatenatingMediaSource(mediaSources);
Setup exoplayer
exoPlayer.prepare(concatenatedSource);
exoPlayer.seekTo(0);
exoPlayer.setPlayWhenReady(true);
exoPlayer.getPlaybackState();
Using exoplayer.seekTo(period) internally calls currentWindowIndex() internally of the source. While you are playing the first video in the concatenated mediasource you end up receiving windowIndex as 0. Use seekTo(windowIndex, time) to solve the issue.

ExoPlayer Cant Play some audio streams

i am newbie here. i am developing a android app to listen to online radio stations.
problem i am getting here is ExoPlayer(2.9.2) can or cant play some streams of same type of different bitrates.
For Example
These mpga streams
http://108.61.34.50:7130/ ---> 96kbs ===> Playable
http://s3.voscast.com:8408 ---> 64kbs ===> Not Playable
http://220.247.227.20:8000/citystream ---> 128kbs ===> Not Playable
i used vlc codec window to get this information, and those 3 streams share same values other than bitrate.
i am using ExtractorMediaSource
songs.add(Uri.parse("http://220.247.227.20:8000/citystream"));//City
player= ExoPlayerFactory.newSimpleInstance(this,
new DefaultTrackSelector());
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "AudioApp"));
ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource();
for (Uri temp : songs)
{
BaseMediaSource mediaSourse=
new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(temp);
concatenatingMediaSource.addMediaSource(mediaSourse);
}
player.prepare(concatenatingMediaSource);
player.setPlayWhenReady(true);
Hope anyone can help me out..
After testing various different streams, i realized that this is a device specific error.
Huawei Y5 2017
the other phone's that i tested work pretty well and i ended up submiting issue to ExpoPlayer team on github without knowing this is device specific issue.
Here it is
Why does ExoPlayer cant play some of the streams of same type with different bitrates ?

how to add multiple subtitles in Exo Player 2

I want to show subtitles with ExoPlayer 2 . users can choose between languages (English,German, or Arabic) . Video links are HLS (.m3u8) and subtitles are .str files .
I couldn't find any samples to do this.
is there any sample?
The link I added as a comment to your original post will be how you'll build the UI around text track selection. Then to actually get the tracks to be added to your mp4 file (or whatever the format is), you'll want to use a MergingMediaSource. The simple version looks like so:
MediaSource videoSource = new ExtractorMediaSource(videoUri, ...);
MediaSource subtitleSource = new SingleSampleMediaSource(subtitleUri, ...);
// Plays the video with the sideloaded subtitle.
MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);
You can merge multiple subtitle tracks into the video source. Many different file formats are accepted.
I got that particular code sample from this blog post - but I believe that same code is also in the ExoPlayer documentation. That code block combined with the sample code that I link to in my other answer here should be enough to get you some subtitles.
Please let me know if that works for you.

Categories

Resources