waveform_ffi 0.0.1 waveform_ffi: ^0.0.1 copied to clipboard
Flutter plugin for waveform
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:waveform_ffi/waveform_ffi.dart';
import 'package:path_provider/path_provider.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _response = '(please, wait)';
@override
void initState() {
super.initState();
initPlatformState();
}
void initPlatformState() {
// sync call
String response = WaveForm.callConvertData("aaaaaaaaa");
setState(() {
_response = response;
});
}
Future<String> get _localPath async {
return (await getApplicationDocumentsDirectory()).path;
}
Future<void> bp() async {
File f = File(await _localPath + "/test.mp3");
if (await f.exists()) {
await f.delete();
}
await f.create();
http.Response response = await http.get(
"https://p.scdn.co/mp3-preview/546cc859633ce69e1b27f9cf22e64f4d9f80b2f4");
await f.writeAsBytes(response.bodyBytes);
try {
_response = WaveForm.callConvertData(f.path);
} catch (e, stacktrace) {}
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter Rust FFI'),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Center(
child: Text(
'Response:\n$_response\n',
textAlign: TextAlign.center,
),
),
FlatButton(
child: Text("aaaaaaaaaa"),
onPressed: bp,
)
],
),
),
),
);
}
}