搜尋套件、儲存庫與 APP 分類

GitHub 儲存庫Ajitcool008/native_audio_trimmer

native_audio_trimmer

Ajitcool008/native_audio_trimmer open-source repository details.

native_audio_trimmer 專案封面
星標
1
分支
0
最近推送(UTC)
2025年5月26日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

native_audio_trimmer

A Flutter plugin for trimming audio files on both Android and iOS platforms without using FFmpeg. This native audio editor provides powerful audio manipulation capabilities, perfect for Flutter audio trimming in apps, podcast trimming, and voice note editing.

Features

  • Trim audio files by specifying start and end times
  • Native implementation for iOS (using AVAssetExportSession)
  • Native implementation for Android (using MediaExtractor, MediaCodec, and MediaMuxer)
  • No FFmpeg dependency, resulting in smaller app size and faster builds
  • Support for multiple audio formats

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  native_audio_trimmer: ^1.0.0
Android

Add the storage permissions to your AndroidManifest.xml if you're targeting Android 12 or below and need to access files outside of your app's directory:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

For Android 13+ (API level 33+), you may need to request more specific permissions depending on your use case:

<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
iOS

No additional setup is required for iOS.

Usage

import 'package:native_audio_trimmer/native_audio_trimmer.dart';

// Create an instance of AudioTrimmer
final audioTrimmer = AudioTrimmer();

// Trim an audio file
try {
  String inputPath = '/path/to/input.mp3';
  String outputPath = '/path/to/output.m4a';
  
  // Trim from 10 seconds to 30 seconds
      // Trim audio
      final trimmedFilePath = await NativeAudioTrimmer.trimAudio(
        inputPath: inputPath,
        outputPath: outputPath,
        startTimeInSeconds: 10.0, // Start time in seconds,
        endTimeInSeconds: 30.0, // End time in seconds,
      );
  
  print('Trimmed audio saved at: $trimmedFilePath');
} catch (e) {
  print('Error trimming audio: $e');
}

Example

Check out the example app in the example folder to see a complete implementation of audio file selection, trimming, and playback.

To run the example app:

cd example
flutter run

Implementation Details

iOS

On iOS, this plugin uses the native AVAssetExportSession to perform audio trimming operations. The resulting audio file is saved in the .m4a format.

Android

On Android, the plugin uses a combination of MediaExtractor, MediaCodec, and MediaMuxer to extract, process, and save the audio data between the specified start and end times.

Supported Formats

Input Formats
  • MP3
  • M4A/AAC
  • WAV
  • OGG (Android only)
  • FLAC
Output Format
  • M4A (AAC) for both platforms

Limitations

  • The plugin currently only outputs to M4A format
  • Very large audio files may require additional memory
  • Some exotic audio formats might not be supported by the native APIs

Contributing

Contributions are welcome! If you find a bug or want a feature, please open an issue on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Ajit Sharma GitHub avatar
GitHub 作者

Ajit Sharma ↗

Expertise in Flutter

語言C++CMakeKotlinDartSwiftRubyCHTMLObjective-C

此儲存庫發佈的套件

使用的依賴

依賴清單 3 項

  • flutter{"sdk":"flutter"}
  • flutter_test開發依賴{"sdk":"flutter"}
  • flutter_lints開發依賴^2.0.0

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