introduced logging; AudioStore cleanup
This commit is contained in:
parent
e551879b1b
commit
be212b0d81
10 changed files with 59 additions and 98 deletions
|
@ -2,6 +2,7 @@ import 'package:audio_session/audio_session.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'injection_container.dart';
|
||||
|
@ -9,7 +10,6 @@ import 'presentation/pages/currently_playing.dart';
|
|||
import 'presentation/pages/home_page.dart';
|
||||
import 'presentation/pages/library_page.dart';
|
||||
import 'presentation/pages/settings_page.dart';
|
||||
import 'presentation/state/audio_store.dart';
|
||||
import 'presentation/state/navigation_store.dart';
|
||||
import 'presentation/theming.dart';
|
||||
import 'presentation/widgets/audio_service_widget.dart';
|
||||
|
@ -23,6 +23,10 @@ Future<void> main() async {
|
|||
final session = await AudioSession.instance;
|
||||
await session.configure(const AudioSessionConfiguration.music());
|
||||
|
||||
Logger.root.onRecord.listen((record) {
|
||||
print('${record.time} [${record.level.name}] ${record.loggerName}: ${record.message}');
|
||||
});
|
||||
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
|
@ -70,8 +74,6 @@ class _RootPageState extends State<RootPage> {
|
|||
|
||||
@override
|
||||
void dispose() {
|
||||
final AudioStore _audioStore = Provider.of<AudioStore>(context);
|
||||
_audioStore.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../domain/entities/song.dart';
|
||||
|
@ -14,9 +15,11 @@ import 'queue_page.dart';
|
|||
class CurrentlyPlayingPage extends StatelessWidget {
|
||||
const CurrentlyPlayingPage({Key key}) : super(key: key);
|
||||
|
||||
static final _log = Logger('CurrentlyPlayingPage');
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print('CurrentlyPlayingPage.build');
|
||||
_log.info('build started');
|
||||
final AudioStore audioStore = Provider.of<AudioStore>(context);
|
||||
|
||||
return Scaffold(
|
||||
|
@ -25,10 +28,8 @@ class CurrentlyPlayingPage extends StatelessWidget {
|
|||
builder: (BuildContext context, BoxConstraints constraints) =>
|
||||
Observer(
|
||||
builder: (BuildContext context) {
|
||||
print('CurrentlyPlayingPage.build -> Observer.build');
|
||||
final Song song = audioStore.song;
|
||||
|
||||
print(audioStore.queueIndexStream.value);
|
||||
_log.info('Observer.build');
|
||||
final Song song = audioStore.currentSongStream.value;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
|
|
|
@ -15,7 +15,7 @@ class AudioStore extends _AudioStore with _$AudioStore {
|
|||
|
||||
abstract class _AudioStore with Store {
|
||||
_AudioStore(this._audioRepository) {
|
||||
currentSong = _audioRepository.currentSongStream.asObservable();
|
||||
currentSongStream = _audioRepository.currentSongStream.distinct().asObservable();
|
||||
|
||||
currentPositionStream =
|
||||
_audioRepository.currentPositionStream.asObservable(initialValue: 0);
|
||||
|
@ -27,22 +27,13 @@ abstract class _AudioStore with Store {
|
|||
shuffleModeStream = _audioRepository.shuffleModeStream
|
||||
.asObservable(initialValue: ShuffleMode.none);
|
||||
|
||||
_disposers.add(autorun((_) {
|
||||
updateSong(currentSong.value);
|
||||
}));
|
||||
|
||||
playbackStateStream = _audioRepository.playbackStateStream.asObservable();
|
||||
}
|
||||
|
||||
final AudioRepository _audioRepository;
|
||||
|
||||
final List<ReactionDisposer> _disposers = [];
|
||||
|
||||
// TODO: naming and usage confusing!
|
||||
@observable
|
||||
ObservableStream<Song> currentSong;
|
||||
@observable
|
||||
Song song;
|
||||
ObservableStream<Song> currentSongStream;
|
||||
|
||||
@observable
|
||||
ObservableStream<PlaybackState> playbackStateStream;
|
||||
|
@ -59,13 +50,6 @@ abstract class _AudioStore with Store {
|
|||
@observable
|
||||
ObservableStream<ShuffleMode> shuffleModeStream;
|
||||
|
||||
void dispose() {
|
||||
print('AudioStore.dispose');
|
||||
for (final ReactionDisposer d in _disposers) {
|
||||
d();
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> playSong(int index, List<Song> songList) async {
|
||||
_audioRepository.playSong(index, songList);
|
||||
|
@ -98,13 +82,4 @@ abstract class _AudioStore with Store {
|
|||
Future<void> shuffleAll() async {
|
||||
_audioRepository.shuffleAll();
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> updateSong(Song streamValue) async {
|
||||
print('updateSong');
|
||||
if (streamValue != null && streamValue != song) {
|
||||
print('actually updating...');
|
||||
song = streamValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,33 +9,18 @@ part of 'audio_store.dart';
|
|||
// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic
|
||||
|
||||
mixin _$AudioStore on _AudioStore, Store {
|
||||
final _$currentSongAtom = Atom(name: '_AudioStore.currentSong');
|
||||
final _$currentSongStreamAtom = Atom(name: '_AudioStore.currentSongStream');
|
||||
|
||||
@override
|
||||
ObservableStream<Song> get currentSong {
|
||||
_$currentSongAtom.reportRead();
|
||||
return super.currentSong;
|
||||
ObservableStream<Song> get currentSongStream {
|
||||
_$currentSongStreamAtom.reportRead();
|
||||
return super.currentSongStream;
|
||||
}
|
||||
|
||||
@override
|
||||
set currentSong(ObservableStream<Song> value) {
|
||||
_$currentSongAtom.reportWrite(value, super.currentSong, () {
|
||||
super.currentSong = value;
|
||||
});
|
||||
}
|
||||
|
||||
final _$songAtom = Atom(name: '_AudioStore.song');
|
||||
|
||||
@override
|
||||
Song get song {
|
||||
_$songAtom.reportRead();
|
||||
return super.song;
|
||||
}
|
||||
|
||||
@override
|
||||
set song(Song value) {
|
||||
_$songAtom.reportWrite(value, super.song, () {
|
||||
super.song = value;
|
||||
set currentSongStream(ObservableStream<Song> value) {
|
||||
_$currentSongStreamAtom.reportWrite(value, super.currentSongStream, () {
|
||||
super.currentSongStream = value;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -152,18 +137,10 @@ mixin _$AudioStore on _AudioStore, Store {
|
|||
return _$skipToPreviousAsyncAction.run(() => super.skipToPrevious());
|
||||
}
|
||||
|
||||
final _$updateSongAsyncAction = AsyncAction('_AudioStore.updateSong');
|
||||
|
||||
@override
|
||||
Future<void> updateSong(Song streamValue) {
|
||||
return _$updateSongAsyncAction.run(() => super.updateSong(streamValue));
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
currentSong: ${currentSong},
|
||||
song: ${song},
|
||||
currentSongStream: ${currentSongStream},
|
||||
playbackStateStream: ${playbackStateStream},
|
||||
currentPositionStream: ${currentPositionStream},
|
||||
queueStream: ${queueStream},
|
||||
|
|
|
@ -18,14 +18,14 @@ class CurrentlyPlayingBar extends StatelessWidget {
|
|||
|
||||
return Observer(
|
||||
builder: (BuildContext context) {
|
||||
if (audioStore.currentSong.value != null) {
|
||||
final Song song = audioStore.currentSong.value;
|
||||
if (audioStore.currentSongStream.value != null) {
|
||||
final Song song = audioStore.currentSongStream.value;
|
||||
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: LinearProgressIndicator(
|
||||
value: audioStore.currentPositionStream.value / audioStore.currentSong.value.duration,
|
||||
value: audioStore.currentPositionStream.value / audioStore.currentSongStream.value.duration,
|
||||
),
|
||||
height: 2,
|
||||
),
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../domain/entities/song.dart';
|
||||
import '../state/audio_store.dart';
|
||||
import '../state/music_data_store.dart';
|
||||
import '../theming.dart';
|
||||
|
@ -15,34 +16,38 @@ class SongCustomizationButtons extends StatelessWidget {
|
|||
final AudioStore audioStore = Provider.of<AudioStore>(context);
|
||||
|
||||
return Observer(
|
||||
builder: (BuildContext context) => Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.link,
|
||||
size: 20.0,
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
),
|
||||
const Icon(
|
||||
Icons.favorite,
|
||||
size: 20.0,
|
||||
color: RASPBERRY,
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.remove_circle_outline,
|
||||
builder: (BuildContext context) {
|
||||
final Song song = audioStore.currentSongStream.value;
|
||||
return Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.link,
|
||||
size: 20.0,
|
||||
color: audioStore.song.blocked ? Colors.red : Colors.white70,
|
||||
),
|
||||
onPressed: () => musicDataStore.setSongBlocked(audioStore.song, !audioStore.song.blocked),
|
||||
),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
),
|
||||
const Icon(
|
||||
Icons.favorite,
|
||||
size: 20.0,
|
||||
color: RASPBERRY,
|
||||
),
|
||||
Container(
|
||||
width: 40,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.remove_circle_outline,
|
||||
size: 20.0,
|
||||
color: song.blocked ? Colors.red : Colors.white70,
|
||||
),
|
||||
onPressed: () => musicDataStore.setSongBlocked(
|
||||
song, !song.blocked),
|
||||
),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class TimeProgressIndicator extends StatelessWidget {
|
|||
|
||||
return Observer(
|
||||
builder: (BuildContext context) {
|
||||
final int duration = audioStore.song?.duration ?? 1000;
|
||||
final int duration = audioStore.currentSongStream.value?.duration ?? 1000;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
|
|
|
@ -118,7 +118,7 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
|||
print('AudioPlayerTask.init');
|
||||
audioPlayer.positionStream.listen((position) => handlePosition(position));
|
||||
audioPlayer.playerStateStream.listen((event) => handlePlayerState(event));
|
||||
audioPlayer.sequenceStateStream.listen((event) => playbackIndex = event.currentIndex);
|
||||
audioPlayer.sequenceStateStream.listen((event) => playbackIndex = event?.currentIndex);
|
||||
|
||||
final connectPort = IsolateNameServer.lookupPortByName(MOOR_ISOLATE);
|
||||
final MoorIsolate moorIsolate = MoorIsolate.fromConnectPort(connectPort);
|
||||
|
|
|
@ -367,7 +367,7 @@ packages:
|
|||
source: hosted
|
||||
version: "0.4.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: logging
|
||||
url: "https://pub.dartlang.org"
|
||||
|
|
|
@ -23,6 +23,7 @@ dependencies:
|
|||
|
||||
get_it: ^4.0.2
|
||||
provider: ^4.0.4
|
||||
logging: ^0.11.4
|
||||
moor: ^3.0.2
|
||||
moor_ffi: ^0.5.0
|
||||
path_provider:
|
||||
|
|
Loading…
Add table
Reference in a new issue