Initial commit

This commit is contained in:
admin1
2026-07-14 11:11:36 +08:00
commit 656499cf94
604 changed files with 119518 additions and 0 deletions
@@ -0,0 +1,65 @@
import 'dart:async';
import 'package:flutter/services.dart';
class SystemVolumeEvent {
final int current;
final int max;
const SystemVolumeEvent({required this.current, required this.max});
double get percent => max == 0 ? 0 : current / max;
}
class SystemAudioController {
static const _methodChannel = MethodChannel('smplayer/system_audio');
static const _eventChannel = EventChannel('smplayer/system_audio_events');
SystemAudioController._();
static final SystemAudioController instance = SystemAudioController._();
Stream<SystemVolumeEvent>? _volumeChanges;
Stream<SystemVolumeEvent> get volumeChanges {
_volumeChanges ??= _eventChannel.receiveBroadcastStream().map((event) {
final map = (event as Map).cast<Object?, Object?>();
return SystemVolumeEvent(
current: (map['current'] as num).toInt(),
max: (map['max'] as num).toInt(),
);
});
return _volumeChanges!;
}
Future<SystemVolumeEvent> getVolume() async {
final result = await _methodChannel.invokeMapMethod<String, dynamic>(
'getVolume',
);
if (result == null) {
return const SystemVolumeEvent(current: 0, max: 15);
}
return SystemVolumeEvent(
current: (result['current'] as num).toInt(),
max: (result['max'] as num).toInt(),
);
}
Future<SystemVolumeEvent> adjustVolume(int delta) async {
final result = await _methodChannel.invokeMapMethod<String, dynamic>(
'adjustVolume',
{'delta': delta},
);
if (result == null) {
return const SystemVolumeEvent(current: 0, max: 15);
}
return SystemVolumeEvent(
current: (result['current'] as num).toInt(),
max: (result['max'] as num).toInt(),
);
}
Future<void> setKeyIntercept(bool enabled) async {
await _methodChannel.invokeMethod<void>('setKeyIntercept', {
'enabled': enabled,
});
}
}