guide_screen.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. import 'package:assets_audio_player/assets_audio_player.dart';
  2. import 'package:flutter/material.dart';
  3. import '../components/background.dart';
  4. import '../components/playing_control.dart';
  5. import '../components/position_seek_widget.dart';
  6. import '../constants.dart';
  7. class GuideScreen extends StatefulWidget {
  8. @override
  9. _GuideScreenState createState() => _GuideScreenState();
  10. }
  11. class _GuideScreenState extends State<GuideScreen> {
  12. Audio find(List<Audio> source, String fromPath) {
  13. return source.firstWhere((element) => element.path == fromPath);
  14. }
  15. @override
  16. void initState() {
  17. // TODO: implement initState
  18. super.initState();
  19. albumBloc.guide('guide', 'guide');
  20. }
  21. @override
  22. void dispose() {
  23. // TODO: implement dispose
  24. super.dispose();
  25. assetsAudioPlayer.stop();
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return Background(
  30. image: Container(
  31. height: double.infinity,
  32. width: double.infinity,
  33. decoration: BoxDecoration(
  34. image: DecorationImage(
  35. image: AssetImage('assets/images/background_config.png'),
  36. fit: BoxFit.cover)),
  37. ),
  38. child: Scaffold(
  39. backgroundColor: Colors.transparent,
  40. appBar: AppBar(
  41. title: Text('GUIDE'),
  42. centerTitle: true,
  43. //actions: [IconButton(icon: Icon(Icons.close), onPressed: () {
  44. // Navigator.pop(context);
  45. // })],
  46. backgroundColor: Colors.transparent,
  47. elevation: 0.0,
  48. ),
  49. body: SingleChildScrollView(
  50. physics: BouncingScrollPhysics(),
  51. child: Column(
  52. children: [
  53. PlayerBuilder.isPlaying(
  54. player: assetsAudioPlayer,
  55. builder: (context, isPlaying) {
  56. return isPlaying
  57. ? assetsAudioPlayer.builderCurrent(
  58. builder: (context, playing) {
  59. if (playing == null) {
  60. return SizedBox();
  61. }
  62. final myAudio =
  63. find(audios, playing.audio.assetAudioPath);
  64. return Padding(
  65. padding: const EdgeInsets.only(
  66. left: 8.0, right: 8.0, bottom: 10),
  67. child: Column(
  68. children: <Widget>[
  69. assetsAudioPlayer.builderRealtimePlayingInfos(
  70. builder: (context, infos) {
  71. if (infos == null) {
  72. return SizedBox();
  73. }
  74. return Column(
  75. children: [
  76. Text(
  77. myAudio.metas.title,
  78. style: TextStyle(fontSize: 14),
  79. ),
  80. SizedBox(
  81. height: 10.0,
  82. ),
  83. Container(
  84. decoration: BoxDecoration(
  85. borderRadius:
  86. BorderRadius.circular(10),
  87. border: Border.all(
  88. color: Colors.white60)),
  89. child: ClipRRect(
  90. borderRadius:
  91. BorderRadius.circular(10.0),
  92. child: Image.network(
  93. myAudio.metas.image.path,
  94. height: 200,
  95. fit: BoxFit.fill,
  96. ),
  97. ),
  98. ),
  99. SizedBox(
  100. height: 10.0,
  101. ),
  102. PositionSeekWidget(
  103. currentPosition:
  104. infos.currentPosition,
  105. duration: infos.duration,
  106. seekTo: (to) {
  107. assetsAudioPlayer.seek(to);
  108. },
  109. ),
  110. ],
  111. );
  112. }),
  113. assetsAudioPlayer.builderLoopMode(
  114. builder: (context, loopMode) {
  115. return PlayerBuilder.isPlaying(
  116. player: assetsAudioPlayer,
  117. builder: (context, isPlaying) {
  118. return PlayingControls(
  119. loopMode: loopMode,
  120. isPlaying: isPlaying,
  121. isPlaylist: true,
  122. onStop: () {
  123. assetsAudioPlayer.stop();
  124. },
  125. toggleLoop: () {
  126. assetsAudioPlayer.toggleLoop();
  127. },
  128. onPlay: () {
  129. assetsAudioPlayer.playOrPause();
  130. },
  131. onNext: () {
  132. //_assetsAudioPlayer.forward(Duration(seconds: 10));
  133. assetsAudioPlayer.next(
  134. keepLoopMode:
  135. true /*keepLoopMode: false*/);
  136. },
  137. onPrevious: () {
  138. assetsAudioPlayer.previous(
  139. /*keepLoopMode: false*/);
  140. },
  141. );
  142. });
  143. },
  144. ),
  145. ],
  146. ),
  147. );
  148. })
  149. : SizedBox();
  150. }),
  151. Divider(
  152. color: Colors.teal[700],
  153. height: 5,
  154. ),
  155. StreamBuilder(
  156. stream: albumBloc.albumGuide,
  157. builder: (context, snapshot) {
  158. if (!snapshot.hasData) {
  159. return Center(
  160. child: CircularProgressIndicator(),
  161. );
  162. }
  163. return ListView.separated(
  164. shrinkWrap: true,
  165. padding: EdgeInsets.only(
  166. top: 10, left: 10, right: 10, bottom: 50),
  167. physics: BouncingScrollPhysics(),
  168. separatorBuilder: (BuildContext context, int index) =>
  169. Divider(
  170. color: Colors.white30,
  171. ),
  172. itemCount: snapshot.data.result.length,
  173. itemBuilder: (BuildContext context, int index) {
  174. return ListTile(
  175. leading: Image.network(
  176. kConfig['content'] +
  177. snapshot.data.result[index].poster.filename,
  178. fit: BoxFit.fill,
  179. width: 60,
  180. height: 60,
  181. ),
  182. trailing: Icon(Icons.play_circle_outline),
  183. title: Text(
  184. snapshot.data.result[index].title,
  185. overflow: TextOverflow.ellipsis,
  186. style: TextStyle(
  187. fontSize: 14, fontWeight: FontWeight.normal),
  188. ),
  189. onTap: () async {
  190. //print(snapshot.data.result[index].type);
  191. //print(snapshot.data.result[index].section);
  192. //print(snapshot.data.result[index].title);
  193. //print(kUrl + snapshot.data.result[index].poster.filename);
  194. //print(kUrl + snapshot.data.result[index].naration.filename);
  195. audios = <Audio>[
  196. Audio.network(
  197. kConfig['content'] +
  198. snapshot
  199. .data.result[index].naration.filename,
  200. metas: Metas(
  201. id: "Online",
  202. title: snapshot.data.result[index].title,
  203. artist: snapshot.data.result[index].section,
  204. album: snapshot.data.result[index].type,
  205. image: MetasImage.network(kConfig['content'] +
  206. snapshot
  207. .data.result[index].poster.filename),
  208. ),
  209. ),
  210. ];
  211. try {
  212. await assetsAudioPlayer.open(
  213. audios[0],
  214. autoStart: true,
  215. showNotification: false,
  216. playInBackground: PlayInBackground.enabled,
  217. audioFocusStrategy: AudioFocusStrategy.request(
  218. resumeAfterInterruption: true,
  219. resumeOthersPlayersAfterDone: true),
  220. headPhoneStrategy:
  221. HeadPhoneStrategy.pauseOnUnplug,
  222. );
  223. } catch (e) {
  224. print(e);
  225. }
  226. },
  227. );
  228. });
  229. },
  230. ),
  231. ],
  232. ),
  233. ),
  234. ),
  235. );
  236. }
  237. }