Untitled
unknown
plain_text
10 months ago
5.3 kB
2
Indexable
class JustMusicPlay extends StatefulWidget { final String audioLink; final String thumbnailLink; final String headingName; final String albumName; final String heroTag; final AudioPlayer audioPlayer; final PanelController? panelController; final ScrollController? scrollController; const JustMusicPlay({ Key? key, required this.audioLink, required this.thumbnailLink, required this.headingName, required this.heroTag, required this.audioPlayer, required this.albumName, this.panelController,this.scrollController, }) : super(key: key); @override State<JustMusicPlay> createState() => _JustMusicPlayState(); } class _JustMusicPlayState extends State<JustMusicPlay> { bool isPlaying = false; @override void initState() { playSongs(); newMethod(); super.initState(); } playSongs() { try { widget.audioPlayer.setAudioSource( AudioSource.uri( Uri.parse(widget.audioLink), tag: newMethod(), ), ); if (widget.audioPlayer.playing) { // this was the issue for notification not changing setState(() { widget.audioPlayer.stop(); }); } widget.audioPlayer.play(); isPlaying = true; } on Exception { log("ERROR PARSING DATA"); } } MediaItem newMethod() { return MediaItem( id: widget.headingName, album: widget.albumName, title: widget.headingName, artUri: Uri.parse(widget.thumbnailLink), ); } @override Widget build(BuildContext context) { final miniPlayerProvider = Provider.of<MiniPlayerVisibilityProvider>(context); return Scaffold( appBar: AppBar( elevation: 0, title: Text(widget.headingName, style: const TextStyle(fontSize: 22)), backgroundColor: blackColor, leading: IconButton( icon: const Icon(Icons.arrow_back_sharp), color: Colors.white, onPressed: () { Navigator.pop(context); // navigatorKey.currentState!.pop(); }, ), actions: [ IconButton( icon: const Icon( Icons.share, color: whiteColor, ), onPressed: () {}, ), ], ), body: Container( color: blackColor, child: Column( children: [ //image of channel Padding( padding: const EdgeInsets.only(top: 50.0, left: 14.0, right: 14.0), child: ClipRRect( borderRadius: const BorderRadius.all(Radius.circular(10.0)), //image code child: Hero( tag: widget.heroTag, child: Image.network( (widget.thumbnailLink), height: 370, width: 500, fit: BoxFit.cover, ))), ), //player icons with func Center( child: Padding( padding: const EdgeInsets.only(top: 38.0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Center( child: IconButton( onPressed: () { if (isPlaying) { widget.audioPlayer.pause(); } else { widget.audioPlayer.play(); } setState(() { isPlaying = !isPlaying; }); }, iconSize: 65, icon: isPlaying ? const Icon( Icons.pause_circle, color: whiteColor, ) : const Icon( Icons.play_circle, color: whiteColor, ), ), ), const SizedBox( width: 20, ), IconButton( onPressed: () { if (isPlaying) { widget.audioPlayer.stop(); } miniPlayerProvider .hideMiniPlayer(); // Mini player ko invisible karne ka code yahan hai Navigator.pop(context); }, iconSize: 65, icon: const Icon( Icons.stop_circle_outlined, color: whiteColor, )), ], ), ), ), ], ), ), ); } }
Editor is loading...
Leave a Comment