https://github.com/wangyng/simple_audio_player
A simple audio player for Flutter.
https://github.com/wangyng/simple_audio_player
flutter
Last synced: 15 days ago
JSON representation
A simple audio player for Flutter.
- Host: GitHub
- URL: https://github.com/wangyng/simple_audio_player
- Owner: WangYng
- License: bsd-3-clause
- Created: 2021-08-06T09:33:47.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-08T05:41:27.000Z (3 months ago)
- Last Synced: 2025-06-30T23:04:30.365Z (15 days ago)
- Topics: flutter
- Language: Objective-C
- Homepage:
- Size: 2.47 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# simple_audio_player
A simple audio player for Flutter.
## Install Started
1. Add this to your **pubspec.yaml** file:
```yaml
dependencies:
simple_audio_player: ^1.1.5
```2. Install it
```bash
$ flutter packages get
```## Normal usage
```dart
@override
void initState() {
super.initState();simpleAudioPlayer = SimpleAudioPlayer();
simpleAudioPlayer.eventStream.listen((event) {
print("player event : $event");
switch (event.type) {
case SimpleAudioPlayerEventType.onReady:
// noop
break;
case SimpleAudioPlayerEventType.onPlayEnd:
// noop
break;
case SimpleAudioPlayerEventType.onError:
// noop
break;
case SimpleAudioPlayerEventType.onPositionChange:
// noop
break;
}
});simpleAudioPlayer.stateStream.listen((event) {
print("player state : $event");
switch (event) {
case SimpleAudioPlayerState.idle:
// noop
break;
case SimpleAudioPlayerState.playing:
// noop
break;
case SimpleAudioPlayerState.pause:
// noop
break;
case SimpleAudioPlayerState.stop:
// noop
break;
}
});simpleAudioPlayer.positionStream.listen((event) {
print("player position : $event");
});focusManager.audioFocusStream.listen((event) {
print("focus event : $event");
});
focusManager.becomingNoisyStream.listen((event) {
print("becoming noisy event : $event");
});
notificationManager.notificationStream.listen((event) {
print("notification event : $event");
});
}// ...
CupertinoButton(
child: Text("requestAudioFocus"),
onPressed: () {
SimpleAudioFocusManager().tryToGetAudioFocus().then((value) {
print("tryToGetAudioFocus $value");
});
},
),
CupertinoButton(
child: Text("giveUpAudioFocus"),
onPressed: () {
SimpleAudioFocusManager().giveUpAudioFocus();
},
),
CupertinoButton(
child: Text("prepare"),
onPressed: () {
simpleAudioPlayer.prepare(
uri: "https://96.f.1ting.com/local_to_cube_202004121813/96kmp3/2021/04/16/16b_am/01.mp3");
},
),
CupertinoButton(
child: Text("play"),
onPressed: () {
simpleAudioPlayer.play();
},
),
CupertinoButton(
child: Text("pause"),
onPressed: () {
simpleAudioPlayer.pause();
},
),
CupertinoButton(
child: Text("stop"),
onPressed: () {
simpleAudioPlayer.stop();
},
),
CupertinoButton(
child: Text("showNotification"),
onPressed: () => notificationManager.showNotification(player: player, title: "title", artist: "artist", clipArt: "https://xxxxx"),
),
CupertinoButton(
child: Text("cancelNotification"),
onPressed: () => notificationManager.cancelNotification(),
),
```## Feature
- [x] audio focus manager
- [x] play online mp3 file
- [x] play local mp3 file
- [x] play assets mp3 file
- [x] audio notification manager
- [x] observe becoming noisy