123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- class DubbingLib {
- static final DubbingLib _instance = DubbingLib();
- static DubbingLib get instance => _instance;
- static const MethodChannel _channel =
- const MethodChannel('dubbing_lib');
- StreamController _onProgressChange;
- StreamController _onRecordProgressChange;
- StreamController _onDecodeResultChange;
- Stream<int> get recordProgressChange => _onRecordProgressChange.stream;
- Stream<Map> get decodeResultChange => _onDecodeResultChange.stream;
- /// 路径文件夹地址
- String videoPath;
- String recordPath;
- String recordDecodePath;
- String bgmPath;
- String bgmDecodePath;
- String audioSyncPath;
- String audioSyncDecodePath;
- String videoMixInPath;
- static Future<String> get platformVersion async {
- final String version = await _channel.invokeMethod('getPlatformVersion');
- return version;
- }
- Future<void> init() {
- return _channel.invokeMethod("initSpeechSdk");
- }
- Future<void> setExtraFullScreen() {
- //todo 暂时视频播放时全屏StatusBar bug
- return _channel.invokeMethod("setExtraFullScreen");
- }
- Future<String> downLoadVideo(String videoUrl) {
- return _channel.invokeMethod("downLoadVideo", {"url": videoUrl});
- }
- Future<void> pauseRecordAudio() {
- return _channel.invokeMethod("pauseRecordAudio");
- }
- /// 返回录音文件地址
- Future<String> startRecord(int index, int duration, String fileName) {
- return _channel.invokeMethod("startRecord",
- {
- "duration": duration,
- "fileName": fileName,
- "index": index,
- "pathAudio": recordPath,
- "pathAudioDecode": recordDecodePath
- }
- );
- }
- Future<void> playRecordAudio(String filePath) {
- return _channel.invokeMethod("playRecordAudio", {"fileName": filePath});
- }
- Future<String> startMixinAudio(String videoId, String bgmUrl, String bgmPath,
- List<int> endTimeList,
- List<String> decodeAudioPathList,
- List<int> durationList, String localVideoPath,
- List<double> startTimeList, String mixinName) {
- return _channel.invokeMethod(
- "startMixinAudio", {
- "videoId": videoId,
- "bgmUrl": bgmUrl,
- "endTimeList": endTimeList,
- "audioDecodePaths": decodeAudioPathList,
- "durationList": durationList,
- "videoPath": localVideoPath,
- "bgmPath": bgmPath,
- "pathBgmDecode": bgmDecodePath,
- "pathBgmRecordSync": audioSyncPath,
- "pathBgmRecordDecodeSync": audioSyncDecodePath,
- "pathVideoMixin": videoMixInPath,
- "startTimeList": startTimeList,
- "mixinName": mixinName
- });
- }
- Future<void> cleanAudioData(String videoId) {
- return _channel.invokeMethod("cleanAudioData", {
- "videoId": videoId,
- "pathAudio": recordPath,
- "pathAudioDecode": recordDecodePath
- });
- }
- Future<String> startMixinPaintedAudio(List<String> audioPaths, String bgmPath, List<int> durationList, List<int> endTimeList,
- String audioDecodePath, String mixinFilePath, String encodePath,List<int> startTimeList) {
- return _channel.invokeMethod("startMixinPaintedAudio",
- {"audioPaths": audioPaths, "bgmPath": bgmPath, "durationList": durationList, "endTimeList": endTimeList,
- "audioDecodePath": audioDecodePath, "mixinFilePath": mixinFilePath, "encodePath": encodePath,"startTimeList": startTimeList});
- }
- /// 初始化路径
- void initPath(
- {@required String videoPath, @required String recordPath, @required String recordDecodePath,
- @required String bgmPath, @required String bgmDecodePath, @required String audioSyncPath, @required String audioSyncDecodePath,
- @required String videoMixInPath}) {
- this.videoPath = videoPath;
- this.recordPath = recordPath;
- this.recordDecodePath = recordDecodePath;
- this.bgmPath = bgmPath;
- this.bgmDecodePath = bgmDecodePath;
- this.audioSyncPath = audioSyncPath;
- this.audioSyncDecodePath = audioSyncDecodePath;
- this.videoMixInPath = videoMixInPath;
- }
- /// 初始化listener 进入录音页面时调用
- void initListener() {
- _onProgressChange = new StreamController<int>.broadcast();
- _onRecordProgressChange = new StreamController<int>.broadcast();
- _onDecodeResultChange = new StreamController<Map>.broadcast();
- _channel.setMethodCallHandler(_onMethodCallHandler);
- }
- /// 1.录音进度 2.解码录音回调
- Future _onMethodCallHandler(MethodCall call) {
- switch (call.method) {
- case "recordProgress":
- _onRecordProgressChange.add(call.arguments['progress']);
- break;
- case "decodeResult":
- _onDecodeResultChange.add(call.arguments);
- break;
- }
- return null;
- }
- /// 关闭stream
- void closeStream() {
- _channel.setMethodCallHandler(null);
- _onProgressChange.close();
- _onRecordProgressChange.close();
- _onDecodeResultChange.close();
- }
- }
|