Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All of the listen() method can't be called after called initialize() #185

Closed
lxcyha opened this issue Nov 26, 2019 · 20 comments
Closed

All of the listen() method can't be called after called initialize() #185

lxcyha opened this issue Nov 26, 2019 · 20 comments

Comments

@lxcyha
Copy link

lxcyha commented Nov 26, 2019

version: flutter_downloader: ^1.3.3
platform: ios simulator

code below:
void main() async{ await FlutterDownloader.initialize(); runApp(MusicianApp()); }

plugin audioplayers:^0.12.0:

audioPlayer.onPlayerStateChanged.listen((state) { // never being called }

plugin flutter_sound: ^1.4.8:

flutterSound.onRecorderDbPeakChanged.listen((value) { // never being called })

flutter doctor -v :
[✓] Flutter (Channel stable, v1.9.1+hotfix.4, on Mac OS X 10.14.6 18G1012, locale en-CN)
• Flutter version 1.9.1+hotfix.4 at /Users/cyh/flutter
• Framework revision cc949a8e8b (9 weeks ago), 2019-09-27 15:04:59 -0700
• Engine revision b863200c37
• Dart version 2.5.0

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/cyh/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 11.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.2.1, Build version 11B500
• CocoaPods version 1.7.0.beta.3

[✓] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 34.0.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[✓] IntelliJ IDEA Ultimate Edition (version 2018.3.4)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 32.0.3
• Dart plugin version 183.5429.25

[✓] VS Code (version 1.36.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.1.0

[✓] Connected device (1 available)
• iPhone X • DFDBB98C-3C75-4688-8832-83AE4FD2001D • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)

! Doctor found issues in 1 category.

@lxcyha lxcyha changed the title All of the listen() method can't be called after initialized All of the listen() method can't be called after called initialize() Nov 26, 2019
@lxcyha
Copy link
Author

lxcyha commented Nov 26, 2019

if I don't use initialize, everything goes well.

@lxcyha
Copy link
Author

lxcyha commented Nov 26, 2019

Is isolate causes this problem?

@hnvn
Copy link
Member

hnvn commented Nov 27, 2019

Does it happen in the example project?

@lxcyha
Copy link
Author

lxcyha commented Nov 27, 2019

@hnvn I need to try

@lxcyha
Copy link
Author

lxcyha commented Nov 27, 2019

@hnvn I tried and the result is when I stop using the initialize method, my listen method will be called many times. But if I use the initialize method, then it causes some problems
code below:

	<array>
                 ****** framework required*****
		<string>audio</string>
		<string>fetch</string>
		<string>remote-notification</string>
	</array>
RaisedButton(onPressed: ()async {
        FlutterSound flutterSound =  FlutterSound();
        flutterSound.setDbLevelEnabled(true);
        flutterSound.setDbPeakLevelUpdate(1);
        await flutterSound.startRecorder(null);
        flutterSound.onRecorderDbPeakChanged.listen((c){
          // *************only call 1 time*********  
         // *******but in fact when you are recording,this method will be called every 1 second******
          print('change' + c.toString() );
        });

        Future.delayed(Duration(seconds: 10), (){
          flutterSound.stopRecorder();
        });
      })

@lxcyha
Copy link
Author

lxcyha commented Nov 27, 2019

@hnvn based on your example. I only adjust initState() and initialize() to make the code running.

@lxcyha
Copy link
Author

lxcyha commented Nov 27, 2019

flutter_sound: ^1.4.8

@SpringMagnolia
Copy link

this happened to me too,still struggling

@hnvn
Copy link
Member

hnvn commented Nov 27, 2019

It is much helpful if you can give me a repository to reproduce this issue

@lxcyha
Copy link
Author

lxcyha commented Nov 27, 2019

@hnvn here: https://github.com/lxcyha/flutter_downloader_problem, you can uncomment initialize and see what diffs between comment and uncomment

@lxcyha
Copy link
Author

lxcyha commented Nov 27, 2019

@hnvn click the RaisedButton and speak some words you can see onRecorderDbPeakChanged can be triggered multiple times. And when you uncomment initialize. it will only trigger 1 time.

@hnvn
Copy link
Member

hnvn commented Nov 27, 2019

I will have a look at it this weekend. My time within the week is quite tight

@lxcyha
Copy link
Author

lxcyha commented Nov 27, 2019

@hnvn thanks, in advanced

@hnvn
Copy link
Member

hnvn commented Nov 28, 2019

Just have a quick look at your codes and see you are missing permission configuration as described in flutter_sound document

@lxcyha
Copy link
Author

lxcyha commented Nov 28, 2019

@hnvn you mean android? I already added permission to info.plist. and you can see the different behavior of tapping the button.

@lxcyha
Copy link
Author

lxcyha commented Nov 28, 2019

@hnvn you can see it in info.plist:

	<key>UIBackgroundModes</key>
	<array>
		<string>audio</string>
		<string>fetch</string>
		<string>remote-notification</string>
	</array>

and for the property NSMicrophoneUsageDescription, that doesn't matter. It's just a description.

@hnvn
Copy link
Member

hnvn commented Nov 30, 2019

I tried but onRecorderDbPeakChanged isn't even trigged at all

@lxcyha
Copy link
Author

lxcyha commented Nov 30, 2019

@hnvn you haven't seen this log?
image

Once you click the RaisedButton, it will show some logs, and when you uncomment initialize method, you can't see these logs until 10 seconds later.

Did you try it in ios simulator?

@IphoneCoder
Copy link

Use this plugin cause the channel invokeMethod not work

@bartekpacia
Copy link
Collaborator

Considering this stale and closing. Feel free to open a new issue if the problem reoccurs.

@bartekpacia bartekpacia closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants