123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- import 'package:assets_audio_player/assets_audio_player.dart';
- import 'package:flutter/material.dart';
- import '../components/background.dart';
- import '../components/playing_control.dart';
- import '../components/position_seek_widget.dart';
- import '../constants.dart';
- class GuideScreen extends StatefulWidget {
- @override
- _GuideScreenState createState() => _GuideScreenState();
- }
- class _GuideScreenState extends State<GuideScreen> {
- Audio find(List<Audio> source, String fromPath) {
- return source.firstWhere((element) => element.path == fromPath);
- }
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- albumBloc.guide('guide', 'guide');
- }
- @override
- void dispose() {
- // TODO: implement dispose
- super.dispose();
- assetsAudioPlayer.stop();
- }
- @override
- Widget build(BuildContext context) {
- return Background(
- image: Container(
- height: double.infinity,
- width: double.infinity,
- decoration: BoxDecoration(
- image: DecorationImage(
- image: AssetImage('assets/images/background_config.png'),
- fit: BoxFit.cover)),
- ),
- child: Scaffold(
- backgroundColor: Colors.transparent,
- appBar: AppBar(
- title: Text('GUIDE'),
- centerTitle: true,
- //actions: [IconButton(icon: Icon(Icons.close), onPressed: () {
- // Navigator.pop(context);
- // })],
- backgroundColor: Colors.transparent,
- elevation: 0.0,
- ),
- body: SingleChildScrollView(
- physics: BouncingScrollPhysics(),
- child: Column(
- children: [
- PlayerBuilder.isPlaying(
- player: assetsAudioPlayer,
- builder: (context, isPlaying) {
- return isPlaying
- ? assetsAudioPlayer.builderCurrent(
- builder: (context, playing) {
- if (playing == null) {
- return SizedBox();
- }
- final myAudio =
- find(audios, playing.audio.assetAudioPath);
- return Padding(
- padding: const EdgeInsets.only(
- left: 8.0, right: 8.0, bottom: 10),
- child: Column(
- children: <Widget>[
- assetsAudioPlayer.builderRealtimePlayingInfos(
- builder: (context, infos) {
- if (infos == null) {
- return SizedBox();
- }
- return Column(
- children: [
- Text(
- myAudio.metas.title,
- style: TextStyle(fontSize: 14),
- ),
- SizedBox(
- height: 10.0,
- ),
- Container(
- decoration: BoxDecoration(
- borderRadius:
- BorderRadius.circular(10),
- border: Border.all(
- color: Colors.white60)),
- child: ClipRRect(
- borderRadius:
- BorderRadius.circular(10.0),
- child: Image.network(
- myAudio.metas.image.path,
- height: 200,
- fit: BoxFit.fill,
- ),
- ),
- ),
- SizedBox(
- height: 10.0,
- ),
- PositionSeekWidget(
- currentPosition:
- infos.currentPosition,
- duration: infos.duration,
- seekTo: (to) {
- assetsAudioPlayer.seek(to);
- },
- ),
- ],
- );
- }),
- assetsAudioPlayer.builderLoopMode(
- builder: (context, loopMode) {
- return PlayerBuilder.isPlaying(
- player: assetsAudioPlayer,
- builder: (context, isPlaying) {
- return PlayingControls(
- loopMode: loopMode,
- isPlaying: isPlaying,
- isPlaylist: true,
- onStop: () {
- assetsAudioPlayer.stop();
- },
- toggleLoop: () {
- assetsAudioPlayer.toggleLoop();
- },
- onPlay: () {
- assetsAudioPlayer.playOrPause();
- },
- onNext: () {
- //_assetsAudioPlayer.forward(Duration(seconds: 10));
- assetsAudioPlayer.next(
- keepLoopMode:
- true /*keepLoopMode: false*/);
- },
- onPrevious: () {
- assetsAudioPlayer.previous(
- /*keepLoopMode: false*/);
- },
- );
- });
- },
- ),
- ],
- ),
- );
- })
- : SizedBox();
- }),
- Divider(
- color: Colors.teal[700],
- height: 5,
- ),
- StreamBuilder(
- stream: albumBloc.albumGuide,
- builder: (context, snapshot) {
- if (!snapshot.hasData) {
- return Center(
- child: CircularProgressIndicator(),
- );
- }
- return ListView.separated(
- shrinkWrap: true,
- padding: EdgeInsets.only(
- top: 10, left: 10, right: 10, bottom: 50),
- physics: BouncingScrollPhysics(),
- separatorBuilder: (BuildContext context, int index) =>
- Divider(
- color: Colors.white30,
- ),
- itemCount: snapshot.data.result.length,
- itemBuilder: (BuildContext context, int index) {
- return ListTile(
- leading: Image.network(
- kConfig['content'] +
- snapshot.data.result[index].poster.filename,
- fit: BoxFit.fill,
- width: 60,
- height: 60,
- ),
- trailing: Icon(Icons.play_circle_outline),
- title: Text(
- snapshot.data.result[index].title,
- overflow: TextOverflow.ellipsis,
- style: TextStyle(
- fontSize: 14, fontWeight: FontWeight.normal),
- ),
- onTap: () async {
- //print(snapshot.data.result[index].type);
- //print(snapshot.data.result[index].section);
- //print(snapshot.data.result[index].title);
- //print(kUrl + snapshot.data.result[index].poster.filename);
- //print(kUrl + snapshot.data.result[index].naration.filename);
- audios = <Audio>[
- Audio.network(
- kConfig['content'] +
- snapshot
- .data.result[index].naration.filename,
- metas: Metas(
- id: "Online",
- title: snapshot.data.result[index].title,
- artist: snapshot.data.result[index].section,
- album: snapshot.data.result[index].type,
- image: MetasImage.network(kConfig['content'] +
- snapshot
- .data.result[index].poster.filename),
- ),
- ),
- ];
- try {
- await assetsAudioPlayer.open(
- audios[0],
- autoStart: true,
- showNotification: false,
- playInBackground: PlayInBackground.enabled,
- audioFocusStrategy: AudioFocusStrategy.request(
- resumeAfterInterruption: true,
- resumeOthersPlayersAfterDone: true),
- headPhoneStrategy:
- HeadPhoneStrategy.pauseOnUnplug,
- );
- } catch (e) {
- print(e);
- }
- },
- );
- });
- },
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
|