Banana Player ๐ŸŒ

A high-performance, cross-platform video player plugin for Flutter. Powered natively by AndroidX Media3 (ExoPlayer) on Android and AVPlayer on iOS, rendered directly into Flutter via hardware-accelerated Texture widgets.

pub package License: MIT GitHub


Features

  • ๐Ÿš€ Native Texture Rendering: Direct GPU-to-GPU surface texture renderingโ€”no expensive platform view hierarchy overlay.
  • ๐Ÿ“ฑ Dual Engine Support:
    • Android: AndroidX Media3 / ExoPlayer with HLS and DASH extensions.
    • iOS: Native AVPlayer with HLS stream support.
  • ๐Ÿ’ฌ Closed Captions & Subtitles: Query multi-language embedded subtitle tracks, select tracks or disable ('off'), and render crisp reactive subtitle overlays natively in Flutter with custom typography and decorations.
  • ๐ŸŽš๏ธ Adaptive Bitrate & Quality Selection: Read video track resolutions, bitrates, and frame rates on the fly; switch tracks manually or let ABR adapt automatically.
  • โฉ Variable Playback Speed: Smooth rate switching from 0.25x to 4.0x.
  • ๐ŸŽฏ BananaSeekBar Widget:
    • Dual-track progress bar (active playback + buffered range).
    • Scrubbing preview tooltip (scrubTooltipBuilder).
    • Direct widget slot overrides for custom thumbs, tracks, leading, and trailing badges.
  • ๐Ÿ“ก Event-Driven Architecture: Listen to state, position, buffer, quality, and subtitle changes via streams or ChangeNotifier.

Platform Support

Platform Minimum Version Native Backend
Android API 24 (Android 7.0+) AndroidX Media3 / ExoPlayer 1.5.1
iOS iOS 15.0+ AVPlayer / AVFoundation

For comprehensive details on build targets, JVM targets, Gradle Version Catalogs, and Media3 capabilities, consult the Compatibility Matrix.

Platform Quality & Subtitle Behavior Notes:

  • On Android, video qualities and subtitle tracks are selected deterministically via Media3 track selection overrides (TrackSelectionOverride).
  • On iOS, adaptive bitrate quality selection operates via AVPlayerItem.preferredPeakBitRate and preferredMaximumResolution for HLS variant streams, while subtitles leverage native AVMediaSelectionGroup selections. Setting quality to 'auto' clears bitrate and resolution caps on both platforms.

Installation

Add banana_player to your pubspec.yaml:

dependencies:
  banana_player: ^0.0.7

Or run:

flutter pub add banana_player

Design System Note: banana_player is style-neutral and depends only on core Flutter widgets (package:flutter/widgets.dart). If your application UI uses Material widgets (Scaffold, CircularProgressIndicator, etc.) on Flutter 3.50+, remember to add material_ui: ^1.0.0 (flutter pub add material_ui) or continue using package:flutter/material.dart on earlier Flutter versions.

Android Configuration

Ensure your android/app/build.gradle.kts has a minSdk of 24 or higher:

android {
    defaultConfig {
        minSdk = 24
    }
}

Internet permission is automatically included by the plugin's manifest. If loading specific insecure http:// streams during development or for specific local servers, prefer configuring a targeted network_security_config.xml with specific domain exceptions rather than globally allowing cleartext traffic:

<!-- In res/xml/network_security_config.xml -->
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">example.com</domain>
    </domain-config>
</network-security-config>
<application
    android:networkSecurityConfig="@xml/network_security_config"
    ...>
</application>

iOS Configuration

Ensure your iOS deployment target is 15.0 or higher in ios/Podfile:

platform :ios, '15.0'

If loading specific insecure http:// streams, configure targeted App Transport Security domain exceptions in ios/Runner/Info.plist instead of globally permitting arbitrary loads:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

Quick Start

import 'package:banana_player/banana_player.dart';
import 'package:flutter/material.dart';
// Note: On Flutter 3.50+, if your app uses the standalone Material package,
// add `material_ui: ^1.0.0` to your pubspec.yaml and import:
// import 'package:material_ui/material_ui.dart';

class VideoScreen extends StatefulWidget {
  const VideoScreen({super.key});

  @override
  State<VideoScreen> createState() => _VideoScreenState();
}

class _VideoScreenState extends State<VideoScreen> {
  final BananaPlayerController _controller = BananaPlayerController();

