Files
driver_tripz/lib/controller/functions/audio_controller.dart
Hamza-Ayed 229646d664 10/26/1
2024-10-26 16:31:17 +03:00

30 lines
827 B
Dart

import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
import 'package:get/get.dart';
class AudioController extends GetxController {
final AudioPlayer _audioPlayer = AudioPlayer();
Future<void> playAudio() async {
// Check if the platform is Android
if (Theme.of(Get.context!).platform == TargetPlatform.android) {
try {
// Load the audio file from the raw resources
await _audioPlayer.setAsset(
'assets/order1.wav'); // Adjust the path based on your project structure
_audioPlayer.play();
} catch (e) {
// Handle errors, such as file not found
print('Error playing audio: $e');
}
}
}
@override
void onClose() {
// Release resources when done
_audioPlayer.dispose();
super.onClose();
}
}