Issue in just_audio pugin in flutter

Issue

I’m making a project in which when user click on button a timer will start and after user set time a sound will play for that I’m using just_audio: ^0.6.15+1 in my flutter project but it cause many issue below is error stuff.

D/Linux   (21303): [Posix_connect Debug]Process com.snss.xlnc :443 
E/flutter (21303): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Connection aborted
E/flutter (21303): #0      AudioPlayer._load (package:just_audio/just_audio.dart:688:11)
E/flutter (21303): <asynchronous suspension>
E/flutter (21303): #1      AudioPlayer.load (package:just_audio/just_audio.dart:625:14)
E/flutter (21303): <asynchronous suspension>
E/flutter (21303): #2      AudioPlayer.setAudioSource (package:just_audio/just_audio.dart:602:18)
E/flutter (21303): <asynchronous suspension>
E/flutter (21303): #3      _ClassStartState.keepRunning (package:xlnc/tutor/startClass.dart:84:7)
E/flutter (21303): <asynchronous suspension>
E/flutter (21303): 

This is my code

var t = DateFormat.Hms().parse(time);
var rT = DateFormat.Hms().parse(remTime);
var co = t.isAfter(rT);

if (co) {
  player.setUrl('$soundUrl');
  player.setVolume(1);
  player.play();
  player.setLoopMode(LoopMode.one);
}

This is my flutter doctor -v

[√] Flutter (Channel stable, 2.0.1, on Microsoft Windows [Version 10.0.19042.804], locale en-IN)
    • Flutter version 2.0.1 at D:\flutter
    • Framework revision c5a4b4029c (7 days ago), 2021-03-04 09:47:48 -0800
    • Engine revision 40441def69
    • Dart version 2.12.0

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at D:\android_sdk
    • Platform android-S, build-tools 30.0.3
    • ANDROID_HOME = D:\android_sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.54.1)
    • VS Code at C:\Users\user\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.20.0

[√] Connected device (3 available)
    • vivo 1907 (mobile) • SOFAE6TCEMRKFUCU • android-arm64  • Android 10 (API 29)
    • Chrome (web)       • chrome           • web-javascript • Google Chrome 89.0.4389.82
    • Edge (web)         • edge             • web-javascript • Microsoft Edge 88.0.705.81

• No issues found!

Solution

First go to your AndroidManifest.xml. It can be found in /android/app/src/main.

Then just add android:usesCleartextTraffic="true" under <application tag.

Your AndroidManifest.xml should look like this below

<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="shafa_doctor"
        android:requestLegacyExternalStorage="true"
        android:usesCleartextTraffic="true" //just add this line only
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

... more code belows

Answered By – Kamrul Hasan Jony

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.