Baseflow / ExoPlayerXamarin

Xamarin bindings library for the Google ExoPlayer library
https://baseflow.com
MIT License
153 stars 66 forks source link

Showing subtitle on Exoplayer (Leanback) #151

Closed isaranghi closed 1 year ago

isaranghi commented 1 year ago

💬 Questions and Help

Hello,

Previously I was using Xam.Plugins.Android.ExoPlayer.Leanback version 2.11.8. I was able to load the subtitles using the following code

` var subtitleView = RequireActivity().FindViewById(Resource.Id.leanback_subtitles) as SubtitleView;

    var style = new CaptionStyleCompat(
        Color.White,
        Color.Transparent,
        Color.Transparent,
        CaptionStyleCompat.EdgeTypeDropShadow,
        Color.Black,
        Typeface.Default!);

    var subtitleSize = GlobalSettings.GetFloat(GlobalSettings.KeySubtitleSize);

    if (subtitleSize != null)
    {
        subtitleView?.SetFixedTextSize((int)ComplexUnitType.Sp, subtitleSize.Value);
    }

    subtitleView?.SetApplyEmbeddedStyles(false);
    subtitleView?.SetStyle(style);

    if (subtitleView != null)
    {
        var textComponent = _player.TextComponent;
        textComponent.AddTextOutput(subtitleView);
    }

`

Now after upgrading to version 2.18.9 I am not able to call textComponent.AddTextOutput(subtitleView); Seems like AddTextOutput function isn't available anymore. Can anyone please help how can I make subtitles work.

Thanks

isaranghi commented 1 year ago

Based on some of the online samples, subtitleView.SetCues(cueGroup.cues) should do the trick. But I can't seem to find cues property on CueGroup class. Is it sometjing that's missed?

ArchangelWTF commented 1 year ago

2.11.8 seems very outdated considering we're on 2.18.* now, think you could update to 2.18 for MAUI or XF? (2.18-xamarin)

Edit: Ah I didn't read the bottom part of the issue

It could be possible that it was removed due to some other part of ExoPlayer being removed in bindings, it certainly looks like it wasn't deprecated by Google.

ArchangelWTF commented 1 year ago

I've had a look at CueGroup and it seems that everything needed is there, I think you pass a list to CueGroup of your Cues and you should get a CueGroup back which you then pass to SetCues

Java: Screenshot 2023-02-09 130822

C# Bindings: Screenshot 2023-02-09 130748

isaranghi commented 1 year ago

Thank you very much for your response but I don't think this issue is closed. Based on the similar answer for ExoPlayer (https://github.com/google/ExoPlayer/issues/9805), you can see that I should be able to do the following...

public void OnCues(CueGroup cueGroup) { _subtitleView.SetCues(cueGroup.Cues); }

But there is no property cue available. I think that CueGroup should publicaly expose a List. SubtitleView.SetCue takes List as parameter and not the CueGroup

image

isaranghi commented 1 year ago

@martijn00 I think we should re-open this issue.. You can see that C# biniding for CueGroup class has public property List missing

ArchangelWTF commented 1 year ago

@isaranghi Since you did not provide a full sample, could you compile https://github.com/ArchangelWTF/ExoPlayerXamarin/tree/cues_fix this and see if Cues() will work for you?

ArchangelWTF commented 1 year ago

@isaranghi Did you manage to get this working yet?

isaranghi commented 1 year ago

@ArchangelWTF yes it worked with the List exposed and setting it by calling subtitleView.SetCues. Would you be able to merge your changes and update the nuget package?