Skip to content

Commit

Permalink
document updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mehranshoqi committed Dec 6, 2023
1 parent 459ad0a commit 2f1f5f0
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 187 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## 2.0.0
## 2.1.2
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class MyApp extends StatelessWidget {
maxDuration: const Duration(seconds: 10),
isFile: false,
onComplete: () {
print('onComplete');
/// do something on complete
},
onPause: () {
print('onPause');
/// do something on pause
},
onPlaying: () {
print('onPlaying');
/// do something on playing
},
),
innerPadding: 12,
Expand Down
2 changes: 1 addition & 1 deletion example/lib/widgets/bubble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '../helpers/style.dart';
///
// ignore: must_be_immutable
class Bubble extends StatelessWidget {
Bubble({
const Bubble({
required this.me,
required this.index,
Key? key,
Expand Down
10 changes: 5 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,18 @@ packages:
dependency: transitive
description:
name: syncfusion_flutter_core
sha256: "3979f0b1c5a97422cadae52d476c21fa3e0fb671ef51de6cae1d646d8b99fe1f"
sha256: "88366a5e95ccb4091feb531021567f76ed3ceddab7424de02a9ac4a335d22a44"
url: "https://pub.dev"
source: hosted
version: "20.4.54"
version: "23.2.6"
syncfusion_flutter_sliders:
dependency: transitive
description:
name: syncfusion_flutter_sliders
sha256: "13a3931ef2d61b94442ce1c7745702f143f2866e3c9b71cb99e08667dba0b327"
sha256: c1a8c74167b7962072244e82f7048684eff62523e55b5e5f25447c3bf1fb91f4
url: "https://pub.dev"
source: hosted
version: "20.4.54"
version: "23.2.6"
term_glyph:
dependency: transitive
description:
Expand Down Expand Up @@ -371,7 +371,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.0"
version: "2.1.2"
web:
dependency: transitive
description:
Expand Down
10 changes: 0 additions & 10 deletions lib/src/helpers/colors.dart

This file was deleted.

4 changes: 4 additions & 0 deletions lib/src/helpers/play_status.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/// PlayStatus enum.
enum PlayStatus { init, playing, pause, stop, downloading, downloadError }

/// PlaySpeed enum.
enum PlaySpeed { x1, x1_25, x1_5, x1_75, x2, x2_25 }

/// Get the speed of the voice playback.
extension GetSpeed on PlaySpeed {
double get getSpeed {
switch (this) {
Expand All @@ -20,6 +23,7 @@ extension GetSpeed on PlaySpeed {
}
}

/// Get the speed of the voice playback.
String get playSpeedStr {
switch (this) {
case PlaySpeed.x1:
Expand Down
64 changes: 0 additions & 64 deletions lib/src/helpers/style.dart

This file was deleted.

5 changes: 4 additions & 1 deletion lib/src/helpers/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'package:flutter/material.dart';

/// Get screen media.
final MediaQueryData media =
MediaQueryData.fromWindow(WidgetsBinding.instance.window);
// ignore: deprecated_member_use
MediaQueryData.fromView(WidgetsBinding.instance.window);

/// This extention help us to make widget responsive.
extension NumberParsing on num {
Expand All @@ -11,12 +12,14 @@ extension NumberParsing on num {
double h() => this * media.size.height / 100;
}

///
extension StringExtension on String {
String? get appendZeroPrefix {
return length <= 1 ? "0$this" : this;
}
}

/// This extention help us to make widget responsive.
extension DurationExtension on Duration {
String get formattedTime {
int sec = inSeconds % 60;
Expand Down
19 changes: 0 additions & 19 deletions lib/src/helpers/widgets.dart

This file was deleted.

39 changes: 28 additions & 11 deletions lib/src/voice_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import 'dart:async';
import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:just_audio/just_audio.dart';
import 'package:voice_message_package/src/helpers/play_status.dart';
import 'package:voice_message_package/src/helpers/utils.dart';

/// A controller for managing voice playback.
///
/// The [VoiceController] class provides functionality for playing, pausing, stopping, and seeking voice playback.
Expand All @@ -18,17 +28,6 @@
/// },
/// );
///
import 'dart:async';
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:just_audio/just_audio.dart';
import 'package:voice_message_package/src/helpers/play_status.dart';
import 'package:voice_message_package/src/helpers/utils.dart';
class VoiceController extends MyTicker {
final String audioSrc;
late Duration maxDuration;
Expand All @@ -47,6 +46,7 @@ class VoiceController extends MyTicker {
StreamSubscription? positionStream;
StreamSubscription? playerStateStream;
/// Gets the current playback position of the voice.
double get currentMillSeconds {
final c = currentDuration.inMilliseconds.toDouble();
if (c >= maxMillSeconds) {
Expand All @@ -71,6 +71,7 @@ class VoiceController extends MyTicker {
double get maxMillSeconds => maxDuration.inMilliseconds.toDouble();
/// Creates a new [VoiceController] instance.
VoiceController({
required this.audioSrc,
required this.maxDuration,
Expand All @@ -91,6 +92,7 @@ class VoiceController extends MyTicker {
_listenToPlayerState();
}
/// Initializes the voice controller.
Future init() async {
await setMaxDuration(audioSrc);
_updateUi();
Expand Down Expand Up @@ -132,11 +134,13 @@ class VoiceController extends MyTicker {
updater.notifyListeners();
}
/// Stops playing the voice.
Future stopPlaying() async {
_player.pause();
playStatus = PlayStatus.stop;
}
/// Starts playing the voice.
Future startPlaying(String path) async {
Uri audioUri = isFile ? Uri.file(audioSrc) : Uri.parse(audioSrc);
await _player.setAudioSource(
Expand All @@ -154,20 +158,23 @@ class VoiceController extends MyTicker {
animController.dispose();
}
/// Seeks to the given [duration].
void onSeek(Duration duration) {
isSeeking = false;
currentDuration = duration;
_updateUi();
_player.seek(duration);
}
/// Pauses the voice playback.
void pausePlaying() {
_player.pause();
playStatus = PlayStatus.pause;
_updateUi();
onPause();
}
/// Resumes the voice playback.
void _listenToPlayerState() {
playerStateStream = _player.playerStateStream.listen((event) async {
if (event.processingState == ProcessingState.completed) {
Expand Down Expand Up @@ -211,8 +218,11 @@ class VoiceController extends MyTicker {
_updateUi();
}
/// Changes the speed of the voice playback.
void onChangeSliderStart(double value) {
isSeeking = true;
/// pause the voice
pausePlaying();
}
Expand All @@ -223,13 +233,15 @@ class VoiceController extends MyTicker {
}
}
/// Changes the speed of the voice playback.
void onChanging(double d) {
currentDuration = Duration(milliseconds: d.toInt());
final value = (noiseWidth * d) / maxMillSeconds;
animController.value = value;
_updateUi();
}
///
String get remindingTime {
if (currentDuration == Duration.zero) {
return maxDuration.formattedTime;
Expand All @@ -243,8 +255,10 @@ class VoiceController extends MyTicker {
return currentDuration.formattedTime;
}
/// Sets the maximum duration of the voice.
Future setMaxDuration(String path) async {
try {
/// get the max duration from the path or cloud
final maxDuration =
isFile ? await _player.setFilePath(path) : await _player.setUrl(path);
if (maxDuration != null) {
Expand All @@ -253,6 +267,7 @@ class VoiceController extends MyTicker {
}
} catch (err) {
if (kDebugMode) {
///
debugPrint("cant get the max duration from the path $path");
}
}
Expand All @@ -277,6 +292,8 @@ class VoiceController extends MyTicker {
/// It can be used to create animations or perform actions at regular intervals.
class MyTicker extends TickerProvider {
@override
/// Creates a new ticker.
Ticker createTicker(TickerCallback onTick) {
return Ticker(onTick);
}
Expand Down
Loading

0 comments on commit 2f1f5f0

Please sign in to comment.