  @override
  void initState() {
    super.initState();
    _controller.initialize(
      url: 'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4',
      autoPlay: true,
      volume: 1.0,
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Center(
        // Wrap with AspectRatio matching your video content (e.g. 16:9, 4:3, or 9:16)
        child: AspectRatio(
          aspectRatio: 16 / 9,
          child: Stack(
            alignment: Alignment.bottomCenter,
            children: [
              // 1. Video surface
              BananaPlayerView(
                controller: _controller,
                placeholder: const Center(
                  child: CircularProgressIndicator(),
                ),
              ),

              // 2. Seek bar
              Positioned(
                left: 16,
                right: 16,
                bottom: 12,
                child: BananaSeekBar(
                  controller: _controller,
                  activeTrackColor: Colors.amber,
                  thumbColor: Colors.amberAccent,
                  showTimeLabels: true,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Advanced Usage

1. Local Files & Bundled Assets

Play local device files or packaged Flutter assets directly:

// 1. Play from local device file (downloaded / recorded)
final File videoFile = File('/path/to/video.mp4');
await _controller.initializeFile(videoFile);

// 2. Play from bundled Flutter asset
await _controller.initializeAsset('assets/videos/intro.mp4');

// 3. Or use initialize with automatic path resolution
await _controller.initialize(url: '/storage/emulated/0/Download/movie.mp4');
await _controller.initialize(url: 'assets/videos/intro.mp4');

2. Quality Selection (HLS / Multi-bitrate)

// Inspect available video streams
final List<VideoQuality> qualities = _controller.videoQualities;

for (final quality in qualities) {
  print('${quality.label} (ID: ${quality.id}) - ${quality.width}x${quality.height} @ ${quality.bitrate} bps');
}

// Switch to a specific resolution by its track ID (e.g. qualities.first.id or '0_0')
if (qualities.isNotEmpty) {
  final targetQuality = qualities.firstWhere(
    (q) => q.id != 'auto',
    orElse: () => qualities.first,
  );
  await _controller.setVideoQuality(targetQuality.id);
}

// Or restore automatic adaptive bitrate streaming
await _controller.setVideoQuality('auto');

3. Closed Captions & Subtitles

BananaPlayer automatically discovers embedded subtitle tracks (e.g. HLS WebVTT, CEA-608/708) and renders reactive subtitle overlays directly in Flutter with zero platform view overhead:

// Inspect available subtitle tracks
final List<SubtitleTrack> tracks = _controller.subtitleTracks;

for (final track in tracks) {
  print('${track.label} (${track.language}) - selected: ${track.isSelected}');
}

// Select a specific subtitle track by id or language
if (tracks.isNotEmpty) {
  await _controller.setSubtitleTrack(tracks.first.id);
}

// Disable subtitles
await _controller.disableSubtitles();

// Listen to real-time subtitle text cues
_controller.onSubtitleTextChanged.listen((text) {
  print('Active cue: $text');
});

Customize the subtitle overlay in BananaPlayerView:

BananaPlayerView(
  controller: _controller,
  showSubtitles: true,
  subtitleTextStyle: const TextStyle(
    fontSize: 16,
    color: Colors.amber,
    fontWeight: FontWeight.bold,
  ),
  subtitleDecoration: BoxDecoration(
    color: const Color(0xBF000000),
    borderRadius: BorderRadius.circular(6),
  ),
)

4. Custom Seek Bar Overrides

BananaSeekBar supports complete custom widget replacement for thumbs, badges, and scrub tooltips:

BananaSeekBar(
  controller: _controller,
  activeTrackColor: Colors.amber,
  bufferedTrackColor: Colors.white24,
  showTimeLabels: false,
  // Custom thumb widget
  customThumb: Container(
    width: 20,
    height: 20,
    decoration: const BoxDecoration(
      color: Colors.amber,
      shape: BoxShape.circle,
    ),
    child: const Icon(Icons.play_arrow, size: 12, color: Colors.black),
  ),
  // Custom floating scrub tooltip
  scrubTooltipBuilder: (context, scrubPosition) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
      decoration: BoxDecoration(
        color: Colors.black87,
        borderRadius: BorderRadius.circular(4),
      ),
      child: Text(
        '${scrubPosition.inMinutes}:${(scrubPosition.inSeconds % 60).toString().padLeft(2, '0')}',
        style: const TextStyle(color: Colors.white, fontSize: 12),
      ),
    );
  },
)

API Reference

BananaPlayerController

Property / Method Description
initialize({required String url, bool autoPlay, double volume}) Creates the native player instance (network stream, local file, or asset).
initializeFile(File file, {bool autoPlay, double volume}) Initializes playback from a local device File.
initializeAsset(String assetPath, {bool autoPlay, double volume, String? package}) Initializes playback from a bundled Flutter asset.
setSource(String url) Changes the media source URL without destroying the surface or decoder.
setSourceFile(File file) Changes the media source to a local device File.
setSourceAsset(String assetPath, {String? package}) Changes the media source to a bundled Flutter asset.
play() / pause() Controls playback state.
seekTo(Duration position) Seeks native player to target duration.
setPlaybackSpeed(double speed) Sets playback speed (clamped between 0.25x and 4.0x).
setVideoQuality(String qualityId) Switches video stream quality track.
getSubtitleTracks() Fetches available closed captions / subtitle tracks.
setSubtitleTrack(String trackId) Selects a subtitle track by ID, or 'off' to disable.
disableSubtitles() Turns off closed captions.
subtitleTracks List of available SubtitleTrack options.
selectedSubtitleTrack Currently active SubtitleTrack or null.
isSubtitlesEnabled Whether closed captions are currently enabled.
currentSubtitleText Current text cue displayed on the screen.
setVolume(double volume) Sets output audio volume (0.0 to 1.0).
playbackState Current PlaybackState (idle, buffering, ready, ended, paused).
videoQualities List of available VideoQuality tracks.
position / duration / bufferedPosition Duration metrics.
dispose() Releases native player and texture resources.

BananaPlayerView

Property Description
controller The BananaPlayerController driving this view.
placeholder Widget shown while the player is uninitialized.
filterQuality Texture filter quality (low, medium, high).
showSubtitles Whether to render the closed caption overlay (default: true).
subtitleTextStyle Custom TextStyle for subtitle cues.
subtitleDecoration Custom Decoration for subtitle text container.
subtitlePadding Outer padding around subtitle container within the video surface.
subtitleAlignment Alignment of subtitles on the surface (default: bottomCenter).
subtitleBuilder Custom builder for rendering subtitle cues.

Author

Created and maintained by Keval Thakkar (thakkarkpt123@gmail.com โ€ข GitHub).


License

This project is licensed under the MIT License โ€” see the LICENSE file for details.

Libraries

banana_player
A high-performance Flutter video player plugin powered by ExoPlayer (Media3) on Android and AVPlayer on iOS with Pigeon IPC, custom seekbars, and quality selection.