Cached image performace, background audio bug
This commit is contained in:
parent
ed087bc583
commit
7df500bc9c
|
@ -61,7 +61,7 @@ class DeezerAPI {
|
||||||
'gateway_input': gatewayInput
|
'gateway_input': gatewayInput
|
||||||
},
|
},
|
||||||
data: jsonEncode(params??{}),
|
data: jsonEncode(params??{}),
|
||||||
options: Options(responseType: ResponseType.json, sendTimeout: 7000, receiveTimeout: 7000)
|
options: Options(responseType: ResponseType.json, sendTimeout: 5000, receiveTimeout: 5000)
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -545,8 +545,15 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
||||||
source = 'Stream';
|
source = 'Stream';
|
||||||
}
|
}
|
||||||
//Calculate
|
//Calculate
|
||||||
int bitrate = ((size / 125) / duration.inSeconds).floor();
|
return '$format ${_bitrateString(size, duration.inSeconds)} ($source)';
|
||||||
return '$format ${bitrate}kbps ($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
|
//Magic number to string, source: https://en.wikipedia.org/wiki/List_of_file_signatures
|
||||||
|
@ -564,17 +571,15 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onTaskRemoved() async {
|
void onTaskRemoved() async {
|
||||||
await _saveQueue();
|
await onStop();
|
||||||
onStop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future onStop() async {
|
Future onStop() async {
|
||||||
await _saveQueue();
|
_audioPlayer.stop();
|
||||||
|
|
||||||
if (_playing != null) _audioPlayer.stop();
|
|
||||||
if (_playerStateSub != null) _playerStateSub.cancel();
|
if (_playerStateSub != null) _playerStateSub.cancel();
|
||||||
if (_eventSub != null) _eventSub.cancel();
|
if (_eventSub != null) _eventSub.cancel();
|
||||||
|
await _saveQueue();
|
||||||
|
|
||||||
await super.onStop();
|
await super.onStop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,7 @@ class _CachedImageState extends State<CachedImage> {
|
||||||
ImageProvider _image = AssetImage('assets/cover.jpg');
|
ImageProvider _image = AssetImage('assets/cover.jpg');
|
||||||
double _opacity = 0.0;
|
double _opacity = 0.0;
|
||||||
bool _disposed = false;
|
bool _disposed = false;
|
||||||
|
String _prevUrl;
|
||||||
|
|
||||||
Future<ImageProvider> _getImage() async {
|
Future<ImageProvider> _getImage() async {
|
||||||
//Image already path
|
//Image already path
|
||||||
|
@ -146,6 +147,7 @@ class _CachedImageState extends State<CachedImage> {
|
||||||
_image = image;
|
_image = image;
|
||||||
_opacity = 1.0;
|
_opacity = 1.0;
|
||||||
});
|
});
|
||||||
|
_prevUrl = widget.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -162,6 +164,7 @@ class _CachedImageState extends State<CachedImage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(CachedImage oldWidget) {
|
void didUpdateWidget(CachedImage oldWidget) {
|
||||||
|
if (_prevUrl == widget.url) return;
|
||||||
_load();
|
_load();
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,13 +126,13 @@ class _HomePageScreenState extends State<HomePageScreen> {
|
||||||
return ErrorScreen();
|
return ErrorScreen();
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
...List.generate(_homePage.sections.length, (i) {
|
children: List.generate(_homePage.sections.length, (i) {
|
||||||
HomePageSection section = _homePage.sections[i];
|
HomePageSection section = _homePage.sections[i];
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
child: Text(
|
child: Text(
|
||||||
section.title,
|
section.title,
|
||||||
|
@ -146,9 +146,28 @@ class _HomePageScreenState extends State<HomePageScreen> {
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: List<Widget>.generate(section.items.length, (i) {
|
children: List.generate(section.items.length, (i) {
|
||||||
HomePageItem item = section.items[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) {
|
switch (item.type) {
|
||||||
case HomePageItemType.SMARTTRACKLIST:
|
case HomePageItemType.SMARTTRACKLIST:
|
||||||
return SmartTrackListTile(
|
return SmartTrackListTile(
|
||||||
|
@ -210,15 +229,5 @@ class _HomePageScreenState extends State<HomePageScreen> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Container(height: 0, width: 0);
|
return Container(height: 0, width: 0);
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Container(height: 16.0,)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
})
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: StreamBuilder(
|
body: SafeArea(
|
||||||
|
child: StreamBuilder(
|
||||||
stream: AudioService.playbackStateStream,
|
stream: AudioService.playbackStateStream,
|
||||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(16, 32, 16, 8),
|
padding: EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 320,
|
width: 320,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
|
@ -69,7 +70,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(8, 42, 8, 0),
|
padding: EdgeInsets.fromLTRB(8, 16, 8, 0),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 300,
|
width: 300,
|
||||||
child: PlayerScreenTopRow(),
|
child: PlayerScreenTopRow(),
|
||||||
|
@ -159,7 +160,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(28, 28, 28, 0),
|
padding: EdgeInsets.fromLTRB(28, 16, 28, 0),
|
||||||
child: PlayerScreenTopRow()
|
child: PlayerScreenTopRow()
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
|
@ -250,6 +251,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,7 +230,8 @@ class PlaylistCardTile extends StatelessWidget {
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: TextStyle(fontSize: 16.0),
|
style: TextStyle(fontSize: 16.0),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
Container(height: 8.0,)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -272,7 +273,8 @@ class SmartTrackListTile extends StatelessWidget {
|
||||||
fontSize: 16.0
|
fontSize: 16.0
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
Container(height: 8.0,)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -315,7 +317,8 @@ class AlbumCard extends StatelessWidget {
|
||||||
fontSize: 16.0
|
fontSize: 16.0
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
Container(height: 8.0,)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -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.
|
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
|
||||||
# Read more about iOS versioning at
|
# Read more about iOS versioning at
|
||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
version: 0.1.0
|
version: 0.1.0+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.7.0 <3.0.0"
|
sdk: ">=2.7.0 <3.0.0"
|
||||||
|
|
Loading…
Reference in New Issue