-
Notifications
You must be signed in to change notification settings - Fork 55
/
README.md
64 lines (55 loc) · 2.41 KB
/
README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# audio_manager
[![pub package](https://img.shields.io/pub/v/audio_manager.svg)](https://pub.dartlang.org/packages/audio_manager)
A flutter plugin for music playback, including notification handling.
> This plugin is developed for iOS based on AVPlayer, while android is based on mediaplayer
<img src="https://raw.githubusercontent.com/jeromexiong/audio_manager/master/screenshots/android.png" height="300" alt="The example app running in Android"><img src="https://raw.githubusercontent.com/jeromexiong/audio_manager/master/screenshots/android2.png" height="300" alt="The example app running in Android"><img src="https://raw.githubusercontent.com/jeromexiong/audio_manager/master/screenshots/iOS.png" height="300" alt="The example app running in iOS"><img src="https://raw.githubusercontent.com/jeromexiong/audio_manager/master/screenshots/iOS2.jpeg" height="300" alt="The example app running in iOS">
## iOS
Add the following permissions in the `info.plist` file
```xml
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
```
- ⚠️ Some methods are invalid in the simulator, please use the real machine
## Android
Since `Android9.0 (API 28)`, the application disables HTTP plaintext requests by default. To allow requests, add `android:usesCleartextTraffic="true"` in `AndroidManifest.xml`
```xml
<application
...
android:usesCleartextTraffic="true"
...
>
```
- ⚠️ Android minimum supported version 23 `(app/build.gradle -> minSdkVersion: 23)`
- ⚠️ Android minimum supported Gradle version is 5.4.1 `(gradle-wrapper.properties -> gradle-5.4.1-all.zip)`
## How to use?
The `audio_manager` plugin is developed in singleton mode. You only need to get`AudioManager.instance` in the method to quickly start using it.
## Quick start
you can use local `assets`, `directory file` or `network` resources
```dart
// Initial playback. Preloaded playback information
AudioManager.instance
.start(
"assets/audio.mp3",
// "network format resource"
// "local resource (file://${file.path})"
"title",
desc: "desc",
// cover: "network cover image resource"
cover: "assets/ic_launcher.png")
.then((err) {
print(err);
});
// Play or pause; that is, pause if currently playing, otherwise play
AudioManager.instance.playOrPause()
// events callback
AudioManager.instance.onEvents((events, args) {
print("$events, $args");
}
```