mirror of
https://github.com/stonega/tsacdop
synced 2025-02-17 20:10:37 +01:00
Play from search result.
This commit is contained in:
parent
7bbcb78fe0
commit
35b1e5c372
@ -62,13 +62,11 @@ class PlayerWidget extends StatelessWidget {
|
||||
height: 60,
|
||||
child:
|
||||
Column(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
|
||||
Selector<AudioPlayerNotifier, Tuple2<String, double>>(
|
||||
Selector<AudioPlayerNotifier, Tuple2<EpisodeBrief, double>>(
|
||||
selector: (_, audio) =>
|
||||
Tuple2(audio.episode?.primaryColor, audio.seekSliderValue),
|
||||
Tuple2(audio.episode, audio.seekSliderValue),
|
||||
builder: (_, data, __) {
|
||||
final c = context.brightness == Brightness.light
|
||||
? data.item1.colorizedark()
|
||||
: data.item1.colorizeLight();
|
||||
final c = data.item1.backgroudColor(context);
|
||||
return SizedBox(
|
||||
height: 2,
|
||||
child: LinearProgressIndicator(
|
||||
|
@ -11,6 +11,7 @@ import 'package:flutter_html/flutter_html.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tsacdop/state/audio_state.dart';
|
||||
import 'package:tsacdop/type/episodebrief.dart';
|
||||
import 'package:webfeed/webfeed.dart';
|
||||
|
||||
import '../.env.dart';
|
||||
@ -1002,17 +1003,16 @@ class _SearchResultDetailState extends State<SearchResultDetail>
|
||||
: Text(context.s.loadMore),
|
||||
onPressed: () {
|
||||
if (widget.searchEngine ==
|
||||
SearchEngine.listenNotes) {
|
||||
_loading
|
||||
? null
|
||||
: setState(
|
||||
() {
|
||||
_loading = true;
|
||||
_searchFuture = _getListenNotesEpisodes(
|
||||
id: widget.onlinePodcast.id,
|
||||
nextEpisodeDate: _nextEpisdoeDate);
|
||||
},
|
||||
);
|
||||
SearchEngine.listenNotes &&
|
||||
!_loading) {
|
||||
setState(
|
||||
() {
|
||||
_loading = true;
|
||||
_searchFuture = _getListenNotesEpisodes(
|
||||
id: widget.onlinePodcast.id,
|
||||
nextEpisodeDate: _nextEpisdoeDate);
|
||||
},
|
||||
);
|
||||
}
|
||||
}),
|
||||
),
|
||||
@ -1027,25 +1027,37 @@ class _SearchResultDetailState extends State<SearchResultDetail>
|
||||
: '${content[index].length.toTime} | '
|
||||
'${content[index].pubDate.toDate(context)}',
|
||||
style: TextStyle(color: context.accentColor)),
|
||||
trailing: TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all<Color>(
|
||||
context.accentColor),
|
||||
overlayColor: MaterialStateProperty.all<Color>(
|
||||
context.primaryColor.withOpacity(0.3)),
|
||||
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
|
||||
EdgeInsets.symmetric(horizontal: 2))),
|
||||
child: Text(context.s.play),
|
||||
onPressed: () {
|
||||
context.read<AudioPlayerNotifier>().episodeLoad(
|
||||
content[index].toEpisode,
|
||||
fromSearch: true);
|
||||
Fluttertoast.showToast(
|
||||
msg: 'Wait a moment',
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
},
|
||||
),
|
||||
trailing: Selector<AudioPlayerNotifier, EpisodeBrief>(
|
||||
selector: (_, audio) => audio.episode,
|
||||
builder: (_, episode, __) {
|
||||
if (episode != null &&
|
||||
episode.enclosureUrl == content[index].audio) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 15,
|
||||
child: WaveLoader(color: context.accentColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
return TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all<Color>(
|
||||
context.accentColor),
|
||||
overlayColor: MaterialStateProperty.all<Color>(
|
||||
context.scaffoldBackgroundColor.withOpacity(0.3)),
|
||||
padding:
|
||||
MaterialStateProperty.all<EdgeInsetsGeometry>(
|
||||
EdgeInsets.symmetric(horizontal: 2))),
|
||||
child: Text(context.s.play.toUpperCase()),
|
||||
onPressed: () {
|
||||
context.read<AudioPlayerNotifier>().episodeLoad(
|
||||
content[index].toEpisode,
|
||||
fromSearch: true);
|
||||
},
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@ -282,7 +282,9 @@ class AudioPlayerNotifier extends ChangeNotifier {
|
||||
await _playlist.getPlaylist();
|
||||
if (state[1] != '') {
|
||||
var episode = await _dbHelper.getRssItemWithUrl(state[1]);
|
||||
if ((!_playlist.isQueue && episode != null && _playlist.contains(episode)) ||
|
||||
if ((!_playlist.isQueue &&
|
||||
episode != null &&
|
||||
_playlist.contains(episode)) ||
|
||||
(_playlist.isQueue &&
|
||||
_queue.isNotEmpty &&
|
||||
_queue.episodes.first.title == episode.title)) {
|
||||
@ -371,9 +373,13 @@ class AudioPlayerNotifier extends ChangeNotifier {
|
||||
}
|
||||
//TODO load episode from last position when player running
|
||||
if (playerRunning) {
|
||||
final history = PlayHistory(_episode.title, _episode.enclosureUrl,
|
||||
backgroundAudioPosition ~/ 1000, seekSliderValue);
|
||||
await _dbHelper.saveHistory(history);
|
||||
if (_playFromSearchList.contains(_episode)) {
|
||||
_queue.delFromPlaylist(_episode);
|
||||
} else {
|
||||
final history = PlayHistory(_episode.title, _episode.enclosureUrl,
|
||||
backgroundAudioPosition ~/ 1000, seekSliderValue);
|
||||
await _dbHelper.saveHistory(history);
|
||||
}
|
||||
_queue.addToPlayListAt(episodeNew, 0);
|
||||
await updatePlaylist(_queue, updateEpisodes: !fromSearch);
|
||||
if (!_playlist.isQueue) {
|
||||
@ -495,8 +501,9 @@ class AudioPlayerNotifier extends ChangeNotifier {
|
||||
.where((event) => event != null)
|
||||
.listen((item) async {
|
||||
var episode = await _dbHelper.getRssItemWithMediaId(item.id);
|
||||
if(episode == null){
|
||||
episode = _playFromSearchList.firstWhere((e) => e.mediaId == item.id, orElse: () => null);
|
||||
if (episode == null) {
|
||||
episode = _playFromSearchList.firstWhere((e) => e.mediaId == item.id,
|
||||
orElse: () => null);
|
||||
}
|
||||
_backgroundAudioDuration = item.duration?.inMilliseconds ?? 0;
|
||||
if (episode != null) {
|
||||
|
@ -72,6 +72,7 @@ class EpisodeBrief extends Equatable {
|
||||
}
|
||||
|
||||
Color backgroudColor(BuildContext context) {
|
||||
if (primaryColor == '') return context.accentColor;
|
||||
return context.brightness == Brightness.light
|
||||
? primaryColor.colorizedark()
|
||||
: primaryColor.colorizeLight();
|
||||
|
@ -51,7 +51,7 @@ class OnlineEpisode {
|
||||
0,
|
||||
pubDate,
|
||||
title,
|
||||
jsonEncode([120,220,128]),
|
||||
'',
|
||||
length ?? 0,
|
||||
0,
|
||||
'',
|
||||
|
Loading…
x
Reference in New Issue
Block a user