Functioning music player features
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
1 parent
357e6e17cc
commit
34476a56da
9 files changed
+161
-98
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
|
||||
class StreamingAudioBusinessObject extends ChangeNotifier {
|
||||
StreamingAudioBusinessObject({
|
||||
this.streamUrl = 'https://kryz.out.airtime.pro/kryz_a',
|
||||
}) {
|
||||
_playerStateSubscription = _player.playerStateStream.listen((state) {
|
||||
final isCurrentlyPlaying =
|
||||
state.playing && state.processingState != ProcessingState.completed;
|
||||
|
||||
if (_isPlaying != isCurrentlyPlaying) {
|
||||
_isPlaying = isCurrentlyPlaying;
|
||||
notifyListeners();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final String streamUrl;
|
||||
final AudioPlayer _player = AudioPlayer();
|
||||
late final StreamSubscription<PlayerState> _playerStateSubscription;
|
||||
bool _isSourceLoaded = false;
|
||||
bool _isPlaying = false;
|
||||
|
||||
bool get isPlaying => _isPlaying;
|
||||
|
||||
Future<void> play() async {
|
||||
if (!_isSourceLoaded) {
|
||||
await _player.setUrl(streamUrl);
|
||||
_isSourceLoaded = true;
|
||||
}
|
||||
|
||||
await _player.play();
|
||||
}
|
||||
|
||||
Future<void> pause() async {
|
||||
await _player.pause();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_playerStateSubscription.cancel();
|
||||
_player.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user