fijkplayer

repository·master·Indexed 23 days ago

https://github.com/befovy/fijkplayer

A Flutter media player plugin for iOS and Android based on the ijkplayer framework. It provides high-performance video playback through the FijkPlayer Dart wrapper and FijkView UI component. The plugin supports a state-machine based playback system and is compatible with hover for Go code integration.

Tokens
7.8K
Snippets
15
Records
40
Agent score
78%

What's inside fijkplayer

  1. Overview of fijkplayer

    master

    fijkplayer is a media player plugin for the Flutter ecosystem that wraps the native ijkplayer for use in Flutter applications. It supports both Android and iOS.

    Key Features:

    • Kernel: Uses ijkplayer as the player kernel, which utilizes FFmpeg for audio/video demuxing and decoding.
    • Hardware Acceleration: Supports hardware-accelerated decoding specific to Android and iOS platforms.
    • Performance: Uses Flutter's Texture widget to bring video from the native layer to Flutter, providing better performance than PlatformView.
    • Ease of Use: Provides an easy-to-use API and includes built-in ijkplayer binaries (hosted on jcenter and CocoaPods), so you do not need to build FFmpeg or native ijkplayer yourself.
  2. How FijkPlayer and FijkView work together

    master

    FijkPlayer

    FijkPlayer is a Dart wrapper for the native C-layer ijkplayer. It handles all playback-related logic, including:

    • Checking media information in the data source.
    • Opening decoders and decoding threads.
    • Managing audio output devices.
    • Outputting decoded data to audio or display devices.

    Important: FijkPlayer consumes significant memory and system resources. You must explicitly call player.release() when the player is no longer in use to prevent resource leaks.

    FijkView

    FijkView is a UI component responsible solely for displaying the decoded video content provided by a FijkPlayer instance. It has minimal API surface, primarily focused on UI display.

  3. Understand FijkPlayer states and transitions

    master

    FijkPlayer operates using a state machine. Understanding the current state is critical for knowing which API calls are valid and when the player is ready for interaction.

    State Categories

    • Playable States: prepared, started, paused, completed. In these states, you can transition to the started state by calling start().
    • Steady States: idle, initialized, prepared, paused, completed, stopped, end, error. These states only change via explicit API calls.
    • Non-steady States: asyncPreparing, started. These states transition automatically when specific conditions are met (e.g., preparation tasks finish or playback ends).

    State Definitions

    StateDescription
    idleInitial state after construction. Minimal memory usage, no extra threads.
    initializedMedia source information is loaded, but no extra threads are open.
    asyncPreparingTransition state after calling prepareAsync(). The player is detecting file types, opening decoders, and starting threads.
    preparedPreparation is complete. Audio/video data is buffering/decoding and ready to play.
    startedMedia is actively playing.
    pausedPlayback is temporarily halted.
    completedPlayback has finished. You can restart from the beginning.
    stoppedThreads are released and the audio device is turned off.
    endAll manual memory has been released. The player awaits garbage collection.
    errorAn error occurred during playback or preparation.
  4. Run the Mac OS Desktop Example

    master

    To run the Mac OS desktop version of the fijkplayer demo, you must first download the required libIjkPlayer.dylib library and then use the hover tool to manage plugins and run the application.

    1. Download the library into the specific Darwin directory: cd fijkplayer/go/dlib/darwin and wget https://github.com/befovy/ijkplayer/releases/download/f0.4.0/libIjkPlayer.dylib
    2. Navigate to the example directory.
    3. Use hover plugins get to fetch dependencies.
    4. Use hover run to start the application.
    cd fijkplayer/go/dlib/darwin
    wget https://github.com/befovy/ijkplayer/releases/download/f0.4.0/libIjkPlayer.dylib
    
    go get -u -v github.com/go-flutter-desktop/hover
    cd fijkplayer/example
    hover plugins get
    hover run
  5. Debug and run fijkplayer on iOS

    master

    To run the app on iOS, follow these steps:

    1. Install Dependencies: Run pod install --verbose in the ios folder after changing Flutter dependencies or when creating a new Flutter app.
    2. Hardware Requirement: Due to known Flutter issues with Texture rendering, you must use a real iOS device; video playback may not work on the iOS simulator.
    3. Code Signing: Open ios/Runner.xcworkspace in Xcode and configure your certificate under Runner -> targets -> Runner -> General -> Signing.
    4. Launch: Connect your device and run the Runner target from Xcode or use flutter run in the terminal.
    pod install --verbose
  6. Verify fijkplayer installation

    master

    After adding the dependency and running flutter pub get, verify the installation by importing the package in your lib/main.dart file and attempting a build.

    1. Add the import to lib/main.dart:

      import 'package:fijkplayer/fijkplayer.dart';
    2. Run the build commands to ensure there are no compilation errors:

      • For Android: flutter build apk
      • For iOS: flutter build ios --no-codesign
    $ flutter pub get --verbose
    $ flutter build apk
    $ flutter build ios --no-codesign
  7. Customize iOS launch screen assets

    master

    To customize the launch screen for the iOS version of your Flutter project, you can either replace the image files directly in the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory or use Xcode for a more visual approach.

    Using Xcode:

    1. Open your Flutter project's iOS workspace using open ios/Runner.xcworkspace.
    2. In the Xcode Project Navigator, select Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog to replace the existing launch images.
    open ios/Runner.xcworkspace
  8. Install fijkplayer via pubspec.yaml

    master

    To install fijkplayer in your Flutter project, add it as a dependency in your pubspec.yaml file. You can use the latest stable version from pub.dev or point directly to the GitHub repository if you need unpublished features.

    Using the stable version: Replace {latest version} with the current stable version number.

    Using the GitHub repository: Use this method to access the develop branch or specific tags/branches.

    Note for Android users: fijkplayer uses the AndroidX support library. Ensure that AndroidX is enabled in your Android project settings.

    # Using stable version
    dependencies:
      fijkplayer: ^{latest version}
    
    # Using GitHub (e.g., develop branch)
    dependencies:
      fijkplayer:
        git:
          url: https://github.com/befovy/fijkplayer.git
          ref: develop
  9. Install fijkplayer

    master

    To use fijkplayer in your Flutter project, add it as a dependency in your pubspec.yaml file. You can install the latest published version from pub.dev or use a specific git branch (such as develop) for features not yet published.

    dependencies:
      fijkplayer: ^{{latest version}}

    Or via git:

    dependencies:
      fijkplayer:
        git:
          url: https://github.com/befovy/fijkplayer.git
          ref: develop # can be replaced to branch or tag name