Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29758eb9bb | ||
|
|
332de9e00c | ||
|
|
6f503c8540 | ||
|
|
9950ff2063 | ||
|
|
4c777a93e1 | ||
|
|
a96578bbf0 | ||
|
|
8fa95705e1 | ||
|
|
9dcca2ce54 | ||
|
|
4152c3d67f | ||
|
|
d84fb58a5c | ||
|
|
128d417014 | ||
|
|
176fa5c8b9 | ||
|
|
ccaf764f52 | ||
|
|
ccda231fb2 | ||
|
|
0f82829172 | ||
|
|
0ccde33c85 |
+14
-2
@@ -197,9 +197,21 @@ class Player {
|
|||||||
final activeSource = json['active_source'] as String?;
|
final activeSource = json['active_source'] as String?;
|
||||||
|
|
||||||
// Detect external source (optical, Spotify, AirPlay, etc.)
|
// Detect external source (optical, Spotify, AirPlay, etc.)
|
||||||
// External sources have non-MA URIs and often media_type='unknown'
|
// Primary indicator: app_id - if not 'music_assistant', it's an external source
|
||||||
|
// Secondary indicators: URI patterns and media_type
|
||||||
bool isExternalSource = false;
|
bool isExternalSource = false;
|
||||||
if (json.containsKey('current_media')) {
|
|
||||||
|
// Check app_id first - this is the most reliable indicator for DLNA players
|
||||||
|
// When MA is playing: app_id = 'music_assistant'
|
||||||
|
// When external source: app_id = 'http', 'spotify', etc.
|
||||||
|
final appId = json['app_id'] as String?;
|
||||||
|
if (appId != null && appId.isNotEmpty && appId != 'music_assistant') {
|
||||||
|
// app_id is set but not 'music_assistant' - external source is active
|
||||||
|
isExternalSource = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also check current_media for additional external source indicators
|
||||||
|
if (!isExternalSource && json.containsKey('current_media')) {
|
||||||
final currentMedia = json['current_media'] as Map<String, dynamic>?;
|
final currentMedia = json['current_media'] as Map<String, dynamic>?;
|
||||||
if (currentMedia != null) {
|
if (currentMedia != null) {
|
||||||
final uri = currentMedia['uri'] as String?;
|
final uri = currentMedia['uri'] as String?;
|
||||||
|
|||||||
@@ -2415,7 +2415,19 @@ class MusicAssistantProvider with ChangeNotifier {
|
|||||||
(p) => p.playerId == builtinPlayerId && p.available,
|
(p) => p.playerId == builtinPlayerId && p.available,
|
||||||
);
|
);
|
||||||
_logger.log('📱 Auto-selected local player: ${playerToSelect?.name}');
|
_logger.log('📱 Auto-selected local player: ${playerToSelect?.name}');
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
// Local player not found or not available - check why
|
||||||
|
final localPlayer = _availablePlayers
|
||||||
|
.where((p) => p.playerId == builtinPlayerId)
|
||||||
|
.toList();
|
||||||
|
if (localPlayer.isEmpty) {
|
||||||
|
_logger.log('⚠️ Priority 2 skipped: local player ($builtinPlayerId) not in available players list');
|
||||||
|
} else {
|
||||||
|
_logger.log('⚠️ Priority 2 skipped: local player found but available=${localPlayer.first.available}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (playerToSelect == null && builtinPlayerId == null) {
|
||||||
|
_logger.log('⚠️ Priority 2 skipped: builtinPlayerId is null');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ class _AlbumDetailsScreenState extends State<AlbumDetailsScreen> with SingleTick
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
SizedBox(height: MediaQuery.of(context).padding.bottom + 16),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1132,7 +1132,7 @@ class _AlbumDetailsScreenState extends State<AlbumDetailsScreen> with SingleTick
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shared "Play on..." bottom sheet with fixed height and scrollable list
|
/// Shared "Play on..." bottom sheet that sizes to content
|
||||||
void _showPlayOnSheet(
|
void _showPlayOnSheet(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
List players, {
|
List players, {
|
||||||
@@ -1141,21 +1141,16 @@ class _AlbumDetailsScreenState extends State<AlbumDetailsScreen> with SingleTick
|
|||||||
// Slide mini player down out of the way
|
// Slide mini player down out of the way
|
||||||
GlobalPlayerOverlay.hidePlayer();
|
GlobalPlayerOverlay.hidePlayer();
|
||||||
|
|
||||||
final screenHeight = MediaQuery.of(context).size.height;
|
|
||||||
final bottomPadding = MediaQuery.of(context).padding.bottom;
|
|
||||||
final sheetHeight = (screenHeight * 0.45) + bottomPadding; // Fixed 45% + safe area
|
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
isScrollControlled: true,
|
|
||||||
builder: (context) => Container(
|
builder: (context) => Container(
|
||||||
height: sheetHeight,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
@@ -1163,30 +1158,33 @@ class _AlbumDetailsScreenState extends State<AlbumDetailsScreen> with SingleTick
|
|||||||
style: Theme.of(context).textTheme.titleLarge,
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Expanded(
|
if (players.isEmpty)
|
||||||
child: players.isEmpty
|
Padding(
|
||||||
? Center(
|
padding: const EdgeInsets.all(32.0),
|
||||||
child: Text(S.of(context)!.noPlayersAvailable),
|
child: Text(S.of(context)!.noPlayersAvailable),
|
||||||
)
|
)
|
||||||
: ListView.builder(
|
else
|
||||||
padding: EdgeInsets.only(bottom: bottomPadding + 16),
|
Flexible(
|
||||||
itemCount: players.length,
|
child: ListView.builder(
|
||||||
itemBuilder: (context, index) {
|
shrinkWrap: true,
|
||||||
final player = players[index];
|
itemCount: players.length,
|
||||||
return ListTile(
|
itemBuilder: (context, index) {
|
||||||
leading: Icon(
|
final player = players[index];
|
||||||
Icons.speaker,
|
return ListTile(
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
leading: Icon(
|
||||||
),
|
Icons.speaker,
|
||||||
title: Text(player.name),
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
onTap: () {
|
),
|
||||||
Navigator.pop(context);
|
title: Text(player.name),
|
||||||
onPlayerSelected(player);
|
onTap: () {
|
||||||
},
|
Navigator.pop(context);
|
||||||
);
|
onPlayerSelected(player);
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
),
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: MediaQuery.of(context).padding.bottom + 16),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -243,57 +243,25 @@ class _ArtistDetailsScreenState extends State<ArtistDetailsScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _startArtistRadio() async {
|
void _showRadioMenu(BuildContext context) {
|
||||||
final maProvider = context.read<MusicAssistantProvider>();
|
|
||||||
final selectedPlayer = maProvider.selectedPlayer;
|
|
||||||
|
|
||||||
if (selectedPlayer == null) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text(S.of(context)!.noPlayerSelected)),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await maProvider.playArtistRadio(selectedPlayer.playerId, widget.artist);
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(S.of(context)!.startingRadio(widget.artist.name)),
|
|
||||||
duration: const Duration(seconds: 1),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
_logger.log('Error starting artist radio: $e');
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(S.of(context)!.failedToStartRadio(e.toString())),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showPlayOnMenu(BuildContext context) {
|
|
||||||
final maProvider = context.read<MusicAssistantProvider>();
|
final maProvider = context.read<MusicAssistantProvider>();
|
||||||
final players = maProvider.availablePlayers;
|
final players = maProvider.availablePlayers;
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
|
||||||
|
// Slide mini player down out of the way
|
||||||
|
GlobalPlayerOverlay.hidePlayer();
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
backgroundColor: colorScheme.surface,
|
backgroundColor: Colors.transparent,
|
||||||
shape: const RoundedRectangleBorder(
|
builder: (context) => Container(
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
decoration: BoxDecoration(
|
||||||
),
|
color: Theme.of(context).colorScheme.surface,
|
||||||
builder: (context) => Padding(
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
padding: const EdgeInsets.all(16.0),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
S.of(context)!.startRadioOn(widget.artist.name),
|
S.of(context)!.startRadioOn(widget.artist.name),
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
@@ -314,7 +282,7 @@ class _ArtistDetailsScreenState extends State<ArtistDetailsScreen> {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
leading: Icon(
|
leading: Icon(
|
||||||
Icons.speaker,
|
Icons.speaker,
|
||||||
color: colorScheme.onSurface,
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
title: Text(player.name),
|
title: Text(player.name),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
@@ -345,54 +313,103 @@ class _ArtistDetailsScreenState extends State<ArtistDetailsScreen> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
SizedBox(height: MediaQuery.of(context).padding.bottom + 16),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
).whenComplete(() {
|
||||||
|
// Slide mini player back up when sheet is dismissed
|
||||||
|
GlobalPlayerOverlay.showPlayer();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _addArtistRadioToQueue() async {
|
void _showAddToQueueMenu(BuildContext context) {
|
||||||
final maProvider = context.read<MusicAssistantProvider>();
|
final maProvider = context.read<MusicAssistantProvider>();
|
||||||
final selectedPlayer = maProvider.selectedPlayer;
|
final players = maProvider.availablePlayers;
|
||||||
|
|
||||||
if (selectedPlayer == null) {
|
// Slide mini player down out of the way
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
GlobalPlayerOverlay.hidePlayer();
|
||||||
SnackBar(content: Text(S.of(context)!.noPlayerSelected)),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final api = maProvider.api;
|
showModalBottomSheet(
|
||||||
if (api == null) {
|
context: context,
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
backgroundColor: Colors.transparent,
|
||||||
SnackBar(content: Text(S.of(context)!.notConnected)),
|
builder: (context) => Container(
|
||||||
);
|
decoration: BoxDecoration(
|
||||||
return;
|
color: Theme.of(context).colorScheme.surface,
|
||||||
}
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
|
),
|
||||||
try {
|
child: Column(
|
||||||
// For adding to queue with radio mode, we use radio_mode but with 'add' option
|
mainAxisSize: MainAxisSize.min,
|
||||||
await api.playArtistRadioToQueue(selectedPlayer.playerId, widget.artist);
|
children: [
|
||||||
if (mounted) {
|
const SizedBox(height: 16),
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
Text(
|
||||||
SnackBar(
|
S.of(context)!.addToQueueOn,
|
||||||
content: Text(S.of(context)!.addedRadioToQueue(widget.artist.name)),
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
duration: const Duration(seconds: 1),
|
),
|
||||||
),
|
const SizedBox(height: 16),
|
||||||
);
|
if (players.isEmpty)
|
||||||
}
|
Padding(
|
||||||
} catch (e) {
|
padding: const EdgeInsets.all(32.0),
|
||||||
_logger.log('Error adding artist radio to queue: $e');
|
child: Text(S.of(context)!.noPlayersAvailable),
|
||||||
if (mounted) {
|
)
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
else
|
||||||
SnackBar(
|
Flexible(
|
||||||
content: Text(S.of(context)!.failedToAddToQueue(e.toString())),
|
child: ListView.builder(
|
||||||
backgroundColor: Colors.red,
|
shrinkWrap: true,
|
||||||
),
|
itemCount: players.length,
|
||||||
);
|
itemBuilder: (context, index) {
|
||||||
}
|
final player = players[index];
|
||||||
}
|
return ListTile(
|
||||||
|
leading: Icon(
|
||||||
|
Icons.speaker,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
title: Text(player.name),
|
||||||
|
onTap: () async {
|
||||||
|
Navigator.pop(context);
|
||||||
|
final api = maProvider.api;
|
||||||
|
if (api == null) {
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(S.of(context)!.notConnected)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await api.playArtistRadioToQueue(player.playerId, widget.artist);
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(S.of(context)!.addedRadioToQueue(widget.artist.name)),
|
||||||
|
duration: const Duration(seconds: 1),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
_logger.log('Error adding artist radio to queue: $e');
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(S.of(context)!.failedToAddToQueue(e.toString())),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: MediaQuery.of(context).padding.bottom + 16),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
).whenComplete(() {
|
||||||
|
// Slide mini player back up when sheet is dismissed
|
||||||
|
GlobalPlayerOverlay.showPlayer();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadArtistImage() async {
|
Future<void> _loadArtistImage() async {
|
||||||
@@ -635,7 +652,7 @@ class _ArtistDetailsScreenState extends State<ArtistDetailsScreen> {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 50,
|
height: 50,
|
||||||
child: ElevatedButton.icon(
|
child: ElevatedButton.icon(
|
||||||
onPressed: _startArtistRadio,
|
onPressed: () => _showRadioMenu(context),
|
||||||
icon: const Icon(Icons.radio),
|
icon: const Icon(Icons.radio),
|
||||||
label: Text(S.of(context)!.radio),
|
label: Text(S.of(context)!.radio),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
@@ -648,23 +665,6 @@ class _ArtistDetailsScreenState extends State<ArtistDetailsScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
|
||||||
|
|
||||||
// "Play on..." Button (Square)
|
|
||||||
SizedBox(
|
|
||||||
height: 50,
|
|
||||||
width: 50,
|
|
||||||
child: FilledButton.tonal(
|
|
||||||
onPressed: () => _showPlayOnMenu(context),
|
|
||||||
style: FilledButton.styleFrom(
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: const Icon(Icons.speaker_group_outlined),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
|
|
||||||
@@ -673,7 +673,7 @@ class _ArtistDetailsScreenState extends State<ArtistDetailsScreen> {
|
|||||||
height: 50,
|
height: 50,
|
||||||
width: 50,
|
width: 50,
|
||||||
child: FilledButton.tonal(
|
child: FilledButton.tonal(
|
||||||
onPressed: _addArtistRadioToQueue,
|
onPressed: () => _showAddToQueueMenu(context),
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
|
|||||||
@@ -211,23 +211,19 @@ class _AudiobookDetailScreenState extends State<AudiobookDetailScreen> {
|
|||||||
final maProvider = context.read<MusicAssistantProvider>();
|
final maProvider = context.read<MusicAssistantProvider>();
|
||||||
final players = maProvider.availablePlayers;
|
final players = maProvider.availablePlayers;
|
||||||
|
|
||||||
|
// Slide mini player down out of the way
|
||||||
GlobalPlayerOverlay.hidePlayer();
|
GlobalPlayerOverlay.hidePlayer();
|
||||||
|
|
||||||
final screenHeight = MediaQuery.of(context).size.height;
|
|
||||||
final bottomPadding = MediaQuery.of(context).padding.bottom;
|
|
||||||
final sheetHeight = (screenHeight * 0.45) + bottomPadding;
|
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
isScrollControlled: true,
|
|
||||||
builder: (context) => Container(
|
builder: (context) => Container(
|
||||||
height: sheetHeight,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
@@ -235,37 +231,43 @@ class _AudiobookDetailScreenState extends State<AudiobookDetailScreen> {
|
|||||||
style: Theme.of(context).textTheme.titleLarge,
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Expanded(
|
if (players.isEmpty)
|
||||||
child: players.isEmpty
|
Padding(
|
||||||
? Center(child: Text(S.of(context)!.noPlayersAvailable))
|
padding: const EdgeInsets.all(32.0),
|
||||||
: ListView.builder(
|
child: Text(S.of(context)!.noPlayersAvailable),
|
||||||
padding: EdgeInsets.only(bottom: bottomPadding + 16),
|
)
|
||||||
itemCount: players.length,
|
else
|
||||||
itemBuilder: (context, index) {
|
Flexible(
|
||||||
final player = players[index];
|
child: ListView.builder(
|
||||||
return ListTile(
|
shrinkWrap: true,
|
||||||
leading: Icon(
|
itemCount: players.length,
|
||||||
Icons.speaker,
|
itemBuilder: (context, index) {
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
final player = players[index];
|
||||||
),
|
return ListTile(
|
||||||
title: Text(player.name),
|
leading: Icon(
|
||||||
onTap: () async {
|
Icons.speaker,
|
||||||
Navigator.pop(context);
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
maProvider.selectPlayer(player);
|
),
|
||||||
maProvider.setCurrentAudiobook(_audiobook);
|
title: Text(player.name),
|
||||||
await maProvider.api?.playAudiobook(
|
onTap: () async {
|
||||||
player.playerId,
|
Navigator.pop(context);
|
||||||
widget.audiobook,
|
maProvider.selectPlayer(player);
|
||||||
);
|
maProvider.setCurrentAudiobook(_audiobook);
|
||||||
},
|
await maProvider.api?.playAudiobook(
|
||||||
|
player.playerId,
|
||||||
|
widget.audiobook,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
),
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: MediaQuery.of(context).padding.bottom + 16),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
).whenComplete(() {
|
).whenComplete(() {
|
||||||
|
// Slide mini player back up when sheet is dismissed
|
||||||
GlobalPlayerOverlay.showPlayer();
|
GlobalPlayerOverlay.showPlayer();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+592
-367
File diff suppressed because it is too large
Load Diff
@@ -44,6 +44,10 @@ class PlayerRevealOverlayState extends State<PlayerRevealOverlay>
|
|||||||
double _dragOffset = 0;
|
double _dragOffset = 0;
|
||||||
bool _isDragging = false;
|
bool _isDragging = false;
|
||||||
|
|
||||||
|
// Scroll controller for when player list overflows
|
||||||
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
bool _isScrollable = false;
|
||||||
|
|
||||||
// Cache extracted colors per player for per-device accent colors
|
// Cache extracted colors per player for per-device accent colors
|
||||||
final Map<String, ColorScheme?> _playerColors = {};
|
final Map<String, ColorScheme?> _playerColors = {};
|
||||||
|
|
||||||
@@ -128,6 +132,7 @@ class PlayerRevealOverlayState extends State<PlayerRevealOverlay>
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_revealController.dispose();
|
_revealController.dispose();
|
||||||
_refreshTimer?.cancel();
|
_refreshTimer?.cancel();
|
||||||
|
_scrollController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,19 +162,51 @@ class PlayerRevealOverlayState extends State<PlayerRevealOverlay>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if scroll is at top (or not scrollable)
|
||||||
|
bool get _isAtTop {
|
||||||
|
if (!_isScrollable) return true;
|
||||||
|
if (!_scrollController.hasClients) return true;
|
||||||
|
return _scrollController.offset <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
void _handleVerticalDragUpdate(DragUpdateDetails details) {
|
void _handleVerticalDragUpdate(DragUpdateDetails details) {
|
||||||
|
final delta = details.primaryDelta ?? 0;
|
||||||
|
|
||||||
|
// If scrollable and not at top, let scroll handle it
|
||||||
|
if (_isScrollable && !_isAtTop) {
|
||||||
|
// Scroll the list
|
||||||
|
if (_scrollController.hasClients) {
|
||||||
|
final newOffset = _scrollController.offset - delta;
|
||||||
|
_scrollController.jumpTo(newOffset.clamp(0.0, _scrollController.position.maxScrollExtent));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// At top: check if trying to scroll down (view more) or dismiss
|
||||||
|
if (_isScrollable && delta < 0 && _scrollController.hasClients) {
|
||||||
|
// Swiping up (delta negative) = scroll down to see more players
|
||||||
|
final newOffset = _scrollController.offset - delta;
|
||||||
|
_scrollController.jumpTo(newOffset.clamp(0.0, _scrollController.position.maxScrollExtent));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only process dismiss gesture when swiping DOWN (positive delta = finger moving down)
|
||||||
|
// Ignore swipe up when not scrollable - cards should stay fixed
|
||||||
|
if (delta <= 0) return;
|
||||||
|
|
||||||
|
// Swiping down = dismiss gesture
|
||||||
setState(() {
|
setState(() {
|
||||||
_isDragging = true;
|
_isDragging = true;
|
||||||
// Negate delta so swipe down = cards move down (toward dismissal)
|
_dragOffset += delta;
|
||||||
_dragOffset -= details.primaryDelta ?? 0;
|
|
||||||
// Clamp: allow moving down (positive) freely, limit moving up to 20px
|
|
||||||
_dragOffset = _dragOffset.clamp(-20.0, double.infinity);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleVerticalDragEnd(DragEndDetails details) {
|
void _handleVerticalDragEnd(DragEndDetails details) {
|
||||||
final velocity = details.primaryVelocity ?? 0;
|
final velocity = details.primaryVelocity ?? 0;
|
||||||
|
|
||||||
|
// If not dragging (was scrolling), don't dismiss
|
||||||
|
if (!_isDragging) return;
|
||||||
|
|
||||||
// Dismiss if dragged down enough or with enough velocity
|
// Dismiss if dragged down enough or with enough velocity
|
||||||
if (_dragOffset > 100 || velocity > 500) {
|
if (_dragOffset > 100 || velocity > 500) {
|
||||||
HapticFeedback.lightImpact();
|
HapticFeedback.lightImpact();
|
||||||
@@ -215,6 +252,21 @@ class PlayerRevealOverlayState extends State<PlayerRevealOverlay>
|
|||||||
const cardSpacing = 12.0;
|
const cardSpacing = 12.0;
|
||||||
final totalStackHeight = players.length * cardHeight + (players.length - 1) * cardSpacing;
|
final totalStackHeight = players.length * cardHeight + (players.length - 1) * cardSpacing;
|
||||||
|
|
||||||
|
// Calculate max available height (80% of screen minus mini player area)
|
||||||
|
final screenHeight = MediaQuery.of(context).size.height;
|
||||||
|
final statusBarHeight = MediaQuery.of(context).padding.top;
|
||||||
|
final bottomPadding = widget.miniPlayerBottom + widget.miniPlayerHeight + 20;
|
||||||
|
final maxListHeight = (screenHeight - statusBarHeight - bottomPadding) * 0.8;
|
||||||
|
|
||||||
|
// Determine if scrolling is needed
|
||||||
|
final needsScroll = totalStackHeight > maxListHeight;
|
||||||
|
// Update scrollable state (used by gesture handlers)
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (_isScrollable != needsScroll) {
|
||||||
|
_isScrollable = needsScroll;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return AnimatedBuilder(
|
return AnimatedBuilder(
|
||||||
animation: _revealAnimation,
|
animation: _revealAnimation,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
@@ -289,7 +341,76 @@ class PlayerRevealOverlayState extends State<PlayerRevealOverlay>
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// Build player cards - all slide from behind mini player
|
// Build player cards - scrollable when overflow, otherwise static
|
||||||
|
// Using ListView.builder for many players: only builds visible items
|
||||||
|
// This significantly improves animation performance with 10+ players
|
||||||
|
if (needsScroll)
|
||||||
|
ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(maxHeight: maxListHeight),
|
||||||
|
child: ListView.builder(
|
||||||
|
controller: _scrollController,
|
||||||
|
physics: const ClampingScrollPhysics(),
|
||||||
|
itemCount: players.length,
|
||||||
|
// Fixed height per item for optimal scroll performance
|
||||||
|
itemExtent: cardHeight + cardSpacing,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final player = players[index];
|
||||||
|
final isPlaying = player.state == 'playing';
|
||||||
|
final playerTrack = maProvider.getCachedTrackForPlayer(player.playerId);
|
||||||
|
String? albumArtUrl;
|
||||||
|
if (playerTrack != null && player.available && player.powered) {
|
||||||
|
albumArtUrl = maProvider.getImageUrl(playerTrack, size: 128);
|
||||||
|
}
|
||||||
|
final playerColorScheme = _playerColors[player.playerId];
|
||||||
|
final cardBgColor = playerColorScheme?.primaryContainer ?? defaultBgColor;
|
||||||
|
final cardTextColor = playerColorScheme?.onPrimaryContainer ?? defaultTextColor;
|
||||||
|
|
||||||
|
// Animation: slide from behind mini player
|
||||||
|
// Only calculate for items that will be built (visible ones)
|
||||||
|
const baseOffset = 80.0;
|
||||||
|
final reverseIndex = players.length - 1 - index;
|
||||||
|
final distanceToTravel = baseOffset + (reverseIndex * (cardHeight + cardSpacing));
|
||||||
|
final slideOffset = distanceToTravel * (1.0 - t);
|
||||||
|
|
||||||
|
return Transform.translate(
|
||||||
|
offset: Offset(0, slideOffset),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: cardSpacing),
|
||||||
|
child: PlayerCard(
|
||||||
|
player: player,
|
||||||
|
trackInfo: playerTrack,
|
||||||
|
albumArtUrl: albumArtUrl,
|
||||||
|
isSelected: false,
|
||||||
|
isPlaying: isPlaying,
|
||||||
|
isGrouped: player.isGrouped,
|
||||||
|
backgroundColor: cardBgColor,
|
||||||
|
textColor: cardTextColor,
|
||||||
|
onTap: () {
|
||||||
|
HapticFeedback.mediumImpact();
|
||||||
|
maProvider.selectPlayer(player);
|
||||||
|
dismiss();
|
||||||
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
HapticFeedback.mediumImpact();
|
||||||
|
maProvider.togglePlayerSync(player.playerId);
|
||||||
|
},
|
||||||
|
onPlayPause: () {
|
||||||
|
if (isPlaying) {
|
||||||
|
maProvider.pausePlayer(player.playerId);
|
||||||
|
} else {
|
||||||
|
maProvider.resumePlayer(player.playerId);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSkipNext: () => maProvider.nextTrack(player.playerId),
|
||||||
|
onPower: () => maProvider.togglePower(player.playerId),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
// Non-scrollable list for when players fit
|
||||||
...List.generate(players.length, (index) {
|
...List.generate(players.length, (index) {
|
||||||
final player = players[index];
|
final player = players[index];
|
||||||
final isPlaying = player.state == 'playing';
|
final isPlaying = player.state == 'playing';
|
||||||
|
|||||||
@@ -0,0 +1,226 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../models/player.dart';
|
||||||
|
import '../l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
/// A themed bottom sheet for selecting a player.
|
||||||
|
///
|
||||||
|
/// Supports adaptive theming - pass [adaptiveColorScheme] to use colors
|
||||||
|
/// extracted from album art, matching the detail screen backgrounds.
|
||||||
|
class PlayerPickerSheet extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
final List<Player> players;
|
||||||
|
final Player? selectedPlayer;
|
||||||
|
final ColorScheme? adaptiveColorScheme;
|
||||||
|
final Future<void> Function(Player player) onPlayerSelected;
|
||||||
|
|
||||||
|
const PlayerPickerSheet({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
required this.players,
|
||||||
|
this.selectedPlayer,
|
||||||
|
this.adaptiveColorScheme,
|
||||||
|
required this.onPlayerSelected,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final themeColorScheme = Theme.of(context).colorScheme;
|
||||||
|
final colorScheme = adaptiveColorScheme ?? themeColorScheme;
|
||||||
|
|
||||||
|
// Use surface container for slightly elevated look, or adaptive surface
|
||||||
|
final backgroundColor = adaptiveColorScheme?.surface ?? themeColorScheme.surfaceContainerHigh;
|
||||||
|
final onBackgroundColor = adaptiveColorScheme?.onSurface ?? themeColorScheme.onSurface;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: backgroundColor,
|
||||||
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
// Drag handle
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 12, bottom: 8),
|
||||||
|
child: Container(
|
||||||
|
width: 32,
|
||||||
|
height: 4,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: onBackgroundColor.withOpacity(0.3),
|
||||||
|
borderRadius: BorderRadius.circular(2),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Title
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||||
|
child: Text(
|
||||||
|
title,
|
||||||
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
|
color: onBackgroundColor,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
|
// Player list
|
||||||
|
if (players.isEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(32.0),
|
||||||
|
child: Text(
|
||||||
|
S.of(context)!.noPlayersAvailable,
|
||||||
|
style: TextStyle(color: onBackgroundColor.withOpacity(0.6)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Flexible(
|
||||||
|
child: ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
|
itemCount: players.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final player = players[index];
|
||||||
|
final isSelected = selectedPlayer?.playerId == player.playerId;
|
||||||
|
|
||||||
|
return _PlayerTile(
|
||||||
|
player: player,
|
||||||
|
isSelected: isSelected,
|
||||||
|
colorScheme: colorScheme,
|
||||||
|
onBackgroundColor: onBackgroundColor,
|
||||||
|
onTap: () => onPlayerSelected(player),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: MediaQuery.of(context).padding.bottom + 70),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PlayerTile extends StatelessWidget {
|
||||||
|
final Player player;
|
||||||
|
final bool isSelected;
|
||||||
|
final ColorScheme colorScheme;
|
||||||
|
final Color onBackgroundColor;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
const _PlayerTile({
|
||||||
|
required this.player,
|
||||||
|
required this.isSelected,
|
||||||
|
required this.colorScheme,
|
||||||
|
required this.onBackgroundColor,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
// Status color based on player state
|
||||||
|
Color statusColor;
|
||||||
|
if (!player.available) {
|
||||||
|
statusColor = Colors.grey.withOpacity(0.5);
|
||||||
|
} else if (!player.powered) {
|
||||||
|
statusColor = Colors.grey;
|
||||||
|
} else if (player.state == 'playing') {
|
||||||
|
statusColor = Colors.green;
|
||||||
|
} else {
|
||||||
|
statusColor = Colors.orange; // Idle/paused but powered
|
||||||
|
}
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||||
|
child: Material(
|
||||||
|
color: isSelected
|
||||||
|
? colorScheme.primaryContainer.withOpacity(0.3)
|
||||||
|
: Colors.transparent,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
// Status indicator
|
||||||
|
Container(
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: statusColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
|
||||||
|
// Speaker icon
|
||||||
|
Icon(
|
||||||
|
Icons.speaker_rounded,
|
||||||
|
color: isSelected
|
||||||
|
? colorScheme.primary
|
||||||
|
: onBackgroundColor.withOpacity(0.7),
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
|
||||||
|
// Player name
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
player.name,
|
||||||
|
style: TextStyle(
|
||||||
|
color: isSelected
|
||||||
|
? colorScheme.primary
|
||||||
|
: onBackgroundColor,
|
||||||
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Selected checkmark
|
||||||
|
if (isSelected)
|
||||||
|
Icon(
|
||||||
|
Icons.check_circle_rounded,
|
||||||
|
color: colorScheme.primary,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shows the player picker bottom sheet with adaptive theming.
|
||||||
|
///
|
||||||
|
/// Returns the selected player, or null if dismissed.
|
||||||
|
Future<void> showPlayerPickerSheet({
|
||||||
|
required BuildContext context,
|
||||||
|
required String title,
|
||||||
|
required List<Player> players,
|
||||||
|
Player? selectedPlayer,
|
||||||
|
ColorScheme? adaptiveColorScheme,
|
||||||
|
required Future<void> Function(Player player) onPlayerSelected,
|
||||||
|
}) {
|
||||||
|
return showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
isScrollControlled: true,
|
||||||
|
builder: (context) => PlayerPickerSheet(
|
||||||
|
title: title,
|
||||||
|
players: players,
|
||||||
|
selectedPlayer: selectedPlayer,
|
||||||
|
adaptiveColorScheme: adaptiveColorScheme,
|
||||||
|
onPlayerSelected: (player) async {
|
||||||
|
Navigator.pop(context);
|
||||||
|
await onPlayerSelected(player);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
name: ensemble
|
name: ensemble
|
||||||
description: A minimalistic Music Assistant client built with Flutter
|
description: A minimalistic Music Assistant client built with Flutter
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 2.7.0-beta+30
|
version: 2.7.2-beta+31
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.0.0 <4.0.0'
|
sdk: '>=3.0.0 <4.0.0'
|
||||||
|
|||||||
Reference in New Issue
Block a user