Skip to content

Commit

Permalink
Merge pull request #4 from pauldemarco/master
Browse files Browse the repository at this point in the history
Volume control from @pauldemarco
  • Loading branch information
luanpotter committed Nov 18, 2017
2 parents 46c5988 + f1edfac commit 4e9d9e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void onMethodCall(MethodCall call, MethodChannel.Result response) {
String playerId = ((HashMap) call.arguments()).get("playerId").toString();
if (call.method.equals("play")) {
String url = ((HashMap) call.arguments()).get("url").toString();
Boolean resPlay = play(playerId, url);
double volume = (double)((HashMap) call.arguments()).get("volume");
Boolean resPlay = play(playerId, url, (float)volume);
response.success(1);
} else if (call.method.equals("pause")) {
pause(playerId);
Expand Down Expand Up @@ -83,7 +84,7 @@ private void pause(String playerId) {
handler.removeCallbacks(sendData);
}

private Boolean play(final String playerId, String url) {
private Boolean play(final String playerId, String url, float volume) {
MediaPlayer mediaPlayer = mediaPlayers.get(playerId);
if (mediaPlayer == null) {
mediaPlayer = new MediaPlayer();
Expand All @@ -107,6 +108,7 @@ private Boolean play(final String playerId, String url) {

channel.invokeMethod("audio.onDuration", buildArguments(playerId, mediaPlayer.getDuration()));

mediaPlayer.setVolume(volume, volume);
mediaPlayer.start();

mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
Expand Down
8 changes: 7 additions & 1 deletion ios/Classes/AudioplayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
result(0);
if (call.arguments[@"isLocal"]==nil)
result(0);
if (call.arguments[@"volume"]==nil)
result(0);
int isLocal = [call.arguments[@"isLocal"]intValue] ;
float volume = (float)[call.arguments[@"volume"] doubleValue] ;
NSLog(@"isLocal: %d %@",isLocal, call.arguments[@"isLocal"] );
[self togglePlay:playerId url:url isLocal:isLocal];
NSLog(@"volume: %f %@",volume, call.arguments[@"volume"] );
[self togglePlay:playerId url:url isLocal:isLocal volume:volume];
},
@"pause":
^{
Expand Down Expand Up @@ -104,6 +108,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
-(void) togglePlay: (NSString*) playerId
url: (NSString*) url
isLocal: (int) isLocal
volume: (float) volume
{
NSMutableDictionary * playerInfo = players[playerId];
AVPlayer *player = playerInfo[@"player"];
Expand Down Expand Up @@ -167,6 +172,7 @@ -(void) togglePlay: (NSString*) playerId
[ self pause:playerId ];
} else {
[ self updateDuration:playerId ];
[ player setVolume:volume ];
[ player play];
[playerInfo setObject:@true forKey:@"isPlaying"];
}
Expand Down
168 changes: 0 additions & 168 deletions ios/Classes/SwiftAudioplayerPlugin.swift

This file was deleted.

6 changes: 3 additions & 3 deletions lib/audioplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AudioPlayer {
static final MethodChannel _channel = const MethodChannel('bz.rxla.flutter/audio')..setMethodCallHandler(platformCallHandler);
static final uuid = new Uuid();
static final players = new Map<String, AudioPlayer>();
static var logEnabled = true;
static var logEnabled = false;

TimeChangeHandler durationHandler;
TimeChangeHandler positionHandler;
Expand All @@ -24,8 +24,8 @@ class AudioPlayer {
players[playerId] = this;
}

Future<int> play(String url, {bool isLocal: false}) =>
_channel.invokeMethod('play', {"playerId": playerId, "url": url, "isLocal": isLocal});
Future<int> play(String url, {bool isLocal: false, double volume: 1.0}) =>
_channel.invokeMethod('play', {"playerId": playerId, "url": url, "isLocal": isLocal, 'volume': volume});

Future<int> pause() => _channel.invokeMethod('pause', {"playerId": playerId});

Expand Down

0 comments on commit 4e9d9e8

Please sign in to comment.