Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion android/src/main/java/bz/rxla/audioplayer/AudioplayerPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ public void onMethodCall(MethodCall call, MethodChannel.Result response) {
Boolean muted = call.arguments();
mute(muted);
response.success(1);
} else if (call.method.equals("setVolume")) {
int volume = call.arguments();
setVolume(volume);
} else {
response.notImplemented();
}
}


private void setVolume(int volume) {
if (AudioplayerPlugin.am == null) return;

AudioplayerPlugin.am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
}

private void mute(Boolean muted) {
if(AudioplayerPlugin.am == null) return;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class _AudioAppState extends State<AudioApp> {
void initAudioPlayer() {
audioPlayer = new AudioPlayer();

audioPlayer.setVolume(10);

audioPlayer.setDurationHandler((d) => setState(() {
duration = d;
}));
Expand Down
2 changes: 2 additions & 0 deletions lib/audioplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AudioPlayer {

Future<dynamic> mute(bool muted) => channel.invokeMethod('mute', muted);

Future<dynamic> setVolume(int volume) => channel.invokeMethod('setVolume', volume);

Future<dynamic> seek(double seconds) => channel.invokeMethod('seek', seconds);

void setDurationHandler(TimeChangeHandler handler) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: audioplayer
description: A flutter plugin to play audio files
version: 0.4.0
version: 0.5.0
author: Erick Ghaumez <erick@rxla.bz>
homepage: https://github.com/rxlabz/audioplayer

Expand Down