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.75k stars 6.03k forks source link

Support LRC (LyRiCs) subtitle format #3938

Open ice459pp opened 6 years ago

ice459pp commented 6 years ago

Hi, everyone, recently,

I use Exoplayer play mp4 files and attach subtitle file with .srt extension file.

And I did it.

Now, I wanna play mp3 file and attach subtitle file with .lrc extension file.

I don't have any idea to attach .lrc subtitle file.

This is the lrc definision.

I know the following code implementing side-loading subtitle and produce MediaResource, and this is for mp4 with .srt subtitle file.

MediaSource contentMediaSource =
                    buildMediaSource(Uri.parse(mediaUrl), /* handler= */ null, /* listener= */ null);

            Format format = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, Format.NO_VALUE, "en");

            Uri subtitleUri = Uri.parse(subtitleUrl);
            MediaSource subtitleMediaSource = new SingleSampleMediaSource.Factory(okHttpDataSourceFactory)
                    .createMediaSource(subtitleUri, format, C.TIME_UNSET);

            mediaSource = new MergingMediaSource(contentMediaSource, subtitleMediaSource);
player.prepare(mediaSource);

I can get subtitle change from the following code.

player.addTextOutput(listener);

The textOutput have Cue object.

The ultimately object is I wanna play mp3 music file and attach .lrc extension subtitle file, and the

lyric(TextView) can show the hover color representing the singer is singing in this lyric.

But the MimeTypes.APPLICATION_SUBRIP is not proper for implementation .lrc extension file.

Is there any thought to solve this question? Maybe it's a enhancement I think.

the mp3 file is here: a song the srt file format is: srt file the lrc file format is: lrc file

ice459pp commented 6 years ago

The only stupid way I solve is convert the .lrc extension file to .srt extention file throught this converter

ojw28 commented 6 years ago

We don't support LRC. Marking this as an enhancement, but it will be considered low priority. The most likely way in which this will be implemented is if we receive an external contribution that adds support.

szaboa commented 6 years ago

I am going to look into this, lets see if I can add support for lrc.

Artoria2e5 commented 1 year ago

LRC is a bit of an oddball since it's extremely ad hoc and you'd need to come up with a new MIME type. It is quite straightforward though and does have a lot of historical (if not current) significance in lyric storage.