Cached image performace, background audio bug

This commit is contained in:
exttex 2020-06-24 15:19:14 +02:00
parent ed087bc583
commit 7df500bc9c
7 changed files with 334 additions and 312 deletions

View File

@ -61,7 +61,7 @@ class DeezerAPI {
'gateway_input': gatewayInput
},
data: jsonEncode(params??{}),
options: Options(responseType: ResponseType.json, sendTimeout: 7000, receiveTimeout: 7000)
options: Options(responseType: ResponseType.json, sendTimeout: 5000, receiveTimeout: 5000)
);
return response.data;
}

View File

@ -545,8 +545,15 @@ class AudioPlayerTask extends BackgroundAudioTask {
source = 'Stream';
}
//Calculate
int bitrate = ((size / 125) / duration.inSeconds).floor();
return '$format ${bitrate}kbps ($source)';
return '$format ${_bitrateString(size, duration.inSeconds)} ($source)';
}
String _bitrateString(int size, int duration) {
int bitrate = ((size / 125) / duration).floor();
//Prettify
if (bitrate > 315 && bitrate < 325) return '320kbps';
if (bitrate > 125 && bitrate < 135) return '128kbps';
return '${bitrate}kbps';
}
//Magic number to string, source: https://en.wikipedia.org/wiki/List_of_file_signatures
@ -564,17 +571,15 @@ class AudioPlayerTask extends BackgroundAudioTask {
@override
void onTaskRemoved() async {
await _saveQueue();
onStop();
await onStop();
}
@override
Future onStop() async {
await _saveQueue();
if (_playing != null) _audioPlayer.stop();
_audioPlayer.stop();
if (_playerStateSub != null) _playerStateSub.cancel();
if (_eventSub != null) _eventSub.cancel();
await _saveQueue();
await super.onStop();
}

View File

@ -124,6 +124,7 @@ class _CachedImageState extends State<CachedImage> {
ImageProvider _image = AssetImage('assets/cover.jpg');
double _opacity = 0.0;
bool _disposed = false;
String _prevUrl;
Future<ImageProvider> _getImage() async {
//Image already path
@ -146,6 +147,7 @@ class _CachedImageState extends State<CachedImage> {
_image = image;
_opacity = 1.0;
});
_prevUrl = widget.url;
}
@override
@ -162,6 +164,7 @@ class _CachedImageState extends State<CachedImage> {
@override
void didUpdateWidget(CachedImage oldWidget) {
if (_prevUrl == widget.url) return;
_load();
super.didUpdateWidget(oldWidget);
}

View File

@ -126,13 +126,13 @@ class _HomePageScreenState extends State<HomePageScreen> {
return ErrorScreen();
return SingleChildScrollView(
child: Column(
children: <Widget>[
...List.generate(_homePage.sections.length, (i) {
crossAxisAlignment: CrossAxisAlignment.start,
children: List.generate(_homePage.sections.length, (i) {
HomePageSection section = _homePage.sections[i];
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
children: [
Padding(
child: Text(
section.title,
@ -146,9 +146,28 @@ class _HomePageScreenState extends State<HomePageScreen> {
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List<Widget>.generate(section.items.length, (i) {
children: List.generate(section.items.length, (i) {
HomePageItem item = section.items[i];
return HomePageItemWidget(item);
}),
),
),
],
);
}),
),
);
}
}
class HomePageItemWidget extends StatelessWidget {
HomePageItem item;
HomePageItemWidget(this.item);
@override
Widget build(BuildContext context) {
switch (item.type) {
case HomePageItemType.SMARTTRACKLIST:
return SmartTrackListTile(
@ -210,15 +229,5 @@ class _HomePageScreenState extends State<HomePageScreen> {
);
}
return Container(height: 0, width: 0);
}),
),
),
Container(height: 16.0,)
],
);
})
],
),
);
}
}

View File

@ -27,7 +27,8 @@ class _PlayerScreenState extends State<PlayerScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder(
body: SafeArea(
child: StreamBuilder(
stream: AudioService.playbackStateStream,
builder: (BuildContext context, AsyncSnapshot snapshot) {
@ -44,7 +45,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(16, 32, 16, 8),
padding: EdgeInsets.fromLTRB(16, 0, 16, 8),
child: Container(
width: 320,
child: Stack(
@ -69,7 +70,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(8, 42, 8, 0),
padding: EdgeInsets.fromLTRB(8, 16, 8, 0),
child: Container(
width: 300,
child: PlayerScreenTopRow(),
@ -159,7 +160,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(28, 28, 28, 0),
padding: EdgeInsets.fromLTRB(28, 16, 28, 0),
child: PlayerScreenTopRow()
),
Padding(
@ -250,6 +251,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
},
);
},
),
)
);
}

View File

@ -230,7 +230,8 @@ class PlaylistCardTile extends StatelessWidget {
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 16.0),
),
)
),
Container(height: 8.0,)
],
),
)
@ -272,7 +273,8 @@ class SmartTrackListTile extends StatelessWidget {
fontSize: 16.0
),
),
)
),
Container(height: 8.0,)
],
),
),
@ -315,7 +317,8 @@ class AlbumCard extends StatelessWidget {
fontSize: 16.0
),
),
)
),
Container(height: 8.0,)
],
),
)

View File

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.1.0
version: 0.1.0+1
environment:
sdk: ">=2.7.0 <3.0.0"