Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mehranshoqi committed Dec 6, 2023
1 parent 89489c3 commit 459ad0a
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 11 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ All you need is pass your audio file src to VoiceMessage widget:

Licensed under the MIT license. See [LICENSE](https://github.com/mehranshoqi/voice_message_player/blob/master/LICENSE "LICENSE").


## Me

:pushpin:Find me at [Portfolio](https://mehran.monster)
:pushpin:Find me at [www.mehran.monster](https://mehran.monster)



Expand Down
41 changes: 40 additions & 1 deletion lib/src/voice_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/// A controller for managing voice playback.
///
/// The [VoiceController] class provides functionality for playing, pausing, stopping, and seeking voice playback.
/// It uses the [just_audio](https://pub.dev/packages/just_audio) package for audio playback.
/// The controller also supports changing the playback speed and provides UI updates through a [ValueNotifier].
///
/// Example usage:
/// ```dart
/// VoiceController voiceController = VoiceController(
/// audioSrc: 'path/to/audio.mp3',
/// maxDuration: Duration(minutes: 5),
/// isFile: true,
/// onComplete: () {
/// },
/// onPause: () {
/// },
/// onPlaying: () {
/// },
/// );
///
import 'dart:async';
import 'dart:math';
Expand Down Expand Up @@ -107,6 +128,7 @@ class VoiceController extends MyTicker {
}
void _updateUi() {
// ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
updater.notifyListeners();
}
Expand Down Expand Up @@ -162,7 +184,9 @@ class VoiceController extends MyTicker {
});
}
/// Changes the speed of the voice playback.
void changeSpeed() {
// Function implementation goes here
switch (speed) {
case PlaySpeed.x1:
speed = PlaySpeed.x1_25;
Expand Down Expand Up @@ -227,7 +251,6 @@ class VoiceController extends MyTicker {
this.maxDuration = maxDuration;
animController.duration = maxDuration;
}

} catch (err) {
if (kDebugMode) {
debugPrint("cant get the max duration from the path $path");
Expand All @@ -236,6 +259,22 @@ class VoiceController extends MyTicker {
}
}
/// A custom [TickerProvider] implementation for the voice controller.
///
/// This class provides the necessary functionality for controlling the voice playback.
/// It implements the [TickerProvider] interface, allowing it to create [Ticker] objects
/// that can be used to schedule animations or other periodic tasks.
///
/// Example usage:
/// ```dart
/// VoiceController voiceController = VoiceController();
/// voiceController.start();
/// voiceController.stop();
/// ```
///
/// This class extends [TickerProvider] and provides a custom ticker for the voice controller.
/// It can be used to create animations or perform actions at regular intervals.
class MyTicker extends TickerProvider {
@override
Ticker createTicker(TickerCallback onTick) {
Expand Down
17 changes: 16 additions & 1 deletion lib/src/voice_message_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import 'package:voice_message_package/src/voice_controller.dart';
import 'package:voice_message_package/src/widgets/noises.dart';
import 'package:voice_message_package/src/widgets/play_pause_button.dart';

/// A widget that displays a voice message view with play/pause functionality.
///
/// The [VoiceMessageView] widget is used to display a voice message with customizable appearance and behavior.
/// It provides a play/pause button, a progress slider, and a counter for the remaining time.
/// The appearance of the widget can be customized using various properties such as background color, slider color, and text styles.
///
class VoiceMessageView extends StatelessWidget {
const VoiceMessageView({
Key? key,
Expand Down Expand Up @@ -154,9 +160,18 @@ class VoiceMessageView extends StatelessWidget {
}

///
/// A custom track shape for a slider that is rounded rectangular in shape.
/// Extends the [RoundedRectSliderTrackShape] class.
class CustomTrackShape extends RoundedRectSliderTrackShape {
///
@override

/// Returns the preferred rectangle for the voice message view.
///
/// The preferred rectangle is calculated based on the current state and layout
/// of the voice message view. It represents the area where the view should be
/// displayed on the screen.
///
/// Returns a [Rect] object representing the preferred rectangle.
Rect getPreferredRect({
required RenderBox parentBox,
Offset offset = Offset.zero,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/widgets/noises.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'package:flutter/material.dart';
import 'package:voice_message_package/src/widgets/single_noise.dart';

/// A widget that represents a collection of noises.
///
/// This widget is used to display a collection of noises in the UI.
/// It is typically used in the context of a voice message player.
class Noises extends StatelessWidget {
const Noises({
super.key,
Expand Down
16 changes: 15 additions & 1 deletion lib/src/widgets/play_pause_button.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:voice_message_package/src/widgets/loading_widget.dart';
import 'package:voice_message_package/voice_message_package.dart';

/// A widget representing a play/pause button.
///
/// This button can be used to control the playback of a media player.
class PlayPauseButton extends StatelessWidget {

const PlayPauseButton({
super.key,
required this.controller,
Expand All @@ -18,8 +21,12 @@ class PlayPauseButton extends StatelessWidget {
@override
Widget build(BuildContext context) => InkWell(
onTap: controller.isDownloadError

/// faild loading audio
? controller.play
: controller.isPlaying

/// playing or pause
? controller.pausePlaying
: controller.play,
child: Container(
Expand All @@ -29,11 +36,18 @@ class PlayPauseButton extends StatelessWidget {
child: controller.isDownloading
? const LoadingWidget()
: Icon(
/// faild to load audio
controller.isDownloadError

/// show refresh icon
? Icons.refresh

/// playing or pause
: controller.isPlaying
? Icons.pause_rounded
: Icons.play_arrow_rounded,

/// icon color
color: Colors.white,
),
),
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: voice_message_package
description: Flutter package to play/puase voice message in chat messengers.
version: 2.1.0
homepage: https://github.com/mehranshoqi/voice_message_player
version: 2.1.1
homepage: https://mehran.monster/htmls/voicey.html

environment:
sdk: ">=2.17.0 <4.0.0"
Expand All @@ -10,8 +10,8 @@ environment:
dependencies:
flutter:
sdk: flutter
just_audio: ^0.9.31
syncfusion_flutter_sliders: ^20.4.51
just_audio: ^0.9.36
syncfusion_flutter_sliders: ^23.2.6

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 459ad0a

Please sign in to comment.