Search code examples
flutterdartjust-audio

Flutter Just_audio, Error No implementation found for method disposeAllPlayers


I am using just_audio package to play my base64 string which is a wav file that I received from my server. The app is being played from an android device API 30-ish. This is the error once the base64 is loaded:

E/flutter (31770): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method disposeAllPlayers on channel com.ryanheise.just_audio.methods)
E/flutter (31770): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
E/flutter (31770): <asynchronous suspension>
E/flutter (31770): #1      MethodChannelJustAudio.disposeAllPlayers (package:just_audio_platform_interface/method_channel_just_audio.dart:29:10)
E/flutter (31770): <asynchronous suspension>
E/flutter (31770): 
E/flutter (31770): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method init on channel com.ryanheise.just_audio.methods)
E/flutter (31770): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
E/flutter (31770): <asynchronous suspension>
E/flutter (31770): #1      MethodChannelJustAudio.init (package:just_audio_platform_interface/method_channel_just_audio.dart:13:5)
E/flutter (31770): <asynchronous suspension>
E/flutter (31770): #2      AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1330:13)
E/flutter (31770): <asynchronous suspension>
E/flutter (31770): 

My custom base64 player which I follow from the instruction of the page:

class MyAudioPlayer extends StreamAudioSource {
  MyAudioPlayer({this.bytes});

  List<int> bytes;

  @override
  Future<StreamAudioResponse> request([int start, int end]) async {
    final start = 0;
    final end = bytes.length;
    return StreamAudioResponse(
      sourceLength: bytes.length,
      contentLength: end - start,
      offset: start,
      stream: Stream.value(bytes.sublist(start, end)),
      contentType: "audio/x-wav",
    );
  }
}

The file in which I played:

  void playTTS(String content) async{
    Dialogs.showLoadingDialog(context: context);
    final List<int> base64 = await ApiService.textToSpeech(content);
    final player = AudioPlayer();
    await player.setAudioSource(MyAudioPlayer(bytes: base64));
    await player.play();
    Navigator.of(context, rootNavigator: true).pop();
    listString.value = List.from(listString.value..add(ValueNotifier(content)));
  }

I have set already set this to my androidmanifest.xml to true already.

android:usesCleartextTraffic="true"

Any help is appreciated.


Solution

  • Seems like I don't have to convert the base64 Wav file with a custom class like the tutorial did. According to the online converter, all I have to do was put data:audio/wav;base64,$base64 before the actual base64 string and uses the normal setUrl and it worked:

     final String code = "data:audio/wav;base64," + json.decode(response.body)["base64"];
     final player = AudioPlayer();
     player.setUrl(code);
     await player.play();