banana_player 0.0.1
banana_player: ^0.0.1 copied to clipboard
A high-performance video player for Flutter using ExoPlayer (Media3) on Android and AVPlayer on iOS with HLS, custom seekbars, and quality selection.
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.
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.
- ποΈ 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.25xto2.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, and quality 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 |
Installation #
Add banana_player to your pubspec.yaml:
dependencies:
banana_player: ^0.0.1
Or run:
flutter pub add banana_player
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 insecure http:// streams, enable cleartext traffic in your application manifest:
<application
android:usesCleartextTraffic="true"
...>
</application>
iOS Configuration #
Ensure your iOS deployment target is 15.0 or higher in ios/Podfile:
platform :ios, '15.0'
If loading insecure http:// streams, configure App Transport Security in ios/Runner/Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Quick Start #
import 'package:flutter/material.dart';
import 'package:banana_player/banana_player.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(
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. Quality Selection (HLS / Multi-bitrate) #
// Inspect available video streams
final List<VideoQuality> qualities = _controller.videoQualities;
for (final quality in qualities) {
print('${quality.label} - ${quality.width}x${quality.height} @ ${quality.bitrate} bps');
}
// Switch to a specific resolution (e.g. '1080p') or back to auto ABR
_controller.setVideoQuality('auto');
2. 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 and allocates the texture. |
play() / pause() |
Controls playback state. |
seekTo(Duration position) |
Seeks native player to target duration. |
setPlaybackSpeed(double speed) |
Sets playback speed (e.g., 0.5, 1.0, 1.5, 2.0). |
setVideoQuality(String qualityId) |
Switches video stream quality track. |
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. |
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.