2022-02-15 09:25:13 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_ringtone_player/flutter_ringtone_player.dart';
|
2022-03-13 07:54:44 +01:00
|
|
|
import 'package:just_audio/just_audio.dart';
|
2022-02-15 09:25:13 +01:00
|
|
|
|
2022-02-19 11:05:21 +01:00
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
|
|
|
|
2022-02-15 09:25:13 +01:00
|
|
|
class UserMediaManager {
|
|
|
|
factory UserMediaManager() {
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
UserMediaManager._internal();
|
|
|
|
|
|
|
|
static final UserMediaManager _instance = UserMediaManager._internal();
|
|
|
|
|
2022-03-13 07:54:44 +01:00
|
|
|
AudioPlayer? _assetsAudioPlayer;
|
2022-02-19 11:05:21 +01:00
|
|
|
|
|
|
|
Future<void> startRingingTone() async {
|
|
|
|
if (PlatformInfos.isMobile) {
|
|
|
|
await FlutterRingtonePlayer.playRingtone(volume: 80);
|
|
|
|
} else if ((kIsWeb || PlatformInfos.isMacOS) &&
|
|
|
|
_assetsAudioPlayer != null) {
|
|
|
|
const path = 'assets/sounds/phone.ogg';
|
2022-03-13 07:54:44 +01:00
|
|
|
final player = _assetsAudioPlayer = AudioPlayer();
|
|
|
|
player.setAsset(path);
|
|
|
|
player.play();
|
2022-02-15 09:25:13 +01:00
|
|
|
}
|
2022-02-19 11:05:21 +01:00
|
|
|
return;
|
2022-02-15 09:25:13 +01:00
|
|
|
}
|
|
|
|
|
2022-02-19 11:05:21 +01:00
|
|
|
Future<void> stopRingingTone() async {
|
|
|
|
if (PlatformInfos.isMobile) {
|
|
|
|
await FlutterRingtonePlayer.stop();
|
2022-02-15 09:25:13 +01:00
|
|
|
}
|
2022-02-19 11:05:21 +01:00
|
|
|
await _assetsAudioPlayer?.stop();
|
|
|
|
_assetsAudioPlayer = null;
|
|
|
|
return;
|
2022-02-15 09:25:13 +01:00
|
|
|
}
|
|
|
|
}
|