Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume control from @pauldemarco #4

Merged
merged 4 commits into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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