Skip to content

Commit

Permalink
Merge branch 'volskaya-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed May 16, 2023
2 parents de3e635 + 68208c2 commit 8f7de5a
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 48 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.5

* Fix timing of progress completion events (@volskaya).
* Update minimum flutter version to 3.0.
* Update AGP to 7.3.0.

## 0.0.4

* Allow extracting multiple files simultaneously (@AlexSmirnov9107).
Expand Down
12 changes: 10 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
prefer_single_quotes: false
unawaited_futures: false
8 changes: 6 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.3.0'
}
}

Expand All @@ -22,7 +22,11 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 31
// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
namespace 'com.ryanheise.just_waveform'
}
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
import androidx.annotation.NonNull;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import android.os.Handler;
import android.os.Looper;
import java.util.List;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import java.util.HashMap;

/** JustWaveformPlugin */
public class JustWaveformPlugin implements FlutterPlugin, MethodCallHandler {
private MethodChannel channel;
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "com.ryanheise.just_waveform");
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
BinaryMessenger messenger = binding.getBinaryMessenger();
channel = new MethodChannel(messenger, "com.ryanheise.just_waveform");
channel.setMethodCallHandler(this);
}

Expand All @@ -35,7 +37,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result)
waveformExtractor.start(new WaveformExtractor.OnProgressListener() {
@Override
public void onProgress(int progress) {
HashMap<String, Object> args = new HashMap();
HashMap<String, Object> args = new HashMap<>();
args.put("progress", progress);
args.put("waveOutFile", waveOutPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class WaveformExtractor {
private static final int TIMEOUT = 5000;
private static final int MAX_SAMPLE_SIZE = 256 * 1024;
//private static final int MAX_SAMPLE_SIZE = 256 * 1024;

private String inPath;
private String wavePath;
Expand Down Expand Up @@ -65,7 +65,7 @@ public void run() {
extractor.setDataSource(inPath);

inFormat = selectAudioTrack(extractor);
int trackCount = extractor.getTrackCount();
//int trackCount = extractor.getTrackCount();
//System.out.println("extractor format = " + inFormat);
inMime = inFormat.getString(MediaFormat.KEY_MIME);
processAudio();
Expand All @@ -85,17 +85,17 @@ void processAudio() {
int sampleRate = inFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
//System.out.println("sample rate = " + sampleRate);
long duration = inFormat.getLong(MediaFormat.KEY_DURATION);
int durationMs = (int)(duration/1000);
//int durationMs = (int)(duration/1000);
long expectedSampleCount = duration * sampleRate / 1000000; // If we hear 2 stereo samples at the same time, we count that as 1 sample here.
//System.out.println("expected sample count = " + expectedSampleCount);

boolean sawInputEOS = false;
int decoderIdleCount = 0;
int bufferSize = MAX_SAMPLE_SIZE;
//int bufferSize = MAX_SAMPLE_SIZE;
int frameCount = 0;
int offset = 100;
//int offset = 100;

ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
//ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
BufferInfo bufferInfo = new BufferInfo();

// For the wave
Expand Down Expand Up @@ -126,7 +126,7 @@ void processAudio() {
int waitingToDecode = 0;
int waitingForDecoded = 0;
long presentationTime = 0L;
long stopwatchStart = System.currentTimeMillis();
//long stopwatchStart = System.currentTimeMillis();
decoder = MediaCodec.createDecoderByType(inMime);
decoder.configure(inFormat, null, null, 0);
decoder.start();
Expand Down Expand Up @@ -225,7 +225,6 @@ void processAudio() {
try (FileOutputStream fout = new FileOutputStream(new File(wavePath))) {
FileChannel channel = fout.getChannel();
int waveHeaderLength = 20; // in bytes
int waveHeaderLengthInShorts = waveHeaderLength / 2; // in shorts
ByteBuffer waveHeaderBytes = ByteBuffer.allocate(waveHeaderLength);
waveHeaderBytes.order(ByteOrder.LITTLE_ENDIAN);
IntBuffer waveHeader = waveHeaderBytes.asIntBuffer();
Expand Down
3 changes: 2 additions & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 31
namespace 'com.ryanheise.just_waveform_example'
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
9 changes: 0 additions & 9 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
11 changes: 9 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.3.0'
}
}

Expand All @@ -14,6 +14,13 @@ allprojects {
google()
mavenCentral()
}

gradle.projectsEvaluated{
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
options.compilerArgs << "-Xlint:unchecked"
}
}
}

rootProject.buildDir = '../build'
Expand All @@ -22,6 +29,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class _MyAppState extends State<MyApp> {
return Center(
child: Text(
'Error: ${snapshot.error}',
style: Theme.of(context).textTheme.headline6,
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
);
Expand All @@ -79,7 +79,7 @@ class _MyAppState extends State<MyApp> {
return Center(
child: Text(
'${(100 * progress).toInt()}%',
style: Theme.of(context).textTheme.headline6,
style: Theme.of(context).textTheme.titleLarge,
),
);
}
Expand Down
35 changes: 24 additions & 11 deletions lib/just_waveform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ class JustWaveform {
switch (call.method) {
case 'onProgress':
final args = call.arguments;
int progress = args['progress'];
String waveOutFilePath = args['waveOutFile'];
Waveform? waveform;
int progress = args['progress'] as int;
String waveOutFilePath = args['waveOutFile'] as String;
final progressController = _progressControllers[waveOutFilePath];
if (progressController == null) break;
if (progressController.isClosed) break;

if (progress == 100) {
waveform = await parse(File(waveOutFilePath));
}
Waveform? waveform;

_progressControllers[waveOutFilePath]
?.add(WaveformProgress._(progress / 100, waveform));
if (progress == 100) {
_progressControllers[waveOutFilePath]?.close();
_progressControllers.remove(waveOutFilePath);
try {
if (progress == 100) {
waveform = await parse(File(waveOutFilePath));
}

progressController
.add(WaveformProgress._(progress / 100, waveform));
if (progress == 100) {
progressController.close();
_progressControllers.remove(waveOutFilePath);
}
} on RangeError {
// If the waveform file is too short.
progressController
.add(WaveformProgress._(progress / 100, waveform));
progressController.close();
} catch (e, stackTrace) {
progressController.addError(e, stackTrace);
}
break;
}
Expand Down
11 changes: 7 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: just_waveform
description: Extracts waveform data from an audio file suitable for visually rendering the waveform.
version: 0.0.4
version: 0.0.5
homepage: https://github.com/ryanheise/just_waveform
topics:
- audio
- waveform

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"
sdk: ">=2.14.0 <4.0.0"
flutter: ">=3.0.0"

dependencies:
flutter:
Expand All @@ -16,7 +19,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flutter_lints: ^2.0.1

flutter:
plugin:
Expand Down

0 comments on commit 8f7de5a

Please sign in to comment.