2020-11-09 21:05:47 +00:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2020-11-28 21:32:17 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-06-23 19:23:12 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:audio_service/audio_service.dart';
|
2020-10-16 18:54:04 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2020-07-18 21:45:48 +00:00
|
|
|
import 'package:flutter_screenutil/screenutil.dart';
|
2021-04-16 18:21:35 +00:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2020-10-19 19:28:45 +00:00
|
|
|
import 'package:freezer/api/cache.dart';
|
2020-06-23 19:23:12 +00:00
|
|
|
import 'package:freezer/api/deezer.dart';
|
2020-11-28 21:32:17 +00:00
|
|
|
import 'package:freezer/api/download.dart';
|
2020-06-23 19:23:12 +00:00
|
|
|
import 'package:freezer/api/player.dart';
|
2020-10-16 18:54:04 +00:00
|
|
|
import 'package:freezer/settings.dart';
|
2020-09-18 17:36:41 +00:00
|
|
|
import 'package:freezer/translations.i18n.dart';
|
2020-10-19 19:28:45 +00:00
|
|
|
import 'package:freezer/ui/elements.dart';
|
2020-11-09 21:05:47 +00:00
|
|
|
import 'package:freezer/ui/lyrics.dart';
|
2020-06-23 19:23:12 +00:00
|
|
|
import 'package:freezer/ui/menu.dart';
|
2020-07-18 21:45:48 +00:00
|
|
|
import 'package:freezer/ui/settings_screen.dart';
|
2020-06-23 19:23:12 +00:00
|
|
|
import 'package:freezer/ui/tiles.dart';
|
2020-06-24 14:52:53 +00:00
|
|
|
import 'package:async/async.dart';
|
2020-08-13 17:39:22 +00:00
|
|
|
import 'package:just_audio/just_audio.dart';
|
2020-07-19 12:41:05 +00:00
|
|
|
import 'package:marquee/marquee.dart';
|
2020-11-09 21:05:47 +00:00
|
|
|
import 'package:palette_generator/palette_generator.dart';
|
2020-06-23 19:23:12 +00:00
|
|
|
|
|
|
|
import 'cached_image.dart';
|
|
|
|
import '../api/definitions.dart';
|
|
|
|
import 'player_bar.dart';
|
|
|
|
|
2020-09-18 17:36:41 +00:00
|
|
|
import 'dart:ui';
|
2021-02-09 20:14:14 +00:00
|
|
|
import 'dart:convert';
|
2020-09-18 17:36:41 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2021-02-09 20:14:14 +00:00
|
|
|
//Changing item in queue view and pressing back causes the pageView to skip song
|
|
|
|
bool pageViewLock = false;
|
2020-11-28 21:32:17 +00:00
|
|
|
|
2021-03-16 19:35:50 +00:00
|
|
|
//So can be updated when going back from lyrics
|
|
|
|
Function updateColor;
|
|
|
|
|
2020-06-23 19:23:12 +00:00
|
|
|
class PlayerScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_PlayerScreenState createState() => _PlayerScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PlayerScreenState extends State<PlayerScreen> {
|
|
|
|
|
2020-11-09 21:05:47 +00:00
|
|
|
LinearGradient _bgGradient;
|
|
|
|
StreamSubscription _mediaItemSub;
|
2021-02-09 20:14:14 +00:00
|
|
|
ImageProvider _blurImage;
|
2020-11-09 21:05:47 +00:00
|
|
|
|
|
|
|
//Calculate background color
|
2020-11-28 21:32:17 +00:00
|
|
|
Future _updateColor() async {
|
2021-02-09 20:14:14 +00:00
|
|
|
if (!settings.colorGradientBackground && !settings.blurPlayerBackground)
|
2020-11-09 21:05:47 +00:00
|
|
|
return;
|
2020-11-28 21:32:17 +00:00
|
|
|
|
2021-02-09 20:14:14 +00:00
|
|
|
//BG Image
|
|
|
|
if (settings.blurPlayerBackground)
|
|
|
|
setState(() {
|
|
|
|
_blurImage = NetworkImage(AudioService.currentMediaItem.extras['thumb'] ?? AudioService.currentMediaItem.artUri);
|
|
|
|
});
|
|
|
|
|
2020-11-28 21:32:17 +00:00
|
|
|
//Run in isolate
|
2020-11-09 21:05:47 +00:00
|
|
|
PaletteGenerator palette = await PaletteGenerator.fromImageProvider(CachedNetworkImageProvider(AudioService.currentMediaItem.extras['thumb'] ?? AudioService.currentMediaItem.artUri));
|
2020-11-28 21:32:17 +00:00
|
|
|
|
|
|
|
//Update notification
|
2021-02-09 20:14:14 +00:00
|
|
|
if (settings.blurPlayerBackground)
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
|
|
statusBarColor: palette.dominantColor.color.withOpacity(0.25),
|
|
|
|
systemNavigationBarColor: Color.alphaBlend(palette.dominantColor.color.withOpacity(0.25), Theme.of(context).scaffoldBackgroundColor)
|
|
|
|
));
|
|
|
|
|
|
|
|
//Color gradient
|
|
|
|
if (!settings.blurPlayerBackground) {
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
|
|
statusBarColor: palette.dominantColor.color.withOpacity(0.7),
|
|
|
|
));
|
|
|
|
setState(() => _bgGradient = LinearGradient(
|
|
|
|
begin: Alignment.topCenter,
|
|
|
|
end: Alignment.bottomCenter,
|
|
|
|
colors: [palette.dominantColor.color.withOpacity(0.7), Color.fromARGB(0, 0, 0, 0)],
|
|
|
|
stops: [
|
|
|
|
0.0,
|
|
|
|
0.6
|
|
|
|
]
|
|
|
|
));
|
|
|
|
}
|
2020-11-09 21:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2021-02-09 20:14:14 +00:00
|
|
|
Future.delayed(Duration(milliseconds: 600), _updateColor);
|
2020-11-09 21:05:47 +00:00
|
|
|
_mediaItemSub = AudioService.currentMediaItemStream.listen((event) {
|
2020-11-28 21:32:17 +00:00
|
|
|
_updateColor();
|
2020-11-09 21:05:47 +00:00
|
|
|
});
|
2021-03-16 19:35:50 +00:00
|
|
|
|
|
|
|
updateColor = this._updateColor;
|
2020-11-09 21:05:47 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2020-10-16 18:54:04 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
2020-11-09 21:05:47 +00:00
|
|
|
if (_mediaItemSub != null)
|
|
|
|
_mediaItemSub.cancel();
|
|
|
|
//Fix bottom buttons
|
2020-10-16 18:54:04 +00:00
|
|
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
|
|
systemNavigationBarColor: settings.themeData.bottomAppBarColor,
|
2020-11-28 21:32:17 +00:00
|
|
|
statusBarColor: Colors.transparent
|
2020-10-16 18:54:04 +00:00
|
|
|
));
|
|
|
|
super.dispose();
|
|
|
|
}
|
2020-06-23 19:23:12 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-07-18 21:45:48 +00:00
|
|
|
//Responsive
|
|
|
|
ScreenUtil.init(context, allowFontScaling: true);
|
|
|
|
|
2020-06-23 19:23:12 +00:00
|
|
|
return Scaffold(
|
2020-06-24 13:19:14 +00:00
|
|
|
body: SafeArea(
|
2020-11-09 21:05:47 +00:00
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
2021-02-09 20:14:14 +00:00
|
|
|
gradient: settings.blurPlayerBackground ? null : _bgGradient
|
2020-11-09 21:05:47 +00:00
|
|
|
),
|
2021-02-09 20:14:14 +00:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
if (settings.blurPlayerBackground && _blurImage != null)
|
|
|
|
ClipRect(
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
image: DecorationImage(
|
|
|
|
image: _blurImage,
|
|
|
|
fit: BoxFit.fill,
|
|
|
|
colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.25), BlendMode.dstATop)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
child: BackdropFilter(
|
|
|
|
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
|
|
|
|
child: Container(color: Colors.transparent),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
StreamBuilder(
|
|
|
|
stream: StreamZip([AudioService.playbackStateStream, AudioService.currentMediaItemStream]),
|
|
|
|
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
|
|
|
|
|
|
|
//When disconnected
|
|
|
|
if (AudioService.currentMediaItem == null) {
|
|
|
|
playerHelper.startService();
|
|
|
|
return Center(child: CircularProgressIndicator(),);
|
2020-11-09 21:05:47 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 20:14:14 +00:00
|
|
|
return OrientationBuilder(
|
|
|
|
builder: (context, orientation) {
|
|
|
|
//Landscape
|
|
|
|
if (orientation == Orientation.landscape) {
|
|
|
|
return PlayerScreenHorizontal();
|
|
|
|
}
|
|
|
|
//Portrait
|
|
|
|
return PlayerScreenVertical();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2020-11-09 21:05:47 +00:00
|
|
|
)
|
2020-07-18 21:45:48 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Landscape
|
|
|
|
class PlayerScreenHorizontal extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_PlayerScreenHorizontalState createState() => _PlayerScreenHorizontalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PlayerScreenHorizontalState extends State<PlayerScreenHorizontal> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
2020-10-14 19:09:16 +00:00
|
|
|
padding: EdgeInsets.fromLTRB(16, 0, 16, 8),
|
|
|
|
child: Container(
|
2020-07-18 21:45:48 +00:00
|
|
|
width: ScreenUtil().setWidth(500),
|
|
|
|
child: Stack(
|
|
|
|
children: <Widget>[
|
2020-10-15 18:37:36 +00:00
|
|
|
BigAlbumArt(),
|
2020-07-18 21:45:48 +00:00
|
|
|
],
|
|
|
|
),
|
2020-10-14 19:09:16 +00:00
|
|
|
),
|
2020-07-18 21:45:48 +00:00
|
|
|
),
|
|
|
|
//Right side
|
|
|
|
SizedBox(
|
|
|
|
width: ScreenUtil().setWidth(500),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(8, 16, 8, 0),
|
|
|
|
child: Container(
|
|
|
|
child: PlayerScreenTopRow(
|
2020-10-19 19:28:45 +00:00
|
|
|
textSize: ScreenUtil().setSp(24),
|
|
|
|
iconSize: ScreenUtil().setSp(36),
|
|
|
|
textWidth: ScreenUtil().setWidth(350),
|
2020-07-18 21:45:48 +00:00
|
|
|
short: true
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
2020-07-19 12:41:05 +00:00
|
|
|
Container(
|
2021-02-09 20:14:14 +00:00
|
|
|
height: ScreenUtil().setSp(50),
|
2020-07-19 12:41:05 +00:00
|
|
|
child: AudioService.currentMediaItem.displayTitle.length >= 22 ?
|
2021-02-09 20:14:14 +00:00
|
|
|
Marquee(
|
|
|
|
text: AudioService.currentMediaItem.displayTitle,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(40),
|
|
|
|
fontWeight: FontWeight.bold
|
|
|
|
),
|
|
|
|
blankSpace: 32.0,
|
|
|
|
startPadding: 10.0,
|
|
|
|
accelerationDuration: Duration(seconds: 1),
|
|
|
|
pauseAfterRound: Duration(seconds: 2),
|
|
|
|
):
|
|
|
|
Text(
|
|
|
|
AudioService.currentMediaItem.displayTitle,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(40),
|
|
|
|
fontWeight: FontWeight.bold
|
|
|
|
),
|
|
|
|
)
|
2020-07-18 21:45:48 +00:00
|
|
|
),
|
|
|
|
Container(height: 4,),
|
|
|
|
Text(
|
2020-10-25 09:47:56 +00:00
|
|
|
AudioService.currentMediaItem.displaySubtitle ?? '',
|
2020-07-18 21:45:48 +00:00
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
overflow: TextOverflow.clip,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(32),
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
child: SeekBar(),
|
|
|
|
),
|
2020-10-19 19:28:45 +00:00
|
|
|
PlaybackControls(ScreenUtil().setSp(60)),
|
2020-07-18 21:45:48 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(8, 0, 8, 16),
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 2.0),
|
|
|
|
child: Row(
|
2020-06-24 14:52:53 +00:00
|
|
|
mainAxisSize: MainAxisSize.max,
|
2020-07-18 21:45:48 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2020-06-24 14:52:53 +00:00
|
|
|
children: <Widget>[
|
2020-07-18 21:45:48 +00:00
|
|
|
IconButton(
|
2021-07-02 16:28:59 +00:00
|
|
|
icon: Icon(Icons.subtitles, size: ScreenUtil().setWidth(32),
|
|
|
|
semanticLabel: "Lyrics".i18n,),
|
2020-07-18 21:45:48 +00:00
|
|
|
onPressed: () {
|
2020-11-09 21:05:47 +00:00
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) => LyricsScreen(trackId: AudioService.currentMediaItem.id)
|
|
|
|
));
|
2020-07-18 21:45:48 +00:00
|
|
|
},
|
2020-06-24 14:52:53 +00:00
|
|
|
),
|
2020-11-28 21:32:17 +00:00
|
|
|
QualityInfoWidget(),
|
2020-11-01 19:23:24 +00:00
|
|
|
RepeatButton(ScreenUtil().setWidth(32)),
|
2020-11-28 21:32:17 +00:00
|
|
|
PlayerMenuButton()
|
2020-07-18 21:45:48 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-06-23 19:23:12 +00:00
|
|
|
|
2020-07-18 21:45:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
//Portrait
|
|
|
|
class PlayerScreenVertical extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_PlayerScreenVerticalState createState() => _PlayerScreenVerticalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PlayerScreenVerticalState extends State<PlayerScreenVertical> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
2020-10-19 19:28:45 +00:00
|
|
|
padding: EdgeInsets.fromLTRB(30, 4, 16, 0),
|
|
|
|
child: PlayerScreenTopRow()
|
2020-06-24 13:19:14 +00:00
|
|
|
),
|
2020-07-18 21:45:48 +00:00
|
|
|
Padding(
|
2020-10-19 19:28:45 +00:00
|
|
|
padding: EdgeInsets.fromLTRB(16, 0, 16, 0),
|
|
|
|
child: Container(
|
|
|
|
height: ScreenUtil().setHeight(1000),
|
|
|
|
child: Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
BigAlbumArt(),
|
|
|
|
],
|
2020-10-14 19:09:16 +00:00
|
|
|
),
|
2020-10-19 19:28:45 +00:00
|
|
|
),
|
2020-07-18 21:45:48 +00:00
|
|
|
),
|
2020-10-19 19:28:45 +00:00
|
|
|
Container(height: 4.0),
|
2020-07-18 21:45:48 +00:00
|
|
|
Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
2020-07-19 12:41:05 +00:00
|
|
|
Container(
|
2021-02-09 20:14:14 +00:00
|
|
|
height: ScreenUtil().setSp(80),
|
2020-12-14 17:29:28 +00:00
|
|
|
child: AudioService.currentMediaItem.displayTitle.length >= 26 ?
|
2021-02-09 20:14:14 +00:00
|
|
|
Marquee(
|
|
|
|
text: AudioService.currentMediaItem.displayTitle,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(64),
|
|
|
|
fontWeight: FontWeight.bold
|
|
|
|
),
|
|
|
|
blankSpace: 32.0,
|
|
|
|
startPadding: 10.0,
|
|
|
|
accelerationDuration: Duration(seconds: 1),
|
|
|
|
pauseAfterRound: Duration(seconds: 2),
|
|
|
|
):
|
|
|
|
Text(
|
|
|
|
AudioService.currentMediaItem.displayTitle,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(64),
|
|
|
|
fontWeight: FontWeight.bold
|
|
|
|
),
|
|
|
|
)
|
2020-07-18 21:45:48 +00:00
|
|
|
),
|
|
|
|
Container(height: 4,),
|
|
|
|
Text(
|
2020-10-25 09:47:56 +00:00
|
|
|
AudioService.currentMediaItem.displaySubtitle ?? '',
|
2020-07-18 21:45:48 +00:00
|
|
|
maxLines: 1,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
overflow: TextOverflow.clip,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(52),
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SeekBar(),
|
2020-10-19 19:28:45 +00:00
|
|
|
PlaybackControls(ScreenUtil().setWidth(100)),
|
2020-07-18 21:45:48 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 0, horizontal: 16.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
IconButton(
|
2021-07-02 16:28:59 +00:00
|
|
|
icon: Icon(Icons.subtitles, size: ScreenUtil().setWidth(46),
|
|
|
|
semanticLabel: "Lyrics".i18n,),
|
2021-03-16 19:35:50 +00:00
|
|
|
onPressed: () async {
|
|
|
|
//Fix bottom buttons
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
|
|
systemNavigationBarColor: settings.themeData.bottomAppBarColor,
|
|
|
|
statusBarColor: Colors.transparent
|
|
|
|
));
|
|
|
|
|
|
|
|
await Navigator.of(context).push(MaterialPageRoute(
|
2020-11-09 21:05:47 +00:00
|
|
|
builder: (context) => LyricsScreen(trackId: AudioService.currentMediaItem.id)
|
|
|
|
));
|
2021-03-16 19:35:50 +00:00
|
|
|
|
|
|
|
updateColor();
|
2020-07-18 21:45:48 +00:00
|
|
|
},
|
|
|
|
),
|
2021-04-16 18:21:35 +00:00
|
|
|
IconButton(
|
2021-07-02 16:28:59 +00:00
|
|
|
icon: Icon(Icons.file_download, semanticLabel: "Download".i18n,),
|
2021-04-16 18:21:35 +00:00
|
|
|
onPressed: () async {
|
|
|
|
Track t = Track.fromMediaItem(AudioService.currentMediaItem);
|
|
|
|
if (await downloadManager.addOfflineTrack(t, private: false, context: context, isSingleton: true) != false)
|
|
|
|
Fluttertoast.showToast(
|
|
|
|
msg: 'Downloads added!'.i18n,
|
|
|
|
gravity: ToastGravity.BOTTOM,
|
|
|
|
toastLength: Toast.LENGTH_SHORT
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2020-11-28 21:32:17 +00:00
|
|
|
QualityInfoWidget(),
|
2020-11-01 19:23:24 +00:00
|
|
|
RepeatButton(ScreenUtil().setWidth(46)),
|
2020-11-28 21:32:17 +00:00
|
|
|
PlayerMenuButton()
|
2020-07-18 21:45:48 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2020-06-23 19:23:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-28 21:32:17 +00:00
|
|
|
class QualityInfoWidget extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_QualityInfoWidgetState createState() => _QualityInfoWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _QualityInfoWidgetState extends State<QualityInfoWidget> {
|
|
|
|
|
|
|
|
String value = '';
|
|
|
|
StreamSubscription streamSubscription;
|
|
|
|
|
|
|
|
//Load data from native
|
|
|
|
void _load() async {
|
|
|
|
if (AudioService.currentMediaItem == null) return;
|
|
|
|
Map data = await DownloadManager.platform.invokeMethod("getStreamInfo", {"id": AudioService.currentMediaItem.id});
|
|
|
|
//N/A
|
|
|
|
if (data == null) {
|
|
|
|
setState(() => value = '');
|
|
|
|
//If not show, try again later
|
|
|
|
if (AudioService.currentMediaItem.extras['show'] == null)
|
|
|
|
Future.delayed(Duration(milliseconds: 200), _load);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//Update
|
|
|
|
StreamQualityInfo info = StreamQualityInfo.fromJson(data);
|
|
|
|
setState(() {
|
|
|
|
value = '${info.format} ${info.bitrate(AudioService.currentMediaItem.duration)}kbps';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_load();
|
|
|
|
if (streamSubscription == null)
|
|
|
|
streamSubscription = AudioService.currentMediaItemStream.listen((event) async {
|
|
|
|
await _load();
|
|
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
if (streamSubscription != null)
|
|
|
|
streamSubscription.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-04-05 20:22:32 +00:00
|
|
|
return TextButton(
|
2020-11-28 21:32:17 +00:00
|
|
|
child: Text(value),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (context) => QualitySettings()));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PlayerMenuButton extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return IconButton(
|
2021-07-02 16:28:59 +00:00
|
|
|
icon: Icon(Icons.more_vert, size: ScreenUtil().setWidth(46),
|
|
|
|
semanticLabel: "Options".i18n,),
|
2020-11-28 21:32:17 +00:00
|
|
|
onPressed: () {
|
|
|
|
Track t = Track.fromMediaItem(AudioService.currentMediaItem);
|
2020-12-27 18:33:59 +00:00
|
|
|
MenuSheet m = MenuSheet(context, navigateCallback: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
});
|
2020-11-28 21:32:17 +00:00
|
|
|
if (AudioService.currentMediaItem.extras['show'] == null)
|
2020-12-14 17:29:28 +00:00
|
|
|
m.defaultTrackMenu(t, options: [m.sleepTimer(), m.wakelock()]);
|
2020-11-28 21:32:17 +00:00
|
|
|
else
|
|
|
|
m.defaultShowEpisodeMenu(
|
|
|
|
Show.fromJson(jsonDecode(AudioService.currentMediaItem.extras['show'])),
|
|
|
|
ShowEpisode.fromMediaItem(AudioService.currentMediaItem),
|
2020-12-14 17:29:28 +00:00
|
|
|
options: [m.sleepTimer(), m.wakelock()]
|
2020-11-28 21:32:17 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-01 19:23:24 +00:00
|
|
|
|
|
|
|
class RepeatButton extends StatefulWidget {
|
2020-10-19 19:28:45 +00:00
|
|
|
|
|
|
|
final double iconSize;
|
2020-11-01 19:23:24 +00:00
|
|
|
RepeatButton(this.iconSize, {Key key}): super(key: key);
|
2020-10-19 19:28:45 +00:00
|
|
|
|
|
|
|
@override
|
2020-11-01 19:23:24 +00:00
|
|
|
_RepeatButtonState createState() => _RepeatButtonState();
|
2020-10-19 19:28:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-01 19:23:24 +00:00
|
|
|
class _RepeatButtonState extends State<RepeatButton> {
|
2020-10-19 19:28:45 +00:00
|
|
|
|
|
|
|
Icon get repeatIcon {
|
|
|
|
switch (playerHelper.repeatType) {
|
|
|
|
case LoopMode.off:
|
|
|
|
return Icon(
|
|
|
|
Icons.repeat,
|
2021-07-02 16:28:59 +00:00
|
|
|
size: widget.iconSize,
|
|
|
|
semanticLabel: "Repeat off".i18n,
|
2020-10-19 19:28:45 +00:00
|
|
|
);
|
|
|
|
case LoopMode.all:
|
|
|
|
return Icon(
|
|
|
|
Icons.repeat,
|
|
|
|
color: Theme.of(context).primaryColor,
|
2021-07-02 16:28:59 +00:00
|
|
|
size: widget.iconSize,
|
|
|
|
semanticLabel: "Repeat".i18n,
|
2020-10-19 19:28:45 +00:00
|
|
|
);
|
|
|
|
case LoopMode.one:
|
|
|
|
return Icon(
|
|
|
|
Icons.repeat_one,
|
|
|
|
color: Theme.of(context).primaryColor,
|
2021-07-02 16:28:59 +00:00
|
|
|
size: widget.iconSize,
|
|
|
|
semanticLabel: "Repeat one".i18n,
|
2020-10-19 19:28:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-01 19:23:24 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return IconButton(
|
|
|
|
icon: repeatIcon,
|
|
|
|
onPressed: () async {
|
|
|
|
await playerHelper.changeRepeat();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PlaybackControls extends StatefulWidget {
|
|
|
|
|
|
|
|
final double iconSize;
|
|
|
|
PlaybackControls(this.iconSize, {Key key}): super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_PlaybackControlsState createState() => _PlaybackControlsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PlaybackControlsState extends State<PlaybackControls> {
|
|
|
|
|
2020-10-19 19:28:45 +00:00
|
|
|
Icon get libraryIcon {
|
|
|
|
if (cache.checkTrackFavorite(Track.fromMediaItem(AudioService.currentMediaItem))) {
|
2021-07-02 16:28:59 +00:00
|
|
|
return Icon(Icons.favorite, size: widget.iconSize * 0.64, semanticLabel: "Unlove".i18n,);
|
2020-10-19 19:28:45 +00:00
|
|
|
}
|
2021-07-02 16:28:59 +00:00
|
|
|
return Icon(Icons.favorite_border, size: widget.iconSize * 0.64, semanticLabel: "Love".i18n,);
|
2020-10-19 19:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: [
|
|
|
|
IconButton(
|
2021-07-02 16:28:59 +00:00
|
|
|
icon: Icon(Icons.sentiment_very_dissatisfied, size: ScreenUtil().setWidth(46), semanticLabel: "Dislike".i18n,),
|
2020-11-01 19:23:24 +00:00
|
|
|
onPressed: () async {
|
|
|
|
await deezerAPI.dislikeTrack(AudioService.currentMediaItem.id);
|
|
|
|
if (playerHelper.queueIndex < (AudioService.queue??[]).length - 1) {
|
|
|
|
AudioService.skipToNext();
|
|
|
|
}
|
|
|
|
}
|
2020-10-19 19:28:45 +00:00
|
|
|
),
|
|
|
|
PrevNextButton(widget.iconSize, prev: true),
|
|
|
|
PlayPauseButton(widget.iconSize * 1.25),
|
|
|
|
PrevNextButton(widget.iconSize),
|
|
|
|
IconButton(
|
|
|
|
icon: libraryIcon,
|
|
|
|
onPressed: () async {
|
|
|
|
if (cache.libraryTracks == null)
|
|
|
|
cache.libraryTracks = [];
|
|
|
|
|
|
|
|
if (cache.checkTrackFavorite(Track.fromMediaItem(AudioService.currentMediaItem))) {
|
|
|
|
//Remove from library
|
|
|
|
setState(() => cache.libraryTracks.remove(AudioService.currentMediaItem.id));
|
|
|
|
await deezerAPI.removeFavorite(AudioService.currentMediaItem.id);
|
|
|
|
await cache.save();
|
|
|
|
} else {
|
|
|
|
//Add
|
|
|
|
setState(() => cache.libraryTracks.add(AudioService.currentMediaItem.id));
|
|
|
|
await deezerAPI.addFavoriteTrack(AudioService.currentMediaItem.id);
|
|
|
|
await cache.save();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-15 18:37:36 +00:00
|
|
|
class BigAlbumArt extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_BigAlbumArtState createState() => _BigAlbumArtState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _BigAlbumArtState extends State<BigAlbumArt> {
|
|
|
|
|
|
|
|
PageController _pageController = PageController(
|
|
|
|
initialPage: playerHelper.queueIndex,
|
|
|
|
);
|
|
|
|
StreamSubscription _currentItemSub;
|
|
|
|
bool _animationLock = true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_currentItemSub = AudioService.currentMediaItemStream.listen((event) async {
|
|
|
|
_animationLock = true;
|
|
|
|
await _pageController.animateToPage(playerHelper.queueIndex, duration: Duration(milliseconds: 300), curve: Curves.easeInOut);
|
|
|
|
_animationLock = false;
|
|
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
if (_currentItemSub != null)
|
|
|
|
_currentItemSub.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-19 19:28:45 +00:00
|
|
|
return GestureDetector(
|
|
|
|
onVerticalDragUpdate: (DragUpdateDetails details) {
|
|
|
|
if (details.delta.dy > 16) {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
2020-10-15 18:37:36 +00:00
|
|
|
},
|
2020-10-19 19:28:45 +00:00
|
|
|
child: PageView(
|
|
|
|
controller: _pageController,
|
|
|
|
onPageChanged: (int index) {
|
2021-02-09 20:14:14 +00:00
|
|
|
if (pageViewLock) {
|
|
|
|
pageViewLock = false;
|
|
|
|
return;
|
|
|
|
}
|
2020-10-19 19:28:45 +00:00
|
|
|
if (_animationLock) return;
|
|
|
|
AudioService.skipToQueueItem(AudioService.queue[index].id);
|
|
|
|
},
|
2020-10-22 21:24:30 +00:00
|
|
|
children: List.generate(AudioService.queue.length, (i) => ZoomableImage(url: AudioService.queue[i].artUri)),
|
2020-10-19 19:28:45 +00:00
|
|
|
),
|
2020-10-15 18:37:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-07-18 21:45:48 +00:00
|
|
|
|
2020-06-23 19:23:12 +00:00
|
|
|
//Top row containing QueueSource, queue...
|
|
|
|
class PlayerScreenTopRow extends StatelessWidget {
|
2020-07-18 21:45:48 +00:00
|
|
|
|
|
|
|
double textSize;
|
|
|
|
double iconSize;
|
|
|
|
double textWidth;
|
|
|
|
bool short;
|
|
|
|
PlayerScreenTopRow({this.textSize, this.iconSize, this.textWidth, this.short});
|
|
|
|
|
2020-06-23 19:23:12 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2020-10-19 19:28:45 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2020-06-23 19:23:12 +00:00
|
|
|
children: <Widget>[
|
2020-10-19 19:28:45 +00:00
|
|
|
Container(
|
|
|
|
width: this.textWidth??ScreenUtil().setWidth(800),
|
|
|
|
child: Text(
|
|
|
|
(short??false)?(playerHelper.queueSource.text??''):'Playing from:'.i18n + ' ' + (playerHelper.queueSource?.text??''),
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
style: TextStyle(fontSize: this.textSize??ScreenUtil().setSp(38)),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
2021-07-02 16:28:59 +00:00
|
|
|
icon: Icon(Icons.menu, semanticLabel: "Queue".i18n,),
|
2020-10-19 19:28:45 +00:00
|
|
|
iconSize: this.iconSize??ScreenUtil().setSp(52),
|
|
|
|
splashRadius: this.iconSize??ScreenUtil().setWidth(52),
|
2021-03-16 19:35:50 +00:00
|
|
|
onPressed: () async {
|
|
|
|
//Fix bottom buttons
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
|
|
systemNavigationBarColor: settings.themeData.bottomAppBarColor,
|
|
|
|
statusBarColor: Colors.transparent
|
|
|
|
));
|
|
|
|
//Navigate
|
|
|
|
await Navigator.of(context).push(MaterialPageRoute(
|
2020-10-19 19:28:45 +00:00
|
|
|
builder: (context) => QueueScreen()
|
|
|
|
));
|
2021-03-16 19:35:50 +00:00
|
|
|
//Fix colors
|
|
|
|
updateColor();
|
2020-10-19 19:28:45 +00:00
|
|
|
},
|
2020-06-23 19:23:12 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SeekBar extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_SeekBarState createState() => _SeekBarState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SeekBarState extends State<SeekBar> {
|
|
|
|
|
|
|
|
bool _seeking = false;
|
|
|
|
double _pos;
|
|
|
|
|
|
|
|
double get position {
|
|
|
|
if (_seeking) return _pos;
|
|
|
|
if (AudioService.playbackState == null) return 0.0;
|
|
|
|
double p = AudioService.playbackState.currentPosition.inMilliseconds.toDouble()??0.0;
|
|
|
|
if (p > duration) return duration;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Duration to mm:ss
|
|
|
|
String _timeString(double pos) {
|
|
|
|
Duration d = Duration(milliseconds: pos.toInt());
|
|
|
|
return "${d.inMinutes}:${d.inSeconds.remainder(60).toString().padLeft(2, '0')}";
|
|
|
|
}
|
|
|
|
|
|
|
|
double get duration {
|
|
|
|
if (AudioService.currentMediaItem == null) return 1.0;
|
|
|
|
return AudioService.currentMediaItem.duration.inMilliseconds.toDouble();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return StreamBuilder(
|
|
|
|
stream: Stream.periodic(Duration(milliseconds: 250)),
|
|
|
|
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
|
|
|
return Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 24.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
_timeString(position),
|
|
|
|
style: TextStyle(
|
2020-07-18 21:45:48 +00:00
|
|
|
fontSize: ScreenUtil().setSp(35)
|
2020-06-23 19:23:12 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
_timeString(duration),
|
|
|
|
style: TextStyle(
|
2020-07-18 21:45:48 +00:00
|
|
|
fontSize: ScreenUtil().setSp(35)
|
2020-06-23 19:23:12 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 32.0,
|
|
|
|
child: Slider(
|
2020-10-31 20:52:23 +00:00
|
|
|
focusNode: FocusNode(canRequestFocus: false, skipTraversal: true), // Don't focus on Slider - it doesn't work (and not needed)
|
2020-06-23 19:23:12 +00:00
|
|
|
value: position,
|
|
|
|
max: duration,
|
|
|
|
onChangeStart: (double d) {
|
|
|
|
setState(() {
|
|
|
|
_seeking = true;
|
|
|
|
_pos = d;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onChanged: (double d) {
|
|
|
|
setState(() {
|
|
|
|
_pos = d;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onChangeEnd: (double d) async {
|
|
|
|
await AudioService.seekTo(Duration(milliseconds: d.round()));
|
|
|
|
setState(() {
|
|
|
|
_pos = d;
|
|
|
|
_seeking = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class QueueScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_QueueScreenState createState() => _QueueScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _QueueScreenState extends State<QueueScreen> {
|
2020-08-13 17:39:22 +00:00
|
|
|
|
2020-10-17 19:20:26 +00:00
|
|
|
StreamSubscription _queueSub;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_queueSub = AudioService.queueStream.listen((event) {setState((){});});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
if (_queueSub != null)
|
|
|
|
_queueSub.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:23:12 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2020-10-19 19:28:45 +00:00
|
|
|
appBar: FreezerAppBar(
|
|
|
|
'Queue'.i18n,
|
2020-06-23 19:23:12 +00:00
|
|
|
actions: <Widget>[
|
|
|
|
IconButton(
|
2020-08-13 17:39:22 +00:00
|
|
|
icon: Icon(
|
|
|
|
Icons.shuffle,
|
2021-07-02 16:28:59 +00:00
|
|
|
semanticLabel: "Shuffle".i18n,
|
2020-08-13 17:39:22 +00:00
|
|
|
),
|
2020-06-23 19:23:12 +00:00
|
|
|
onPressed: () async {
|
2020-08-13 17:39:22 +00:00
|
|
|
await playerHelper.toggleShuffle();
|
|
|
|
setState(() {});
|
2020-06-23 19:23:12 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2020-10-16 18:54:04 +00:00
|
|
|
body: ReorderableListView(
|
|
|
|
onReorder: (int oldIndex, int newIndex) async {
|
|
|
|
if (oldIndex == playerHelper.queueIndex) return;
|
|
|
|
await playerHelper.reorder(oldIndex, newIndex);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
children: List.generate(AudioService.queue.length, (int i) {
|
2020-06-23 19:23:12 +00:00
|
|
|
Track t = Track.fromMediaItem(AudioService.queue[i]);
|
|
|
|
return TrackTile(
|
|
|
|
t,
|
|
|
|
onTap: () async {
|
2021-02-09 20:14:14 +00:00
|
|
|
pageViewLock = true;
|
|
|
|
await AudioService.skipToQueueItem(t.id);
|
2020-06-23 19:23:12 +00:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2021-02-09 20:14:14 +00:00
|
|
|
key: Key(i.toString()),
|
2020-12-14 17:29:28 +00:00
|
|
|
trailing: IconButton(
|
2021-07-02 16:28:59 +00:00
|
|
|
icon: Icon(Icons.close, semanticLabel: "Close".i18n,),
|
2020-12-14 17:29:28 +00:00
|
|
|
onPressed: () async {
|
|
|
|
await AudioService.removeQueueItem(t.toMediaItem());
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
2020-06-23 19:23:12 +00:00
|
|
|
);
|
2020-10-16 18:54:04 +00:00
|
|
|
}),
|
2020-06-23 19:23:12 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|