mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Functional player bar
This commit is contained in:
parent
3f98037160
commit
87838ce7d2
3 changed files with 54 additions and 14 deletions
|
|
@ -31,7 +31,12 @@ class Player {
|
||||||
/// Index of the currently played (or paused) track within the playlist.
|
/// Index of the currently played (or paused) track within the playlist.
|
||||||
///
|
///
|
||||||
/// This will be zero, if the player is not active!
|
/// This will be zero, if the player is not active!
|
||||||
final currentTrack = BehaviorSubject.seeded(0);
|
final currentIndex = BehaviorSubject.seeded(0);
|
||||||
|
|
||||||
|
/// The currently played track.
|
||||||
|
///
|
||||||
|
/// This will be null, if there is no current track.
|
||||||
|
final currentTrack = BehaviorSubject<InternalTrack>.seeded(null);
|
||||||
|
|
||||||
/// Whether we are currently playing or not.
|
/// Whether we are currently playing or not.
|
||||||
///
|
///
|
||||||
|
|
@ -63,7 +68,7 @@ class Player {
|
||||||
void _stop() {
|
void _stop() {
|
||||||
active.add(false);
|
active.add(false);
|
||||||
playlist.add([]);
|
playlist.add([]);
|
||||||
currentTrack.add(0);
|
currentIndex.add(0);
|
||||||
playing.add(false);
|
playing.add(false);
|
||||||
position.add(const Duration());
|
position.add(const Duration());
|
||||||
duration.add(const Duration(seconds: 1));
|
duration.add(const Duration(seconds: 1));
|
||||||
|
|
@ -100,7 +105,8 @@ class Player {
|
||||||
|
|
||||||
// TODO: Consider checking, whether values have actually changed.
|
// TODO: Consider checking, whether values have actually changed.
|
||||||
playlist.add(state.playlist);
|
playlist.add(state.playlist);
|
||||||
currentTrack.add(state.currentTrack);
|
currentIndex.add(state.currentTrack);
|
||||||
|
currentTrack.add(state.playlist[state.currentTrack]);
|
||||||
playing.add(state.playing);
|
playing.add(state.playing);
|
||||||
position.add(Duration(milliseconds: state.positionMs));
|
position.add(Duration(milliseconds: state.positionMs));
|
||||||
duration.add(Duration(milliseconds: state.durationMs));
|
duration.add(Duration(milliseconds: state.durationMs));
|
||||||
|
|
@ -184,6 +190,9 @@ class Player {
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_playbackServiceStateSubscription.cancel();
|
_playbackServiceStateSubscription.cancel();
|
||||||
active.close();
|
active.close();
|
||||||
|
playlist.close();
|
||||||
|
currentIndex.close();
|
||||||
|
currentTrack.close();
|
||||||
playing.close();
|
playing.close();
|
||||||
position.close();
|
position.close();
|
||||||
duration.close();
|
duration.close();
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||||
import '../backend.dart';
|
import '../backend.dart';
|
||||||
import '../music_library.dart';
|
import '../music_library.dart';
|
||||||
import '../widgets/play_pause_button.dart';
|
import '../widgets/play_pause_button.dart';
|
||||||
|
import '../widgets/recording_tile.dart';
|
||||||
|
|
||||||
class ProgramScreen extends StatefulWidget {
|
class ProgramScreen extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
|
@ -53,12 +54,13 @@ class _ProgramScreenState extends State<ProgramScreen> {
|
||||||
|
|
||||||
if (playlist != null && playlist.isNotEmpty) {
|
if (playlist != null && playlist.isNotEmpty) {
|
||||||
return StreamBuilder<int>(
|
return StreamBuilder<int>(
|
||||||
stream: backend.player.currentTrack,
|
stream: backend.player.currentIndex,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: playlist.length,
|
itemCount: playlist.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
|
||||||
final track = playlist[index];
|
final track = playlist[index];
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
|
@ -68,7 +70,9 @@ class _ProgramScreenState extends State<ProgramScreen> {
|
||||||
width: 24.0,
|
width: 24.0,
|
||||||
height: 24.0,
|
height: 24.0,
|
||||||
),
|
),
|
||||||
title: Text(track.track.fileName),
|
title: RecordingTile(
|
||||||
|
recordingId: track.track.recordingId,
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
backend.player.skipTo(index);
|
backend.player.skipTo(index);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:musicus/database.dart';
|
||||||
|
|
||||||
import '../backend.dart';
|
import '../backend.dart';
|
||||||
|
import '../music_library.dart';
|
||||||
import '../screens/program.dart';
|
import '../screens/program.dart';
|
||||||
|
|
||||||
import 'play_pause_button.dart';
|
import 'play_pause_button.dart';
|
||||||
|
import 'texts.dart';
|
||||||
|
|
||||||
class PlayerBar extends StatelessWidget {
|
class PlayerBar extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
|
|
@ -28,15 +31,39 @@ class PlayerBar extends StatelessWidget {
|
||||||
child: Icon(Icons.keyboard_arrow_up),
|
child: Icon(Icons.keyboard_arrow_up),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: StreamBuilder<InternalTrack>(
|
||||||
|
stream: backend.player.currentTrack,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.data != null) {
|
||||||
|
final recordingId = snapshot.data.track.recordingId;
|
||||||
|
|
||||||
|
return FutureBuilder<Recording>(
|
||||||
|
future:
|
||||||
|
backend.db.recordingById(recordingId).getSingle(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
final workId = snapshot.data.work;
|
||||||
|
|
||||||
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
DefaultTextStyle.merge(
|
||||||
'Composer',
|
style:
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
child: ComposersText(workId),
|
||||||
),
|
),
|
||||||
Text('Work: Movement'),
|
WorkText(workId),
|
||||||
],
|
],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
PlayPauseButton(),
|
PlayPauseButton(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue