Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get subtitles working. #54

Closed
msivers opened this issue Sep 5, 2017 · 5 comments
Closed

Can't get subtitles working. #54

msivers opened this issue Sep 5, 2017 · 5 comments

Comments

@msivers
Copy link

msivers commented Sep 5, 2017

Can't seem to get subtitles working with SimpleExoPlayer (ExoPlayerXamarin 2.5.1.2).

Using the following urls:
http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
http://html5doctor.com/demos/webvtt/subtitles.vtt

Full activity code sample:

[Activity(Label = "VideoPlayerActivity")]
public class VideoPlayerActivity : Activity
{
	private string videoUrl;
	private string captionUrl;
	private SimpleExoPlayerView videoPlayerView;
	private SimpleExoPlayer videoPlayer;

	protected override void OnCreate(Bundle savedInstanceState)
	{
		base.OnCreate(savedInstanceState);

		SetContentView(Resource.Layout.VideoPlayerLayout);

		videoPlayerView = FindViewById<SimpleExoPlayerView>(Resource.Id.VideoPlayerView);

		videoUrl = Intent.GetStringExtra("VideoUrl");
		captionUrl = Intent.GetStringExtra("CaptionUrl");

		LoadVideo(videoUrl, captionUrl);
	}

	public void LoadVideo(string videoUrl, string closedCaptionUrl = null)
	{
		var videoUri = (!string.IsNullOrWhiteSpace(videoUrl)) ? Android.Net.Uri.Parse(videoUrl) : null;
		var captionUri = (!string.IsNullOrWhiteSpace(closedCaptionUrl)) ? Android.Net.Uri.Parse(videoUrl) : null;

		Handler mainHandler = new Handler();
		var bandwidthMeter = new DefaultBandwidthMeter();
		var videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
		TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

		videoPlayer = ExoPlayerFactory.NewSimpleInstance(this, trackSelector);

		var dataSourceFactory = new DefaultDataSourceFactory(this, Util.GetUserAgent(this, "VideoPlayer"), bandwidthMeter);
		var extractorsFactory = new DefaultExtractorsFactory();
		var videoSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null);

		if (captionUri != null)
		{
			var subtitleFormat = Format.CreateTextSampleFormat(null, MimeTypes.TextVtt, C.SelectionFlagDefault, null);
			var subtitleSource = new SingleSampleMediaSource(captionUri, dataSourceFactory, subtitleFormat, C.TimeUnset);

			MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);

			videoPlayer.Prepare(mergedSource);
		}
		else
		{
			videoPlayer.Prepare(videoSource);
		}

		videoPlayer.PlayWhenReady = true;
		videoPlayerView.Player = videoPlayer;
	}
}

Only first frame of video is shown - can't play video. If I remove the subtitleSource parameter from the MergingMediaSource constructor then the video plays fine so there seems to be something wrong with the creation of the SingleSampleMediaSource instance. I've tried lots of different variations of parameters for CreateTextSampleFormat but nothing has worked so far.

Help or guidance would be greatly appreciated.

@martijn00
Copy link
Member

Is this related to google/ExoPlayer#3228? If so it would be fixed after updating to 2.5.2

@martijn00
Copy link
Member

The update is out on nuget. Can you let me know if that helps?

@msivers
Copy link
Author

msivers commented Sep 25, 2017

Hi Martjin, I've tried with version 2.5.3 and still doesn't work. Can you replicate the problem as I think this is general issue of using mp4 and vtt files?

@devmartinez0
Copy link

@msivers If you are using a VTT subtitle file you need to enable Close Captions in your Device's Settings > Accessibility > Captions (the languaje of the captions must be the same as the subtitle file).

@martijn00
Copy link
Member

Can you try 2.7.2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants