google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

Subtitle language 'Und' when run on mag box #5671

Closed amiraelsayed closed 5 years ago

amiraelsayed commented 5 years ago

hello,

I am building application for IPTV and I was able to add subtitles to my tracks, and it is working with no problem on tv box, the problem only happen when I run the application on mag box, it start to show the name of subtitle as Und

can anyone please advice on this problem ?

marcbaechinger commented 5 years ago

Can you please provide us with a bit more of information of what you actually did?

The issue template which has been removed does outline what information we need to be able to help you. The issue template can be found here: https://github.com/google/ExoPlayer/blob/release-v2/.github/ISSUE_TEMPLATE/bug.md

Please describe what you did and how it can be reproduced with the content links you provide. Specifically if this happens on a given device only we need a bug report from that device which has been taken right after the problem occured.

amiraelsayed commented 5 years ago

This is my method

private MediaSource buildMediaSourceWithSubtitle(Uri uri, @Nullable String overrideExtension, ArrayList<Subtitle> subtitles) {
ArrayList<MediaSource> allSources = new ArrayList<>();

    // add list of subtitles if found
    if (subtitles != null && subtitles.size() > 0) {
        for (int i = 0; i < subtitles.size(); i++) {
            Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, C.SELECTION_FLAG_FORCED, subtitles.get(i).getName());
            allSources.add(new SingleSampleMediaSource(subtitles.get(i).getUri(), dataSourceFactory, textFormat, C.TIME_UNSET));
        }
    }

    MediaSource mediaSource = null;
    MediaSource[] allSourcesArray = null;

    @ContentType int type = Util.inferContentType(uri, overrideExtension);
    switch (type) {
        case C.TYPE_DASH:
            mediaSource = new DashMediaSource.Factory(dataSourceFactory)
                    .setManifestParser(
                            new FilteringManifestParser<>(new DashManifestParser(), getOfflineStreamKeys(uri)))
                    .createMediaSource(uri);
            allSources.add(0, mediaSource);
            allSourcesArray = allSources.toArray(new MediaSource[allSources.size()]);

            return new MergingMediaSource(allSourcesArray);
        case C.TYPE_SS:
            mediaSource = new SsMediaSource.Factory(dataSourceFactory)
                    .setManifestParser(
                            new FilteringManifestParser<>(new SsManifestParser(), getOfflineStreamKeys(uri)))
                    .createMediaSource(uri);
            allSources.add(0, mediaSource);
            allSourcesArray = allSources.toArray(new MediaSource[allSources.size()]);

            return new MergingMediaSource(allSourcesArray);
        case C.TYPE_HLS:
            mediaSource = new HlsMediaSource.Factory(dataSourceFactory)
                    .setPlaylistParserFactory(
                            new DefaultHlsPlaylistParserFactory(getOfflineStreamKeys(uri)))
                    .createMediaSource(uri);
            allSources.add(0, mediaSource);
            allSourcesArray = allSources.toArray(new MediaSource[allSources.size()]);

            return new MergingMediaSource(allSourcesArray);
        case C.TYPE_OTHER:
            mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
            allSources.add(0, mediaSource);
            allSourcesArray = allSources.toArray(new MediaSource[allSources.size()]);

            return new MergingMediaSource(allSourcesArray);
        default: {
            throw new IllegalStateException("Unsupported type: " + type);
        }
    }
}

you can see that I set the subtitle name here "subtitles.get(i).getName()" , it works pefect but on this device "MAG260" the subtitle name appear as "Und"

can you please help ?

marcbaechinger commented 5 years ago

It's hard to help given the information you provide. The code looks okay-ish.

"Und" means 'Undefined' and revers to the language of the subtitle more than being its name. I understand that displaying the subtitle works, but the language is undefined.

I wonder what is the return value of subtitles.get(i).getName() when you pass it to create the textFormat:

Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, 
  C.SELECTION_FLAG_FORCED, subtitles.get(i).getName());

Can you check what it returns and how you get that name in your Subtitle object?

If you want me to look into this some further, then please create a bugreport and attach it to this issue. Make sure you are trying this either in the demo app or while you are using an EventLogger.

amiraelsayed commented 5 years ago

my subtitle object is fine, and it is workinh perfect when I use emulator or use TV box, this problem only happen when I use the Mag

amiraelsayed commented 5 years ago

WhatsApp Image 2019-04-09 at 8 32 38 AM WhatsApp Image 2019-04-09 at 8 32 23 AM

amiraelsayed commented 5 years ago

I have download the repo of the project and tried to investigate a little bit more to try to know what is the reason of this strange problem
as you can see

the first image for smart tv box, you will see after the last ":" that the title of the subtitle is correct and that is what shown to the user

the problem is in the second image that was on MAG box, as you can see after the last ":" the title is "und" and this is wrong, it seems the object is the same in both cases

why the title is correct in Smart TV and wrong in the second one?

marcbaechinger commented 5 years ago

It seems to me that the MAG box has a problem with the language tags which are used for creating the text format.

HELLO: Format(null, null, null, application/x-subrip, null, Arabic, [-1,-1,-1.0], [-1,-1]):arabic

The part in the middle seems to be 'format.toString()' of the text format you've created. The string 'Arabic' is the language tag. I would expect this to be a three or probably two letter language tag like 'ar' or 'ara' rather than 'Arabic' (see for example https://www.loc.gov/standards/iso639-2/php/code_list.php).

When I do a format.toString() of a text track in the demo app it gives me for a german (deutsch) subtitle:

Format(8, null, audio/mp4, audio/mp4a-latm, mp4a.40.2, 128000, deu, [-1, -1, -1.0], [-1, -1])

which results in 'deu'. So my guess is that while the OS of other devices can handle 'Arabic', the MAG box can't (like new Locale('ara').getDisplayLanguage() vs. new Locale('Arabic').getDisplayLanguage()) or the user language of the two devices is configured differently. The fix would be to use 'ara' to create the text track format.

You can try to create your text tracks so that you have subtitles.get(i).getLanguageCode() instead of subtitles.get(i).getName() like the following:

Format textFormat = 
    Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP,
             C.SELECTION_FLAG_FORCED, subtitles.get(i).getLanguageCode());

Or alternatively as a quick test change your data so that subtitles.get(i).getName() returns 'ara' instead of 'Arabic'?

marcbaechinger commented 5 years ago

Closing due to inactivity.