I'm attempting to use the MediaItem class to load videos and show subtitles on the exoplayer2 CastPlayer. I'm able to see subtitles on the phone before casting and the video plays fine when cast to a TV using application/dash+xml format. However, I'm not able to figure out how to get subtitles to appear on the TV. I have added the MediaItem.Subtitle using MediaItem.Builder().setSubtitles(subtitleList). Previously I was able to do so with the deprecated MediaInfo class. I can't see any methods in the CastPlayer class to turn them on or how to customize the PlayerControlView to add a subtitle/caption button. Any ideas are greatly appreciated.
List<MediaItem.Subtitle> subtitleList = new ArrayList<>();
MediaItem.Subtitle externalSubtitle = new MediaItem.Subtitle(Uri.parse(url), MimeTypes.TEXT_VTT,"en", C.SELECTION_FLAG_DEFAULT, C.ROLE_FLAG_SUBTITLE, "ENGLISH-EXTERNAL");
subtitleList.add(externalSubtitle);
MediaItem mediaItem = new MediaItem.Builder()
.setUri(url)
.setMediaMetadata(mediaMetadata)
.setMimeType(mimeType)
.setSubtitles(subtitleList)
.build();
castPlayer.setMediaItem(mMediaItem);
Related
I am using following test stream to render mpd in android exoplayer
https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd
following is my exoplayer code:
val adaptiveTrackSelection = AdaptiveTrackSelection.Factory()
val trackSelector: TrackSelector = DefaultTrackSelector(mContext!!, adaptiveTrackSelection)
mConcatenatingMediaSource = ConcatenatingMediaSource()
val mediaItem = MediaItem.Builder().setUri(url).setMimeType(MimeTypes.APPLICATION_MPD)
.build()
val dashMediaSource = DashMediaSource.Factory(DefaultDataSourceFactory(mContext!!, mContext!!.packageName))
.createMediaSource(mediaItem)
mConcatenatingMediaSource.addMediaSource(dashMediaSource)
exoPlayer = SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).build()
.also { exoPlayer ->
exoPlayer.playWhenReady = true
exoPlayer.addMediaSource(mConcatenatingMediaSource as MediaSource)
playerView!!.player = exoPlayer
exoPlayer.prepare()
attachEventListener(exoPlayer)
}
I am getting player state STATE_READY, I am getting position update for each second and finally player state STATE_ENDED as well, but on screen it is always a blank screen. I am testing on samsung device with os android 12.
Can anyone please help me solve this issue.
The link you have shared is to a DRM protected video stream and the behaviour you are seeing is consistent with the player not displaying encrypted content.
If you just want to test ExoPlayer in general then you can simple choose a different stream which is not DRM protected.
If you do want to test this particular stream then you will need to set up the DRM information in ExoPLayer.
The ExoPlayer documentation provides guidance on this including the example below (https://exoplayer.dev/drm.html):
MediaItem mediaItem = new MediaItem.Builder()
.setUri(videoUri)
.setDrmConfiguration(
new MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID)
.setLicenseUri(licenseUri)
.setMultiSession(true)
.setLicenseRequestHeaders(httpRequestHeaders)
.build())
.build();
This is for Widevine which is the default DRM on Android and which your stream supports. You can see this by looking in the manifest you linked to and you will see the Widevine UUID listed in a Content protection element.
ContentProtection schemeIdUri="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
As an FYI, the full list of DRM UUID's is here: https://dashif.org/identifiers/content_protection/
I am trying to integrate subtitles into videos using Exoplayer. Currently only .srt subtitle files are working with MIMETypes.APPLICATION_SUBRIP. How do I make it work for .smi subtitle files.
MediaItem.SubtitleConfiguration subtitleConfiguration = new MediaItem.SubtitleConfiguration.Builder(Uri.parse(subTitlePath))
.setMimeType(MimeTypes.APPLICATION_SUBRIP)//mime type
.setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
.build();
MediaItem mediaItem=new MediaItem.Builder()
.setUri(Uri.parse(videoUri))
.setSubtitleConfigurations(ImmutableList.of(subtitleConfiguration))
.build();
According to below thread (issue in github),
Ref : https://github.com/google/ExoPlayer/issues/5869
The answer is that it is not possible to play that with the ExoPlayer at the moment, because we don't have a decoder for SAMI subtitles.
But in the future may we have the decoder and more support from ExoPlayer.
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
I already searched but I couldn't find any solution to my problem.
I play a video source like this:
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getActivity(), Util.getUserAgent(getActivity(), "UA")));
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(source));
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.prepare(videoSource);
This "source" may have a subtitle track (embedded, if there's one it's already in the video and I don't want to import a srt file), how do I detect if there's a subtitle track, get a list of them and show the subtitles at the bottom of the video?
Also, how do I personalize them? I would like to have the white on a black background.
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);