提交 05b39a7a authored 作者: yueweilu's avatar yueweilu

将flutter_sound添加到项目

上级 f549e23b
......@@ -37,5 +37,12 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.microphone
'PERMISSION_MICROPHONE=1',
]
end
end
end
PODS:
- audio_session (0.0.1):
- Flutter
- Flutter (1.0.0)
- flutter_inappwebview (0.0.1):
- Flutter
......@@ -7,47 +9,67 @@ PODS:
- flutter_inappwebview/Core (0.0.1):
- Flutter
- OrderedSet (~> 5.0)
- flutter_sound (9.2.13):
- Flutter
- flutter_sound_core (= 9.2.13)
- flutter_sound_core (9.2.13)
- flutter_tts (0.0.1):
- Flutter
- OrderedSet (5.0.0)
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- permission_handler_apple (9.1.1):
- Flutter
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
DEPENDENCIES:
- audio_session (from `.symlinks/plugins/audio_session/ios`)
- Flutter (from `Flutter`)
- flutter_inappwebview (from `.symlinks/plugins/flutter_inappwebview/ios`)
- flutter_sound (from `.symlinks/plugins/flutter_sound/ios`)
- flutter_tts (from `.symlinks/plugins/flutter_tts/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
SPEC REPOS:
trunk:
- flutter_sound_core
- OrderedSet
EXTERNAL SOURCES:
audio_session:
:path: ".symlinks/plugins/audio_session/ios"
Flutter:
:path: Flutter
flutter_inappwebview:
:path: ".symlinks/plugins/flutter_inappwebview/ios"
flutter_sound:
:path: ".symlinks/plugins/flutter_sound/ios"
flutter_tts:
:path: ".symlinks/plugins/flutter_tts/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
permission_handler_apple:
:path: ".symlinks/plugins/permission_handler_apple/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
SPEC CHECKSUMS:
audio_session: 4f3e461722055d21515cf3261b64c973c062f345
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_inappwebview: 3d32228f1304635e7c028b0d4252937730bbc6cf
flutter_sound: c60effa2a350fb977885f0db2fbc4c1ad5160900
flutter_sound_core: 26c10e5832e76aaacfae252d8925232281c486ae
flutter_tts: 0f492aab6accf87059b72354fcb4ba934304771d
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
PODFILE CHECKSUM: 02caaa843f6501172c0d470d80e72f61175c8b93
PODFILE CHECKSUM: 0ad3cbdbfc252b10d3b4db129d4d399f42000f4b
COCOAPODS: 1.11.2
......@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSMicrophoneUsageDescription</key>
<string>紫金云书需要使用麦克风进行录音</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
......
library record;
import 'dart:io';
import 'package:audio_session/audio_session.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_book/theme.dart';
import 'package:flutter_book/utils/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:flutter_sound/public/flutter_sound_player.dart';
import 'package:flutter_sound/public/flutter_sound_recorder.dart';
import 'package:flutter_sound_platform_interface/flutter_sound_platform_interface.dart';
import 'package:flutter_sound_platform_interface/flutter_sound_recorder_platform_interface.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
......
part of record;
class RecordPage extends StatelessWidget {
typedef _Fn = void Function();
const theSource = AudioSource.microphone;
class RecordPage extends StatefulWidget {
const RecordPage({Key? key}) : super(key: key);
@override
State<RecordPage> createState() => _RecordPageState();
}
class _RecordPageState extends State<RecordPage> {
final FlutterSoundRecorder? _mRecorder = FlutterSoundRecorder();
final FlutterSoundPlayer? _mPlayer = FlutterSoundPlayer();
final String _mPath = 'tau_file.mp4';
final Codec _codec = Codec.aacMP4;
bool _mRecorderIsInited = false;
@override
void initState() {
openTheRecorder().then((value) {
setState(() {
_mRecorderIsInited = true;
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
title: Text('Bottom Sheet Example',style: TextStyle(
color: Colors.white
),),
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFFEE5982),Color(0xFFAB1941)]
)
),
),
actions: [
IconButton(
color: Colors.white,
icon: const Icon(Icons.shopping_cart),
tooltip: 'Open shopping cart',
onPressed: () {
Console.log('++++++++++++++++');
},
title: const Text('Recorder'),
),
body: Column(
children: [
Container(
margin: const EdgeInsets.all(3),
padding: const EdgeInsets.all(3),
height: 80,
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.indigo,
width: 3
)
),
child: Row(
children: [
ElevatedButton(
onPressed: getRecorderFn(),
child: Text(_mRecorder!.isRecording?'stop':'Record')
),
SizedBox(
width: 20,
),
Text(_mRecorder!.isRecording? 'Recording in progress' : 'Record is stopped')
],
),
),
Container(
margin: const EdgeInsets.all(3),
padding: const EdgeInsets.all(3),
height: 80,
width: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFFAF0E6),
border: Border.all(
color: Colors.indigo,
width: 3,
),
),
child: Row(children: [
ElevatedButton(
onPressed: (){
},
//color: Colors.white,
//disabledColor: Colors.grey,
child: Text(_mPlayer!.isPlaying ? 'Stop' : 'Play'),
),
SizedBox(
width: 20,
),
Text(_mPlayer!.isPlaying
? 'Playback in progress'
: 'Player is stopped'),
]),
)
],
),
body: Center(
child: ElevatedButton(
onPressed: () {
_showBottomSheet(context);
},
child: Text('Show Bottom Sheet'),
),
),
);
}
void _showBottomSheet(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('This is a bottom sheet'),
SizedBox(height: 16.0),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop(); // 关闭底部表单
},
child: Text('Close'),
),
],
),
);
},
);
Future<void> openTheRecorder() async {
Permission permission = Permission.microphone;
var status = await permission.request();
if (status != PermissionStatus.granted){
throw RecordingPermissionException('Microphone permission not granted');
}else if (status == PermissionStatus.denied) {
requestPermission(permission);
} else if(status == PermissionStatus.permanentlyDenied){
requestPermission(permission);
} else if(status == PermissionStatus.restricted){
requestPermission(permission);
}
await _mRecorder!.openRecorder();
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
avAudioSessionCategoryOptions:
AVAudioSessionCategoryOptions.allowBluetooth |
AVAudioSessionCategoryOptions.defaultToSpeaker,
avAudioSessionMode: AVAudioSessionMode.spokenAudio,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy.defaultPolicy,
avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
androidAudioAttributes: const AndroidAudioAttributes(
contentType: AndroidAudioContentType.speech,
flags: AndroidAudioFlags.none,
usage: AndroidAudioUsage.voiceCommunication,
),
androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
androidWillPauseWhenDucked: true,
));
_mRecorderIsInited = true;
}
_Fn? getRecorderFn() {
if (!_mRecorderIsInited){
return null;
}
return _mRecorder!.isStopped ? record : stopRecorder;
}
void record() async {
Directory? tempDir = await getExternalStorageDirectory();
var time = DateTime.now().millisecondsSinceEpoch;
const String mPath = 'tau_file.mp4';
String filePath = '${tempDir!.path}/$time$mPath';
_mRecorder!.startRecorder(
toFile: filePath,
codec: _codec,
audioSource: theSource
).then((value) {
setState(() {});
});
}
void stopRecorder() async{
await _mRecorder!.stopRecorder().then((value) async {
Directory? tempDir = await getExternalStorageDirectory();
List<FileSystemEntity> files = tempDir!.listSync();
for (FileSystemEntity file in files) {
print('File: ${file.path}');
}
setState(() {
});
});
}
void requestPermission(Permission permission) async {
PermissionStatus status = await permission.request();
if (status.isPermanentlyDenied){
openAppSettings();
}
}
}
......@@ -9,6 +9,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.11.0"
audio_session:
dependency: "direct main"
description:
name: audio_session
sha256: "6fdf255ed3af86535c96452c33ecff1245990bb25a605bfb1958661ccc3d467f"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.18"
boolean_selector:
dependency: transitive
description:
......@@ -155,6 +163,30 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.8.2"
flutter_sound:
dependency: "direct main"
description:
name: flutter_sound
sha256: "090a4694b11ecc744c2010621c4ffc5fe7c3079d304ea014961a72c7b72cfe6c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.2.13"
flutter_sound_platform_interface:
dependency: "direct main"
description:
name: flutter_sound_platform_interface
sha256: "4537eaeb58a32748c42b621ad6116f7f4c6ee0a8d6ffaa501b165fe1c9df4753"
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.2.13"
flutter_sound_web:
dependency: transitive
description:
name: flutter_sound_web
sha256: ad4ca92671a1879e1f613e900bbbdb8170b20d57d1e4e6363018fe56b055594f
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.2.13"
flutter_spinkit:
dependency: transitive
description:
......@@ -293,6 +325,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.1"
nested:
dependency: transitive
description:
name: nested
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
......@@ -302,7 +342,7 @@ packages:
source: hosted
version: "1.8.3"
path_provider:
dependency: transitive
dependency: "direct main"
description:
name: path_provider
sha256: a1aa8aaa2542a6bc57e381f132af822420216c80d4781f7aa085ca3229208aaa
......@@ -349,6 +389,46 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
sha256: "284a66179cabdf942f838543e10413246f06424d960c92ba95c84439154fcac8"
url: "https://pub.flutter-io.cn"
source: hosted
version: "11.0.1"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
sha256: f9fddd3b46109bd69ff3f9efa5006d2d309b7aec0f3c1c5637a60a2d5659e76e
url: "https://pub.flutter-io.cn"
source: hosted
version: "11.1.0"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
sha256: "99e220bce3f8877c78e4ace901082fb29fa1b4ebde529ad0932d8d664b34f3f5"
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.1.4"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: "6760eb5ef34589224771010805bea6054ad28453906936f843a8cc4d3a55c4a4"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.12.0"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
sha256: cc074aace208760f1eee6aa4fae766b45d947df85bc831cde77009cdb4720098
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.3"
platform:
dependency: transitive
description:
......@@ -365,6 +445,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.7"
provider:
dependency: transitive
description:
name: provider
sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096"
url: "https://pub.flutter-io.cn"
source: hosted
version: "6.1.1"
pull_to_refresh_flutter3:
dependency: "direct main"
description:
......@@ -373,6 +461,22 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
recase:
dependency: transitive
description:
name: recase
sha256: e4eb4ec2dcdee52dcf99cb4ceabaffc631d7424ee55e56f280bc039737f89213
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.1.0"
rxdart:
dependency: transitive
description:
name: rxdart
sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.27.7"
shared_preferences:
dependency: "direct main"
description:
......@@ -466,6 +570,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
synchronized:
dependency: transitive
description:
name: synchronized
sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.0+1"
term_glyph:
dependency: transitive
description:
......@@ -490,6 +602,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.2"
uuid:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.7"
vector_math:
dependency: transitive
description:
......
......@@ -55,6 +55,9 @@ dependencies:
flutter_sound: ^9.2.13
permission_handler: 11.0.1
audio_session: ^0.1.6
flutter_sound_platform_interface: 9.2.13
path_provider: ^2.0.2
dev_dependencies:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论