dsc-uob / subtitle

Subtitle decoder package, enables you to handle translation data smoothly.
MIT License
6 stars 17 forks source link

Downloading subtitles from the Internet does not work #1

Closed kpk-i710 closed 1 year ago

kpk-i710 commented 3 years ago

When I do the load from the line, everything works, it does not download from the Internet at all.

var url = Uri.parse( 'https://brenopolanski.github.io/html5-video-webvtt-example/MIB2-subtitles-pt-BR.vtt'); var controller = SubtitleController( provider: SubtitleProvider.fromNetwork(url), ); await controller.initial();

I did everything as in the instructions

MuhmdHsn313 commented 3 years ago

Please try to write your own NetworkSubtitleProvider using like this code while I'm fixing the problem!:

/// ## Network subtitles
/// A class that deals with subtitle files from the **Internet**, you can provide a download
/// link of subtitle in the constructor function for the purpose of completing its processing.
/// You can call it by [NetworkSubtitleProvider].
///
/// ```dart
///
///   // Using  [NetworkSubtitle] class.
///   NetworkSubtitleProvider netSub = new NetworkSubtitleProvider(Uri.parse('<YOUR SUBTITLE PATH URL>'));
///
/// ```
class NetworkSubtitleProvider extends SubtitleProvider {
  /// The url of subtitle file on the internet.
  final Uri url;
  final SubtitleType? type;

  const NetworkSubtitle(
    this.url, {
    this.type,
  });

  // Replace this method with your code to return a `SubtitleObject`.
  @override
  Future<SubtitleObject> getSubtitle() async {
    // Preparing subtitle file data.
    final _repository = SubtitleRepository.inctance;
    final data = await _repository.fetchFromNetwork(url);

    // Find the current format type of subtitle.
    final ext = fileExtension(url.path);
    final type = this.type ?? getSubtitleType(ext);

    return SubtitleObject(data: data, type: type);
  }
}
MuhmdHsn313 commented 1 year ago

Solved in #8