Hi I am looking for an example to configure ExoPlayer for DASH. But the example I found uses Youtube videos. Is there an example on videos which are not on youtube? Can DASH be configured for any video on the internet?
Yes, ExoPlayer can play any DASH, SmoothStreaming, HLS or MP4 Progressive download over HTTP URLs.
The demo application provided in ExoPlayer source code can be modified to add any video that will be shown in the startup Activity. To do that, edit https://github.com/google/ExoPlayer/blob/master/demo/src/main/java/com/google/android/exoplayer/demo/Samples.java file to add a new sample set.
Example:
public static final Sample[] CUSTOM_DASH_VIDEOS = new Sample[] {
new Sample("Some User friendly name of video 1",
"http://www.somewhere.com/somecontent.mpd?param1=val1¶m2=val2", DemoUtil.TYPE_DASH),
new Sample("Some User friendly name of video 2",
"http://www.somewhere.com/somecontent.mpd?param1=val1¶m2=val2", DemoUtil.TYPE_DASH),
};
Now, in https://github.com/google/ExoPlayer/blob/master/demo/src/main/java/com/google/android/exoplayer/demo/SampleChooserActivity.java add a new row in sample adapter.
sampleAdapter.add(new Header("Custom DASH Videos"));
sampleAdapter.addAll((Object[]) Samples.CUSTOM_DASH_VIDEOS);
Hope this answers your question.
Related
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();
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
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);
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.
I am working on an app which stream youtube videos.
Here is my code snippet :
MediaController mediaController = new MediaController(PlayVideo.this);
mediaController.setAnchorView(videoView_Video);
mediaController.setMediaPlayer(videoView_Video);
Uri videoUri = Uri.parse(url);
videoView_Video.setMediaController(mediaController);
videoView_Video.setVideoURI(videoUri);
videoView_Video.requestFocus();
videoView_Video.start();
mediaController.show();
My URI:
videoUri = rtsp://v2.cache8.c.youtube.com/CiILENy73wIaGQm-LZitWsUGKxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
Now I Am getting an error as below:
1. http youtube = false, scheme = rtsp
2. Couldn't open file on client side, trying server side
3. Error (1,-2147483648)
4. Error: 1,-2147483648
And a dialog with a message :
Please suggest any answer to overcome this.
Use the proper API instead of manually parsing and finding videos.
https://developers.google.com/youtube/android/player/
you just import the proper YouTubeVideoPlayer and things work fine.
ps.: I don't suggest using this in a ViewPager, I only had problems with that.
Google has a YouTube Android Player API that enables you to incorporate video playback functionality into your Android applications. The API itself is very easy to use and works well. For example, here is how to create a new activity to play a video using the API.
Intent intent = YouTubeStandalonePlayer.createVideoIntent(this, "<<YOUTUBE_API_KEY>>", "<<Youtube Video ID>>", 0, true, false);
startActivity(intent);
See this for more details.