Skip to content

Commit

Permalink
Upgrade the flutter version (SimformSolutionsPvtLtd#278)
Browse files Browse the repository at this point in the history
Update flutter version
  • Loading branch information
himanshuGandhiSimform authored Mar 14, 2024
1 parent 2954a35 commit 8e57aa1
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ class AudioPlayer(
private var isPlayerPrepared: Boolean = false
private var finishMode = FinishMode.Stop
private var key = playerKey
private var updateFrequency = UpdateFrequency.Low
private var updateFrequency:Long = 200

fun preparePlayer(
result: MethodChannel.Result,
path: String?,
volume: Float?,
frequency: UpdateFrequency,
frequency: Long?,
) {
if (path != null) {
updateFrequency = frequency
frequency?.let {
updateFrequency = it
}
val uri = Uri.parse(path)
val mediaItem = MediaItem.fromUri(uri)
player = ExoPlayer.Builder(appContext).build()
Expand Down Expand Up @@ -191,7 +193,7 @@ class AudioPlayer(
args[Constants.current] = currentPosition
args[Constants.playerKey] = key
methodChannel.invokeMethod(Constants.onCurrentDuration, args)
handler.postDelayed(this, updateFrequency.value)
handler.postDelayed(this, updateFrequency)
} else {
result.error(Constants.LOG_TAG, "Can't get current Position of player", "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class AudioWaveformsPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
if (key != null) {
initPlayer(key)
audioPlayers[key]?.preparePlayer(
result,
audioPath,
volume?.toFloat(),
getUpdateFrequency(frequency),
result,
audioPath,
volume?.toFloat(),
frequency?.toLong(),
)
} else {
result.error(Constants.LOG_TAG, "Player key can't be null", "")
Expand Down Expand Up @@ -246,15 +246,6 @@ class AudioWaveformsPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
return
}

private fun getUpdateFrequency(frequency: Int?): UpdateFrequency {
if (frequency == 2) {
return UpdateFrequency.High
} else if (frequency == 1) {
return UpdateFrequency.Medium
}
return UpdateFrequency.Low
}

private fun createOrUpdateExtractor(
playerKey: String,
noOfSamples: Int,
Expand Down
6 changes: 0 additions & 6 deletions android/src/main/kotlin/com/simform/audio_waveforms/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ enum class FinishMode(val value:Int) {
Stop(2)
}

enum class UpdateFrequency(val value:Long) {
High(50),
Medium(100),
Low(200),
}

fun interface RequestPermissionsSuccessCallback {
fun onSuccess(results: Boolean?)
}
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Demonstrates how to use the audio_waveforms plugin.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=3.1.0 <4.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
8 changes: 4 additions & 4 deletions ios/Classes/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AudioPlayer: NSObject, AVAudioPlayerDelegate {
private var timer: Timer?
private var player: AVAudioPlayer?
private var finishMode: FinishMode = FinishMode.stop
private var updateFrequency = UpdateFrequency.low
private var updateFrequency = 200
var plugin: SwiftAudioWaveformsPlugin
var playerKey: String
var flutterChannel: FlutterMethodChannel
Expand All @@ -20,9 +20,9 @@ class AudioPlayer: NSObject, AVAudioPlayerDelegate {
flutterChannel = channel
}

func preparePlayer(path: String?, volume: Double?, updateFrequency: UpdateFrequency,result: @escaping FlutterResult) {
func preparePlayer(path: String?, volume: Double?, updateFrequency: Int?,result: @escaping FlutterResult) {
if(!(path ?? "").isEmpty) {
self.updateFrequency = updateFrequency
self.updateFrequency = updateFrequency ?? 200
let audioUrl = URL.init(string: path!)
if(audioUrl == nil){
result(FlutterError(code: Constants.audioWaveforms, message: "Failed to initialise Url from provided audio file", details: "If path contains `file://` try removing it"))
Expand Down Expand Up @@ -128,7 +128,7 @@ class AudioPlayer: NSObject, AVAudioPlayerDelegate {

func startListening() {
if #available(iOS 10.0, *) {
timer = Timer.scheduledTimer(withTimeInterval: (updateFrequency.rawValue / 1000), repeats: true, block: { _ in
timer = Timer.scheduledTimer(withTimeInterval: (Double(updateFrequency) / 1000), repeats: true, block: { _ in
let ms = (self.player?.currentTime ?? 0) * 1000
self.flutterChannel.invokeMethod(Constants.onCurrentDuration, arguments: [Constants.current: Int(ms), Constants.playerKey: self.playerKey])
})
Expand Down
10 changes: 1 addition & 9 deletions ios/Classes/SwiftAudioWaveformsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class SwiftAudioWaveformsPlugin: NSObject, FlutterPlugin {
initPlayer(playerKey: key!)
audioPlayers[key!]?.preparePlayer(path: args?[Constants.path] as? String,
volume: args?[Constants.volume] as? Double,
updateFrequency: getUpdateFrequency(freq: args?[Constants.updateFrequency] as? Int) ,
updateFrequency: args?[Constants.updateFrequency] as? Int,
result: result)
} else {
result(FlutterError(code: Constants.audioWaveforms, message: "Can not prepare player", details: "Player key is null"))
Expand Down Expand Up @@ -145,14 +145,6 @@ public class SwiftAudioWaveformsPlugin: NSObject, FlutterPlugin {
}
}

func getUpdateFrequency(freq: Int?) -> UpdateFrequency{
if(freq == 2){
return UpdateFrequency.high
} else if(freq == 1){
return UpdateFrequency.medium
}
return UpdateFrequency.low
}

func initPlayer(playerKey: String) {
if audioPlayers[playerKey] == nil {
Expand Down
5 changes: 0 additions & 5 deletions ios/Classes/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ enum FinishMode : Int{
case stop = 2
}

enum UpdateFrequency : Double{
case high = 50.0
case medium = 100.0
case low = 200.0
}
/// Creates an 2D array of floats
public typealias FloatChannelData = [[Float]]

Expand Down
3 changes: 0 additions & 3 deletions lib/src/audio_waveforms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ class _AudioWaveformsState extends State<AudioWaveforms> {
_totalBackDistance = Offset.zero;
_dragOffset = Offset.zero;
}
ambiguate(WidgetsBinding.instance)?.addPostFrameCallback((_) {
setState(() {});
});
}

void _recorderControllerListener() {
Expand Down
12 changes: 6 additions & 6 deletions lib/src/base/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ enum FinishMode {
stop
}

// TODO: remove this function if we remove support for flutter 2.x
T? ambiguate<T>(T? object) => object;

/// An enum to decide which type of waveform to show.
enum WaveformType {
/// Fits Waveform in provided width. Audio can be seeked with
Expand Down Expand Up @@ -190,11 +187,14 @@ extension RecorderStateExtension on RecorderState {
/// Rate of updating the reported current duration.
enum UpdateFrequency {
/// Reports duration at every 50 milliseconds.
high,
high(50),

/// Reports duration at every 100 milliseconds.
medium,
medium(100),

/// Reports duration at every 200 milliseconds.
low
low(200);

const UpdateFrequency(this.value);
final int value;
}
14 changes: 1 addition & 13 deletions lib/src/controllers/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class PlayerController extends ChangeNotifier {
final isPrepared = await AudioWaveformsInterface.instance.preparePlayer(
path: path,
key: playerKey,
frequency: _getFrequency(),
frequency: updateFrequency.value,
volume: volume,
);
if (isPrepared) {
Expand Down Expand Up @@ -310,18 +310,6 @@ class PlayerController extends ChangeNotifier {
notifyListeners();
}

// TODO: Replace this with enhanced enum when we drop support for dart 2.17 earlier versions
int _getFrequency() {
switch (updateFrequency) {
case UpdateFrequency.high:
return 2;
case UpdateFrequency.medium:
return 1;
case UpdateFrequency.low:
return 0;
}
}

@override
void notifyListeners() {
if (_isDisposed) return;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/controllers/recorder_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class RecorderController extends ChangeNotifier {

/// Sets [shouldClearLabels] flag to false.
void revertClearLabelCall() {
ambiguate(WidgetsBinding.instance)?.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
shouldClearLabels = false;
notifyListeners();
});
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ homepage: https://github.com/SimformSolutionsPvtLtd/audio_waveforms
issue_tracker: https://github.com/SimformSolutionsPvtLtd/audio_waveforms/issues

environment:
sdk: ">=2.12.0 <4.0.0"
flutter: ">=1.20.0"
sdk: ">=3.1.0 <4.0.0"
flutter: ">=3.0.0"

dependencies:
flutter:
Expand Down

0 comments on commit 8e57aa1

Please sign in to comment.