Skip to content

Commit

Permalink
Merge pull request #388 from bitmovin/feature/add-SRT-subtitle-support
Browse files Browse the repository at this point in the history
Add SRT (SubRip) subtitle support
  • Loading branch information
rolandkakonyi authored Jan 26, 2024
2 parents f9cb566 + 6aadc78 commit eaf89f1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
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

0 comments on commit eaf89f1

Please sign in to comment.