Compare commits

..

No commits in common. "b1db0059ebaa61f949b3d6bfa2d8ec08222eea71" and "773cf12b97ceb1e00c0591e059c982cfeb6e8612" have entirely different histories.

5 changed files with 46 additions and 157 deletions

View file

@ -26,19 +26,11 @@ class AudioPlayerService {
/// Registers listeners on the player /// Registers listeners on the player
void setup() { void setup() {
if (_setUp) return; if (_setUp) return;
_player.createPositionStream().listen((d) {
if (!isPlaying) return;
progressNotifier.value = [
d.inSeconds,
_songList[_player.currentIndex!].duration,
];
});
_player.currentIndexStream.listen((index) { _player.currentIndexStream.listen((index) {
logger.d("Done fired"); logger.d("Done fired");
songNotifier.value = index == null ? null : _songList[index]; songNotifier.value = index == null ? null : _songList[index];
_setColorScheme(); _setColorScheme();
}); });
_setUp = true; _setUp = true;
} }
@ -48,8 +40,9 @@ class AudioPlayerService {
/// Currently playing song /// Currently playing song
/// ///
/// Null if no song is loaded /// Null if no song is loaded
Song? get song => Song? get song => _player.currentIndex == null || _player.currentIndex == -1
_player.currentIndex == null ? null : _songList[_player.currentIndex!]; ? null
: _songList[_player.currentIndex!];
final _queue = ConcatenatingAudioSource( final _queue = ConcatenatingAudioSource(
children: [], children: [],
@ -78,16 +71,10 @@ class AudioPlayerService {
logger.d("Playing ${_player.currentIndex}"); logger.d("Playing ${_player.currentIndex}");
} }
/// Moves to the specified number of seconds
Future<void> seek(double position) async {
await _player.seek(Duration(seconds: position.toInt()));
}
/// Sets color scheme from image /// Sets color scheme from image
Future<void> _setColorScheme() async { Future<void> _setColorScheme() async {
if (AudioPlayerService().song == null) { if (AudioPlayerService().song == null) {
themeNotifier.value = ColorScheme.fromSeed(seedColor: Colors.deepPurple); themeNotifier.value = ColorScheme.fromSeed(seedColor: Colors.deepPurple);
return;
} }
themeNotifier.value = await ColorScheme.fromImageProvider( themeNotifier.value = await ColorScheme.fromImageProvider(
provider: CachedNetworkImageProvider( provider: CachedNetworkImageProvider(
@ -139,7 +126,6 @@ class AudioPlayerService {
await _queue.clear(); await _queue.clear();
_songList _songList
..clear() ..clear()
..addAll(queuePast)
..addAll(queueNext); ..addAll(queueNext);
final q = List<AudioSource>.generate( final q = List<AudioSource>.generate(

View file

@ -35,9 +35,6 @@ final ValueNotifier<ColorScheme> themeNotifier =
/// Notifier to change theme from inside the app /// Notifier to change theme from inside the app
final ValueNotifier<Song?> songNotifier = ValueNotifier(null); final ValueNotifier<Song?> songNotifier = ValueNotifier(null);
/// Notifier for the song progress bar
final ValueNotifier<List<int>> progressNotifier = ValueNotifier([0, 1]);
/// Main app class /// Main app class
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
/// Main app class /// Main app class
@ -61,12 +58,9 @@ class MyApp extends StatelessWidget {
return Stack( return Stack(
children: [ children: [
child!, child!,
Material( Player(
type: MaterialType.transparency,
child: Player(
key: playerKey, key: playerKey,
), ),
),
], ],
); );
}, },

View file

@ -1,7 +1,6 @@
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_xlider/flutter_xlider.dart';
import 'package:ocarina/api/audio/audioplayer_service.dart'; import 'package:ocarina/api/audio/audioplayer_service.dart';
import 'package:ocarina/api/subsonic/song.dart'; import 'package:ocarina/api/subsonic/song.dart';
import 'package:ocarina/main.dart'; import 'package:ocarina/main.dart';
@ -209,22 +208,13 @@ class PlayerState extends State<Player> {
), ),
), ),
), ),
Container( SizedBox(
// Full player controls here
height: 90.h, height: 90.h,
color: Theme.of(context).colorScheme.primaryContainer,
width: 100.w, width: 100.w,
child: Center( child: Center(
child: Column( child: Column(
children: [ children: [
const SizedBox( ClipRRect(
height: 30,
),
SizedBox(
width: 80.w,
height: 80.w,
child: ClipRRect(
// borderRadius: BorderRadius.circular(16),
child: (AudioPlayerService().song == null) child: (AudioPlayerService().song == null)
? ColoredBox( ? ColoredBox(
color: Theme.of(context) color: Theme.of(context)
@ -240,8 +230,7 @@ class PlayerState extends State<Player> {
), ),
) )
: (CachedNetworkImage( : (CachedNetworkImage(
cacheKey: cacheKey: AudioPlayerService().song!.coverArtId,
AudioPlayerService().song!.coverArtId,
imageUrl: imageUrl:
AudioPlayerService().song!.coverArtUrl, AudioPlayerService().song!.coverArtUrl,
placeholder: (c, d) => Shimmer.fromColors( placeholder: (c, d) => Shimmer.fromColors(
@ -271,77 +260,6 @@ class PlayerState extends State<Player> {
}, },
)), )),
), ),
),
const SizedBox(
height: 10,
),
SizedBox(
width: 70.w,
height: 40,
child: AutoSizeText(
AudioPlayerService().song?.title ?? "Nothing",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.sp,
),
overflowReplacement: TextScroll(
AudioPlayerService().song?.title ?? "Nothing",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.sp,
),
),
),
),
SizedBox(
width: 70.w,
height: 50,
child: AutoSizeText(
AudioPlayerService().song?.artistName ?? "Nobody",
style: TextStyle(fontSize: 16.sp),
textAlign: TextAlign.center,
overflowReplacement: TextScroll(
AudioPlayerService().song?.artistName ?? "Nobody",
style: TextStyle(
fontSize: 16.sp,
),
),
),
),
const SizedBox(
height: 10,
),
SizedBox(
width: 60.w,
height: 40,
child: Overlay(
initialEntries: [
OverlayEntry(
builder: (c) => ValueListenableBuilder<List<int>>(
valueListenable: progressNotifier,
builder: (c, v, _) {
return FlutterSlider(
values: [v[0].toDouble()],
max: v[1].toDouble(),
min: 0,
onDragCompleted:
(handlerIndex, lowerValue, upperValue) {
if (AudioPlayerService().song == null) {
return;
}
logger.d(lowerValue);
AudioPlayerService()
.seek(lowerValue as double);
},
);
},
),
),
],
),
),
], ],
), ),
), ),

View file

@ -368,14 +368,6 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_xlider:
dependency: "direct main"
description:
name: flutter_xlider
sha256: b83da229b8a2153adeefc5d9e08e0060689c8dc2187b30e3502cf67c1a6495be
url: "https://pub.dev"
source: hosted
version: "3.5.0"
frontend_server_client: frontend_server_client:
dependency: transitive dependency: transitive
description: description:

View file

@ -55,7 +55,6 @@ dependencies:
shared_preferences: ^2.2.3 shared_preferences: ^2.2.3
dynamic_color: ^1.7.0 dynamic_color: ^1.7.0
cached_network_image: ^3.3.1 cached_network_image: ^3.3.1
flutter_xlider: ^3.5.0
dev_dependencies: dev_dependencies:
build_runner: ^2.4.9 build_runner: ^2.4.9