This file describes some common pitfalls and how to solve them. Please always refer to this before opening an issue.
Not all formats are supported by all platforms. Essentially audioplayers
is just centralized interface that communicate with native audio players on each platform. We are not parsing the bytes of your song. Each platform has its own native support. Please do not open issues regarding encoding/file format compatibility unless it is an AudioPlayers specific issue.
You can check a list of supported formats below:
- Android
- iOS
- macOS
- Web: audio formats supported by the browser you are using (more details)
- Windows
- Linux: List of defined audio types and their according Plugins
It is very common for mobile platforms to forbid non-HTTPS traffic due to it's lack of encryption and severe security deficiency. However, there are ways to bypass this protection.
On iOS and macOS, edit your .plist
and add:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
On Android, add android:usesCleartextTraffic="true"
to your AndroidManifest.xml
file located in android/app/src/main/AndroidManifest.xml
:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...
>
...
</application>
</manifest>
Flutter requires that assets are specified on your pubspec.yaml
file, under flutter > assets
; check this for an example.
Note: when playing local assets, by default every instance of AudioPlayers uses a shared global instance of AudioCache, that will have a default prefix "/assets" configured, as per Flutter conventions. However you can easily changing that by specifying your own instance of AudioCache with any other (or no) prefix.
The remote URL must be accessible and not be a redirect. If it's not an audio file, it does a redirect, it requires some headers, cookies or authentication, it will not work. Please bundle the file on the app or host it somewhere that properly provides the file. If you are having issues with playing audio from an URL, please first download the file and try running it locally. If the issue persists, then open the issue, including the file so we can test. Otherwise, it's an issue with your URL, not audioplayers.
Warning: If you are having any sort of build issues, you must read this first.
Our CI builds our example app using audioplayers for Android, iOS, Linux, macOS, Windows, and web. So if the build is passing, any build errors (from android/ios sdk, gradle, java, kotlin, cocoa pods, swift, flutter, etc) is not a global issue and likely is something on your setup.
Before opening an issue, you must try these steps:
- Run this on your project and try again:
flutter clean
rm -rf build
rm -rf ~/.pub-cache
flutter pub get
- Update xcode, android studio, android sdks, to the latest versions.
- If the issue persists, clone the audioplayers repo and run the
example
app on the platform you are having issues. If it works, then there is something wrong with your project, and you can compare it to theexample
app to see what the problem is. - If the problem still persists, and no existing (open or closed) issue on this repo, no stack overflow question or existing discord discussion solves you problem, then you can open an issue. But you must follow the issue template, and refer to the problem on the example app (or start with its code and make only the necessary modifications to trigger the issue), not on your own app that we don't have access (because since step 2 the error must be reproducible on the example app).
- Again, only open an issue if you reached step 3 and follow the issue template closely. Build issues that do not follow these steps will be closed without warning.
Some platforms need additional requirements to be fulfilled:
There is a required configuration to enable audio do be playing on the background; add the following lines to your info.plist
:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
Or on XCode you can add it as a capability; more details here.
One of the know reasons for streams not playing is that the stream is being gziped by the server, as described here.
Depending on the file format and platform, when audioplayers uses the native implementation of the "looping" feature, there will be gaps between plays, which might not be noticeable for non-continuous SFX but will definitely be noticeable for looping songs.
TODO(luan): break down alternatives here, low latency mode, audio pool, gapless_audioplayer, ocarina, etc
By default, macOS apps don't allow outgoing connections; so playing audio files/streams from the internet won't work. To fix this, add the following to the .entitlements
files for your app:
<key>com.apple.security.network.client</key>
<true/>