subtitlesFromFile static method
- {required File file,
- required SubtitleItemType type,
- String? source,
- String? metadata,
- int? index}
Fetches a subtitle from a subtitle file.
Implementation
static Future<SubtitleItem> subtitlesFromFile({
required File file,
required SubtitleItemType type,
String? source,
String? metadata,
int? index,
}) async {
String fileExtension = path.extension(file.path).toLowerCase();
if (!file.existsSync()) {
return SubtitleItem(
controller: SubtitleController(
provider: SubtitleProvider.fromFile(
file,
),
),
metadata: metadata,
source: source,
type: type,
index: index,
);
}
switch (fileExtension) {
case '.srt':
return SubtitleItem(
controller: SubtitleController(
provider: SubtitleProvider.fromString(
data: file.readAsStringSync(),
type: SubtitleType.srt,
),
),
metadata: metadata,
type: type,
index: index,
);
case '.ass':
case '.ssa':
return SubtitleItem(
controller: SubtitleController(
provider: SubtitleProvider.fromString(
data: await convertAssSubtitles(file.path),
type: SubtitleType.srt,
),
),
metadata: metadata,
type: type,
index: index,
);
}
return SubtitleItem(
controller: SubtitleController(
provider: SubtitleProvider.fromFile(
file,
),
),
metadata: metadata,
type: type,
index: index,
);
}