-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76d71e1
commit a45f184
Showing
8 changed files
with
530 additions
and
161 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
lib/features/audio/data/repositories/audio_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// import 'dart:io'; | ||
// import 'package:flutter_sound/flutter_sound.dart'; | ||
// import 'package:path_provider/path_provider.dart'; | ||
|
||
// class AudioRepository { | ||
// final FlutterSoundRecorder _recorder = FlutterSoundRecorder(); | ||
// final FlutterSoundPlayer _player = FlutterSoundPlayer(); | ||
// String? filePath; | ||
|
||
// Future<void> startRecording() async { | ||
// Directory tempDir = await getApplicationDocumentsDirectory(); | ||
// filePath = "${tempDir.path}/audio_${DateTime.now().millisecondsSinceEpoch}.aac"; | ||
|
||
// await _recorder.openRecorder(); | ||
// await _recorder.startRecorder(toFile: filePath); | ||
// } | ||
|
||
// Future<void> stopRecording() async { | ||
// await _recorder.stopRecorder(); | ||
// } | ||
|
||
// Future<List<File>> getAllRecordings() async { | ||
// Directory dir = await getApplicationDocumentsDirectory(); | ||
// return dir.listSync().whereType<File>().toList(); | ||
// } | ||
|
||
// Future<void> playAudio(File file) async { | ||
// await _player.openPlayer(); | ||
// await _player.startPlayer(fromURI: file.path); | ||
// } | ||
|
||
// Future<void> stopPlayback() async { | ||
// await _player.stopPlayer(); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/features/audio/presentation/providers/audio_recorder_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
lib/features/audio/presentation/screens/audio_list_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// lib/features/audio/presentation/pages/audio_list_page.dart | ||
class AudioListPage extends ConsumerWidget { | ||
const AudioListPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Recorded Sermons'), | ||
backgroundColor: Theme.of(context).primaryColor, | ||
actions: [ | ||
IconButton( | ||
icon: const Icon(Icons.add), | ||
onPressed: () => Navigator.push( | ||
context, | ||
MaterialPageRoute(builder: (_) => const RecordAudioPage()), | ||
), | ||
), | ||
], | ||
), | ||
body: StreamBuilder<QuerySnapshot>( | ||
stream: FirebaseFirestore.instance.collection('Devotion').snapshots(), | ||
builder: (context, snapshot) { | ||
if (snapshot.hasError) { | ||
return const Center(child: Text('Something went wrong')); | ||
} | ||
|
||
if (snapshot.connectionState == ConnectionState.waiting) { | ||
return const Center(child: CircularProgressIndicator()); | ||
} | ||
|
||
final recordings = snapshot.data?.docs ?? []; | ||
|
||
return ListView.builder( | ||
padding: const EdgeInsets.all(8), | ||
itemCount: recordings.length, | ||
itemBuilder: (context, index) { | ||
final recording = AudioFile.fromJson( | ||
recordings[index].data() as Map<String, dynamic> | ||
); | ||
|
||
return Card( | ||
margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 8), | ||
child: ListTile( | ||
leading: const CircleAvatar( | ||
child: Icon(Icons.audio_file), | ||
), | ||
title: Text(recording.title), | ||
subtitle: Text(recording.scripture ?? ''), | ||
trailing: IconButton( | ||
icon: const Icon(Icons.play_arrow), | ||
onPressed: () { | ||
// Navigate to audio player page | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (_) => AudioPlayerPage(audioFile: recording), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
lib/features/audio/presentation/screens/audio_player_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import 'package:devotion/features/audio/data/models/audio_model.dart'; | ||
import 'package:devotion/features/audio/presentation/providers/audio_player_provider.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class AudioPlayerPage extends ConsumerStatefulWidget { | ||
final AudioFile audioFile; | ||
|
||
const AudioPlayerPage({required this.audioFile, super.key}); | ||
|
||
@override | ||
_AudioPlayerPageState createState() => _AudioPlayerPageState(); | ||
} | ||
|
||
class _AudioPlayerPageState extends ConsumerState<AudioPlayerPage> { | ||
@override | ||
Widget build(BuildContext context) { | ||
final playerState = ref.watch(audioPlayerProvider); | ||
|
||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(widget.audioFile.title), | ||
backgroundColor: Theme.of(context).primaryColor, | ||
), | ||
body: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Card( | ||
elevation: 4, | ||
child: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
children: [ | ||
Text( | ||
widget.audioFile.title, | ||
style: Theme.of(context).textTheme.headlineSmall, | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 8), | ||
Text( | ||
widget.audioFile.scripture ?? '', | ||
style: Theme.of(context).textTheme.bodyLarge, | ||
), | ||
const SizedBox(height: 24), | ||
Slider( | ||
value: playerState.position.inSeconds.toDouble(), | ||
max: playerState.duration.inSeconds.toDouble(), | ||
onChanged: (value) { | ||
ref.read(audioPlayerProvider.notifier) | ||
.seekTo(Duration(seconds: value.toInt())); | ||
}, | ||
), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
Text(_formatDuration(playerState.position)), | ||
Text(_formatDuration(playerState.duration)), | ||
], | ||
), | ||
const SizedBox(height: 16), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
IconButton( | ||
icon: const Icon(Icons.replay_10), | ||
onPressed: () => ref.read(audioPlayerProvider.notifier) | ||
.seekTo(playerState.position - const Duration(seconds: 10)), | ||
), | ||
FloatingActionButton( | ||
onPressed: () => playerState.isPlaying | ||
? ref.read(audioPlayerProvider.notifier).pause() | ||
: ref.read(audioPlayerProvider.notifier).play(), | ||
child: Icon( | ||
playerState.isPlaying ? Icons.pause : Icons.play_arrow, | ||
), | ||
), | ||
IconButton( | ||
icon: const Icon(Icons.forward_10), | ||
onPressed: () => ref.read(audioPlayerProvider.notifier) | ||
.seekTo(playerState.position + const Duration(seconds: 10)), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.