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

Add SRT (SubRip) subtitle support #388

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Support for side-loaded SRT (SubRip) subtitles

### Fixed

- Remove `patch-package` usage from released product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,11 @@ fun ReadableMap.toSubtitleTrack(): SubtitleTrack? {
/**
* Converts any subtitle format name in its mime type representation.
*/
private fun String.toSubtitleMimeType(): String = "text/$this"
private fun String.toSubtitleMimeType(): String = when (this) {
"srt" -> "application/x-subrip"
"ttml" -> "application/ttml+xml"
else -> "text/$this"
}

/**
* Converts any `SubtitleTrack` into its json representation.
Expand Down
11 changes: 9 additions & 2 deletions example/src/screens/SubtitlePlayback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ export default function SubtitlePlayback() {
poster: 'https://bitmovin-a.akamaihd.net/content/sintel/poster.png',
// External subtitle tracks to be added to the source.
subtitleTracks: [
// Add custom english subtitles. You can select 'Custom English' in the subtitles menu.
// Add custom english subtitles. You can select 'Custom English (WebVTT)' in the subtitles menu.
{
url: 'https://bitdash-a.akamaihd.net/content/sintel/subtitles/subtitles_en.vtt',
label: 'Custom English',
label: 'Custom English (WebVTT)',
language: 'en',
format: SubtitleFormat.VTT,
},
// Add custom english subtitles. You can select 'Custom English (SRT)' in the subtitles menu.
{
url: 'https://bitdash-a.akamaihd.net/content/sintel/subtitles/subtitles_en.srt',
label: 'Custom English (SRT)',
language: 'en',
format: SubtitleFormat.SRT,
},
],
});
return () => {
Expand Down
4 changes: 4 additions & 0 deletions ios/RCTConvert+BitmovinPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ extension RCTConvert {
return .webVtt
case "ttml":
return .ttml
case "srt":
return .srt
default:
return nil
}
Expand Down Expand Up @@ -582,6 +584,8 @@ extension RCTConvert {
return "vtt"
case .ttml:
return "ttml"
case .srt:
return "srt"
}
}(),
]
Expand Down
20 changes: 19 additions & 1 deletion src/subtitleTrack.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
/**
* Supported subtitle/caption file formats.
* @platform Android, iOS, tvOS
*/
export enum SubtitleFormat {
/**
* Closed Captioning (CEA) subtitle format.
* @platform Android, iOS, tvOS
*/
CEA = 'cea',
/**
* Timed Text Markup Language (TTML) subtitle format.
* @platform Android, iOS, tvOS
*/
TTML = 'ttml',
/**
* Web Video Text Tracks Format (WebVTT) subtitle format.
* @platform Android, iOS, tvOS
*/
VTT = 'vtt',
/**
* SubRip (SRT) subtitle format.
* @platform Android, iOS, tvOS
*/
SRT = 'srt',
}

/**
* Describes a subtitle track.
* @platform Android, iOS, tvOS
*/
export interface SubtitleTrack {
/**
Expand Down Expand Up @@ -47,7 +66,6 @@ export interface SubtitleTrack {

/**
* A subtitle track that can be added to `SourceConfig.subtitleTracks`.
*
*/
export interface SideLoadedSubtitleTrack extends SubtitleTrack {
url: string;
Expand Down
Loading