-
Notifications
You must be signed in to change notification settings - Fork 162
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
feat: ✨ Add a method to pause all players at once #372
base: main
Are you sure you want to change the base?
Conversation
@@ -140,15 +140,16 @@ class AudioPlayer( | |||
} | |||
|
|||
|
|||
fun pause(result: MethodChannel.Result) { | |||
fun pause(result: MethodChannel.Result, isPauseAllPlayer: Boolean = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this boolean?
ios/Classes/AudioPlayer.swift
Outdated
@@ -91,10 +91,12 @@ class AudioPlayer: NSObject, AVAudioPlayerDelegate { | |||
} | |||
|
|||
|
|||
func pausePlayer(result: @escaping FlutterResult) { | |||
func pausePlayer(result: @escaping FlutterResult, isPauseAllPlayer: Bool = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^
26deec9
to
ef20485
Compare
ef20485
to
ba326d8
Compare
```dart | ||
playerController.pauseAllPlayers(); | ||
``` | ||
There could be any number of players but you can just call this function from any **one** player and it will pause all the players. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just write, this function works similar to stopAllPlayer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jay-simformsolutions update to this this function works similar to stopAllPlayer but just pauses all players.
example/lib/main.dart
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this changes
stopListening() | ||
player?.pause() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add try catch
@@ -129,26 +129,19 @@ class AudioPlayer( | |||
} | |||
} | |||
|
|||
fun stop(result: MethodChannel.Result) { | |||
fun stop() { | |||
stopListening() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add try catch
.forEach((playKey, controller) { | ||
controller._setPlayerState(PlayerState.stopped); | ||
}); | ||
} | ||
PlatformStreams.instance.playerControllerFactory.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont need clear since we aren't releasing player.
pubspec.yaml
Outdated
@@ -1,6 +1,6 @@ | |||
name: audio_waveforms | |||
description: A Flutter package that allow you to generate waveform while recording audio or from audio file. | |||
version: 1.2.0 | |||
version: 1.2.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update to 1.3.0
ba326d8
to
e9850d7
Compare
@@ -3,6 +3,8 @@ | |||
- Fixed [#386](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/pull/386) - On permission denied isRecording flag changed | |||
- Fixed [#384](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/384) - Provide a callback of drag,tap,start and end details on user gesture | |||
- Fixed [#309](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/309) - Added support for Liner PCM codec in iOS | |||
- Fixes [#325](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues/325) - Added feature to pause all player controller at once. | |||
- Fixes [#379](https://github.com/SimformSolutionsPvtLtd/audio_waveforms/pull/379) - Getting error on dispose(Cannot add new events after calling close) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use issue link.
```dart | ||
playerController.pauseAllPlayers(); | ||
``` | ||
There could be any number of players but you can just call this function from any **one** player and it will pause all the players. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jay-simformsolutions update to this this function works similar to stopAllPlayer but just pauses all players.
@@ -102,7 +102,8 @@ class AudioWaveformsPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { | |||
Constants.stopPlayer -> { | |||
val key = call.argument(Constants.playerKey) as String? | |||
if (key != null) { | |||
audioPlayers[key]?.stop(result) | |||
audioPlayers[key]?.stop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add try catch
@@ -111,7 +112,8 @@ class AudioWaveformsPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { | |||
Constants.pausePlayer -> { | |||
val key = call.argument(Constants.playerKey) as String? | |||
if (key != null) { | |||
audioPlayers[key]?.pause(result) | |||
audioPlayers[key]?.pause() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add try catch
} | ||
result.success(true) | ||
} catch (e: Exception) { | ||
result.error(Constants.LOG_TAG, "Failed to pause player", e.message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.error(Constants.LOG_TAG, "Failed to pause player", e.message) | |
result.error(Constants.LOG_TAG, "Failed to pause players", e.message) |
} | ||
result.success(true) | ||
} catch (e: Exception) { | ||
result.error(Constants.LOG_TAG, "Failed to stop player", e.message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.error(Constants.LOG_TAG, "Failed to stop player", e.message) | |
result.error(Constants.LOG_TAG, "Failed to stop players", e.message) |
@@ -152,7 +152,7 @@ class _WaveBubbleState extends State<WaveBubble> { | |||
IconButton( | |||
onPressed: () async { | |||
controller.playerState.isPlaying | |||
? await controller.pausePlayer() | |||
? await controller.stopAllPlayers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this change
@@ -318,10 +318,32 @@ class PlayerController extends ChangeNotifier { | |||
/// | |||
/// This method will close the stream and free resources taken by all | |||
/// players. This method will not dispose controller. | |||
Future<void> stopAllPlayers() async { | |||
/// | |||
/// Returns true if all player stopped otherwise return false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check grammar
return isAllPlayersStopped; | ||
} | ||
|
||
/// This function works similar to stopAllPlayer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This function works similar to stopAllPlayer. | |
/// Pauses all the players. Works similar to stopAllPlayer. |
Fixed 325