Getting Error on Web
Flutter Web Bootstrap: Programmatic
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_player.dart 132:13 new
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 ctor: FlutterSoundPlayer()
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_recorder.dart 140:13 new
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 ctor: FlutterSoundRecorder()
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_player.dart 511:13 _openAudioSession
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 FS:---> openAudioSession
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_player.dart 524:15 _openAudioSession
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 Resetting flutter_sound Player Plugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_player.dart 360:13 log
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 ---> resetPlugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_player.dart 360:13 log
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 <--- resetPlugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_recorder.dart 372:13 openRecorder
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 FS:---> openAudioSession
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_recorder.dart 381:13 _openAudioSession
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 ---> openAudioSession
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_recorder.dart 396:17 _openAudioSession
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 Resetting flutter_sound Recorder Plugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_recorder.dart 310:13 log
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 ---> resetPlugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 963:28 get current
│ #1 packages/flutter_sound/public/flutter_sound_recorder.dart 310:13 log
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 <--- resetPlugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
TypeError: dart.global.newPlayerInstance is not a function
at flutter_sound_player_web.FlutterSoundPlayerWeb.new.openPlayer (http://localhost:58834/packages/flutter_sound_web/flutter_sound_player_web.dart.lib.js:69:42)
at openPlayer.next (
Up are my logs now my code is
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => const MaterialApp(
home: ChatPage(),
);
}
class ChatPage extends StatefulWidget {
const ChatPage({super.key});
@override
State<ChatPage> createState() => _ChatPageState();
}
class _ChatPageState extends State<ChatPage> {
@override
Widget build(BuildContext context) => Scaffold(
backgroundColor: Colors.black,
body:SimpleRecorder()
);
}
Now Simplerecorder
import 'package:audio_session/audio_session.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:flutter_sound_platform_interface/flutter_sound_recorder_platform_interface.dart';
import 'package:permission_handler/permission_handler.dart';
typedef _Fn = void Function();
/* This does not work. on Android we must have the Manifest.permission.CAPTURE_AUDIO_OUTPUT permission.
* But this permission is _is reserved for use by system components and is not available to third-party applications._
* Pleaser look to [this](https://developer.android.com/reference/android/media/MediaRecorder.AudioSource#VOICE_UPLINK)
*
* I think that the problem is because it is illegal to record a communication in many countries.
* Probably this stands also on iOS.
* Actually I am unable to record DOWNLINK on my Xiaomi Chinese phone.
*
*/
//const theSource = AudioSource.voiceUpLink;
//const theSource = AudioSource.voiceDownlink;
const theSource = AudioSource.microphone;
/// Example app.
class SimpleRecorder extends StatefulWidget {
@override
_SimpleRecorderState createState() => _SimpleRecorderState();
}
class _SimpleRecorderState extends State<SimpleRecorder> {
Codec _codec = Codec.mp3;
String _mPath = 'tau_file.mp4';
FlutterSoundPlayer? _mPlayer = FlutterSoundPlayer();
FlutterSoundRecorder? _mRecorder = FlutterSoundRecorder();
bool _mPlayerIsInited = false;
bool _mRecorderIsInited = false;
bool _mplaybackReady = false;
@override
void initState() {
_mPlayer!.openPlayer().then((value) {
setState(() {
_mPlayerIsInited = true;
});
});
openTheRecorder().then((value) {
setState(() {
_mRecorderIsInited = true;
});
});
super.initState();
}
@override
void dispose() {
_mPlayer!.closePlayer();
_mPlayer = null;
_mRecorder!.closeRecorder();
_mRecorder = null;
super.dispose();
}
Future<void> openTheRecorder() async {
if (!kIsWeb) {
var status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
throw RecordingPermissionException('Microphone permission not granted');
}
}
await _mRecorder!.openRecorder();
if (!await _mRecorder!.isEncoderSupported(_codec) && kIsWeb) {
_codec = Codec.opusWebM;
_mPath = 'tau_file.webm';
if (!await _mRecorder!.isEncoderSupported(_codec) && kIsWeb) {
_mRecorderIsInited = true;
return;
}
}
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;
}
// ---------------------- Here is the code for recording and playback -------
void record() {
_mRecorder!
.startRecorder(
toFile: _mPath,
codec: _codec,
audioSource: theSource,
)
.then((value) {
setState(() {});
});
}
void stopRecorder() async {
await _mRecorder!.stopRecorder().then((value) {
setState(() {
//var url = value;
_mplaybackReady = true;
});
});
}
void play() {
assert(_mPlayerIsInited &&
_mplaybackReady &&
_mRecorder!.isStopped &&
_mPlayer!.isStopped);
_mPlayer!
.startPlayer(
fromURI: _mPath,
//codec: kIsWeb ? Codec.opusWebM : Codec.aacADTS,
whenFinished: () {
setState(() {});
})
.then((value) {
setState(() {});
});
}
void stopPlayer() {
_mPlayer!.stopPlayer().then((value) {
setState(() {});
});
}
// ----------------------------- UI --------------------------------------------
_Fn? getRecorderFn() {
if (!_mRecorderIsInited || !_mPlayer!.isStopped) {
return null;
}
return _mRecorder!.isStopped ? record : stopRecorder;
}
_Fn? getPlaybackFn() {
if (!_mPlayerIsInited || !_mplaybackReady || !_mRecorder!.isStopped) {
return null;
}
return _mPlayer!.isStopped ? play : stopPlayer;
}
@override
Widget build(BuildContext context) {
Widget makeBody() {
return Column(
children: [
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: getRecorderFn(),
//color: Colors.white,
//disabledColor: Colors.grey,
child: Text(_mRecorder!.isRecording ? 'Stop' : 'Record'),
),
SizedBox(
width: 20,
),
Text(_mRecorder!.isRecording
? 'Recording in progress'
: 'Recorder 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: getPlaybackFn(),
//color: Colors.white,
//disabledColor: Colors.grey,
child: Text(_mPlayer!.isPlaying ? 'Stop' : 'Play'),
),
SizedBox(
width: 20,
),
Text(_mPlayer!.isPlaying
? 'Playback in progress'
: 'Player is stopped'),
]),
),
],
);
}
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
title: const Text('Simple Recorder'),
),
body: makeBody(),
);
}
}
same issue
me too
Same issue for me, any solution? I'm using version 9.2.13
This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.
running in the same issue flutter_sound: ^9.15.61
@RA341 : could you be more precise ? What is exactly your issue ?
pretty much the same issue, do we have to include the js libraries
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 packages/flutter_sound/public/flutter_sound_player.dart 133:5 new
│ #1 packages/client/service/microphone_manager.dart 15:18 _internal
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 ctor: FlutterSoundPlayer()
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 packages/flutter_sound/public/flutter_sound_recorder.dart 140:5 new
│ #1 packages/client/service/microphone_manager.dart 16:20 _internal
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 ctor: FlutterSoundRecorder()
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 packages/flutter_sound/public/flutter_sound_player.dart 502:5 _openAudioSession
│ #1 packages/flutter_sound/public/flutter_sound_player.dart 501:47 [_openAudioSession]
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 FS:---> openAudioSession
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 packages/flutter_sound/public/flutter_sound_player.dart 515:7 _openAudioSession
│ #1 packages/flutter_sound/public/flutter_sound_player.dart 501:47 [_openAudioSession]
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 Resetting flutter_sound Player Plugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 packages/flutter_sound/public/flutter_sound_player.dart 347:5 log
│ #1 packages/flutter_sound_web/flutter_sound_player_web.dart 221:13 resetPlugin
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 ---> resetPlugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 packages/flutter_sound/public/flutter_sound_player.dart 347:5 log
│ #1 packages/flutter_sound_web/flutter_sound_player_web.dart 227:13 resetPlugin
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 <--- resetPlugin
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
TypeError: dart.global.newPlayerInstance is not a function
packages/flutter_sound_web/flutter_sound_player_web.dart 243:18 openPlayer
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5 _async
packages/flutter_sound_web/flutter_sound_player_web.dart 232:25 openPlayer
packages/flutter_sound/public/flutter_sound_player.dart 526:12 _openAudioSession
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 <fn>
dart-sdk/lib/async/zone.dart 1661:54 runUnary
dart-sdk/lib/async/future_impl.dart 163:18 handleValue
dart-sdk/lib/async/future_impl.dart 847:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 876:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 472:9 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7 <fn>
A long time ago, it was necessary to load explicitly the Java Script library.
But not anymore. I guess that you use the standard index.html provided by flutter. Don’t you do?
yeah
am i doing something wrong during initialization
initstate
Future<void> init() async {
await player.openPlayer();
await recorder.openRecorder();
}
@override
void initState() {
init().then(
(value) => setState(() {}),
);
super.initState();
}
Flutter is supposed to load automatically the js scripts that are in your assets. But you aren’t the first developer having this issue. I don’t really understand why.
A long time ago, it was necessary to load explicitly the Java Script library. But not anymore. I guess that you use the standard
index.htmlprovided by flutter. Don’t you do?
I do have minor modifications to the index.html, but they are cosmetic and should not affect the flutter itself (I think)
<body>
<div id="loading">
<img src="icons/mictest.gif" style="max-width: 480;"alt="loading">
</div>
<script>
var loadingElement = document.getElementById('loading');
function hideLoading() {
loadingElement.classList.add('fade-out');
// Remove the loading element from the DOM after the transition
setTimeout(() => {
loadingElement.style.display = 'none';
}, 400); // This should match the transition duration in CSS
}
window.addEventListener("flutter-first-frame", function () {
var element = document.getElementsByClassName("loading");
hideLoading();
});
</script>
<script src="flutter_bootstrap.js" async></script>
</body>
Of course you use the regular pubspec of flutter sound and not a modified plugin? The 3 js scripts are declared in flutter-sound-web pubspec
Yep using the normal package
flutter_sound: ^9.15.61
from what i understand looking at the internet, the issue seems to be that the js libraries are not downloaded
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_function
Is a possible workaround to include the libraries in index anyway
I am going immediately test that every thing is ok on my side. Not many people use the web version, and it is possible that a bug has been introduced recently. Wait a moment, I am testing…
OK. The speed control example runs fine on my site. There is a little problem to play the "simple player" but I think that the problem is because the asset example is not correctly uploaded on my server. I will fix that.
Of course, you can load yourself the scripts, but I would would be glad to understand why it is necessary.
Curious can you try running an empty flutter project from scratch, then copying the example
Regarding the scripts, just asking really I have no idea
could this be flutter version issue ? I am using 3.24
Developer identity "Apple Development: Laurent Aries (6HKJS9QR6C)" selected for iOS code signing
larpoux@Mac-Studio:~/proj/tau/tauwaweb/example$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.6.1 23G93 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.92.2)
[✓] VS Code (version unknown)
✗ Unable to determine VS Code version.
[✓] VS Code (version unknown)
✗ Unable to determine VS Code version.
[✓] Connected device (6 available)
[✓] Network resources
• No issues found!
Wait ok so this is weird
The app runs into that error when I first start building, but if I keep the program running and hot reload/restart, the initlization works perfectly and starts working
You are probably a better expert than me on web development.
You are not the first to have this problem. But I have never understood the reason.
I am experiencing the same problem. I debug the app in chrome. My code is basically the sample recorder app.
From pubspec.yaml
flutter_sound: ^9.15.61
permission_handler: ^11.3.1
audio_session: ^0.1.21
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.24.1, on Microsoft Windows [Version 10.0.19045.4894], locale de-DE)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[√] Chrome - develop for the web
[X] Visual Studio - develop Windows apps
X Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2024.1)
[√] VS Code (version 1.93.1)
[√] Connected device (3 available)
[√] Network resources
Code
import 'package:flutter/material.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:permission_handler/permission_handler.dart';
import 'package:audio_session/audio_session.dart';
// const theSource = AudioSource.microphone
typedef _Fn = void Function();
void main() {
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
Codec _codec = Codec.aacMP4;
String _mPath = 'tau_file.mp4';
FlutterSoundPlayer? _mPlayer = FlutterSoundPlayer();
FlutterSoundRecorder? _mRecorder = FlutterSoundRecorder();
bool _mPlayerIsInited = false;
bool _mRecorderIsInited = false;
bool _mplaybackReady = false;
@override
void initState() {
_mPlayer!.openPlayer().then((value) {
setState(() {
_mPlayerIsInited = true;
});
});
openTheRecorder().then((value) {
setState(() {
_mRecorderIsInited = true;
});
});
super.initState();
}
@override
void dispose() {
_mPlayer!.closePlayer();
_mPlayer = null;
_mRecorder!.closeRecorder();
_mRecorder = null;
super.dispose();
}
Future<void> openTheRecorder() async {
if (!kIsWeb) {
var status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
throw RecordingPermissionException('Microphone permission not granted');
}
}
await _mRecorder!.openRecorder();
if (!await _mRecorder!.isEncoderSupported(_codec) && kIsWeb) {
_codec = Codec.opusWebM;
_mPath = 'tau_file.webm';
if (!await _mRecorder!.isEncoderSupported(_codec) && kIsWeb) {
_mRecorderIsInited = true;
return;
}
}
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;
}
// ---------------------- Here is the code for recording and playback -------
void record() {
_mRecorder!
.startRecorder(
toFile: _mPath,
codec: _codec,
// audioSource: theSource,
)
.then((value) {
setState(() {});
});
}
void stopRecorder() async {
await _mRecorder!.stopRecorder().then((value) {
setState(() {
//var url = value;
_mplaybackReady = true;
});
});
}
void play() {
assert(_mPlayerIsInited &&
_mplaybackReady &&
_mRecorder!.isStopped &&
_mPlayer!.isStopped);
_mPlayer!
.startPlayer(
fromURI: _mPath,
//codec: kIsWeb ? Codec.opusWebM : Codec.aacADTS,
whenFinished: () {
setState(() {});
})
.then((value) {
setState(() {});
});
}
void stopPlayer() {
_mPlayer!.stopPlayer().then((value) {
setState(() {});
});
}
// ----------------------------- UI --------------------------------------------
_Fn? getRecorderFn() {
if (!_mRecorderIsInited || !_mPlayer!.isStopped) {
return null;
}
return _mRecorder!.isStopped ? record : stopRecorder;
}
_Fn? getPlaybackFn() {
if (!_mPlayerIsInited || !_mplaybackReady || !_mRecorder!.isStopped) {
return null;
}
return _mPlayer!.isStopped ? play : stopPlayer;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FloatingActionButton(onPressed: getRecorderFn(), child: const Icon(Icons.mic)),
const Text("Hello"),
],
)
),
),
);
}
}
@Ricu once the app fails can you hot restart see if it starts working
@Ricu once the app fails can you hot restart see if it starts working
It does indeed work after hot restarting.
@Larpoux can you confirm this is happening on your side
I never have any problem to load the scripts with the regular index.html from flutter. Hard for me to debug that, because I don’t reproduce the issue. Of course, if you understand what happens, I will do what is necessary in flutter sound
Perhaps a problem with your chrome?
did you try with a fresh flutter project
The examples are very basic. You can try to run them and see if you have the same problem