flutter_ass_player

Cross-platform Flutter video player with native libass rendering and a bundled JASSUB WebAssembly renderer for Advanced SubStation Alpha (.ass) subtitles.

Platform Video ASS renderer
Android, iOS, Linux, macOS, Windows media_kit Native libass
Web media_kit JASSUB/libass WebAssembly

Installation

Add the package to your application:

dependencies:
  flutter_ass_player: ^0.1.0

The package depends on media_kit and includes its video libraries. Follow the platform setup in the media_kit installation guide when your target requires additional configuration.

Basic usage

import 'package:flutter_ass_player/flutter_ass_player.dart';

final controller = AssPlayerController();

AssVideoPlayer(
  source: 'https://example.com/video.mp4',
  assContent: assDocument,
  controller: controller,
  configuration: const AssPlayerConfiguration(
    autoPlay: true,
    webFontAssets: <String>[
      'assets/fonts/NotoSans-Regular.ttf',
    ],
  ),
);

The assContent value must be a complete ASS document, not a file path. It can be replaced while the player is active:

await controller.setAssContent(updatedAssDocument);
await controller.seek(const Duration(seconds: 5));
await controller.playRange(
  const Duration(seconds: 5),
  const Duration(seconds: 10),
);

Dispose a controller created by your application when it is no longer needed. Controllers created internally by AssVideoPlayer are disposed automatically.

Fonts

Declare every custom font used by an ASS document in the host application's pubspec.yaml:

flutter:
  assets:
    - assets/fonts/NotoSans-Regular.ttf

Pass those paths through webFontAssets for web rendering. On Android, libass cannot discover system fonts, so also set the TTF asset and its actual family name:

const AssPlayerConfiguration(
  nativeFontAsset: 'assets/fonts/NotoSans-Regular.ttf',
  nativeFontFamily: 'Noto Sans',
  webFontAssets: <String>['assets/fonts/NotoSans-Regular.ttf'],
);

nativeFontAsset and nativeFontFamily must either both be set or both be omitted.

Web deployment

The bundled renderer works without cross-origin isolation. To enable browser features that use shared memory and multiple threads, send these response headers for the application and its assets:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

Remote videos and fonts must permit access from the application's origin.

Licensing

Original package code is available under the MIT License. The web runtime redistributes JASSUB 1.7.17 and its dependencies under their respective licenses. See third-party notices before distributing an application containing the web assets.

Libraries

flutter_ass_player
Cross-platform video playback with Advanced SubStation Alpha subtitles.