How blairbai/fijkplayer works
Project Type and Purpose
• This is a cross‑platform Flutter plugin (“fijkplayer”) that exposes a video/media player API to Dart apps.
• It bundles native implementations on Android (Java), iOS (Objective‑C), and desktop (Go via Hover), all under a single Dart API.
• The “example” and “test” folders demonstrate integration and validate functionality; “docs” is a Jekyll‐powered documentation website.
High‑Level Architecture Overview
• A layered architecture with four main layers:
1. Flutter App Layer (e.g. example/)
2. Dart Plugin Layer (lib/)
3. Platform Channel / Plugin Registration Layer
4. Native Engine Layer (Android, iOS, Go)
Main Components
A. Flutter Application
• Example Flutter app using fijkplayer API (example/lib, example/android, example/ios, example/macos)
B. Dart Plugin API
• lib/fijkplayer.dart: High‑level FijkPlayer class
• lib/core/*: core Dart classes (FijkOption, FijkValue, FijkView, etc.)
• lib/ui/*: built‑in UI components (slider, panel, volume)
C. Platform Channel / Plugin Registry
• Generated by Flutter tooling at build time.
• On Android: FijkPlugin.java registers channels and routes Dart method calls.
• On iOS: FijkPlugin.{h,m} registers with Flutter engine and handles channels.
• On Desktop via Go: import.go.tmpl and plugin.go create a similar channel bridge.
D. Native Engine Wrappers
• Android (android/src/main/java/com/befovy/fijkplayer)
• FijkEngine.java: JNI interface to native ijkplayer
• FileMediaDataSource, RawMediaDataSource: data source handlers
• QueuingEventSink: event streaming into Dart
• iOS (ios/Classes)
• FijkPlugin, FijkPlayer, FijkHostOption, FijkQueuingEventSink: Objective‑C wrappers around ijkmediaframework
• Go (go/*.go + go/native-ijk.go)
• go-player.go, plugin.go, queue-sink.go: Go wrappers binding to ijkplayer via cgo
E. Third‑Party Engine
• ijkplayer (C/FFmpeg‑based) – compiled separately and linked into each native target.
Relationships and Data Flows
1. Dart UI code invokes methods on FijkPlayer (lib/core/fijkplayer.dart).
2. FijkPlayer uses MethodChannel to send “setDataSource”, “play”, “pause”, etc., to platform.
3. Platform registry (FijkPlugin) receives calls, delegates to native wrapper (FijkEngine on Android, Obj‑C class on iOS, Go code on desktop).
4. Native wrapper calls into ijkplayer C library to control playback.
5. Playback events (onPrepared, onProgress, onError) are dispatched back through QueuingEventSink to Dart via EventChannel.
6. Dart side emits events that update UI (FijkView) or notify the application.
Architectural Patterns and Principles
• Layered Separation: UI → Dart API → Platform Bridge → Native Engine
• Adapter/Facade: FijkEngine, FijkPlayer, and Go wrappers present a uniform API over C library.
• Event‑driven: EventChannel/QueuingEventSink decouple native callbacks from Dart listeners.
• Cross‑platform plugin pattern: platform channels and plugin registrars enable code reuse across mobile/desktop.