You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import 'package:chewie_audio/chewie_audio.dart'; import 'package:flutter/material.dart'; import 'package:sonnat/core/theme/app_colors.dart'; import 'package:sonnat/core/widgets/global_loading.dart'; import 'package:video_player/video_player.dart';
class AudioPlayer extends StatefulWidget { final String url;
const AudioPlayer({super.key, required this.url});
@override State<AudioPlayer> createState() => _AudioPlayerState(); }
class _AudioPlayerState extends State<AudioPlayer> { ChewieAudioController? chewieController; late VideoPlayerController videoPlayerController;
@override void initState() { super.initState(); videoPlayerController = VideoPlayerController.network(widget.url); }
Future<bool> initAudio() async { await videoPlayerController.initialize(); chewieController = ChewieAudioController( videoPlayerController: videoPlayerController, autoPlay: false, looping: false, ); return Future.value(true); }
@override Widget build(BuildContext context) { return FutureBuilder( future: initAudio(), builder: (context, snapshot) { if (snapshot.hasData) { return Container( decoration: BoxDecoration( boxShadow: const [ BoxShadow( color: AppColors.gray2, blurRadius: 1, offset: Offset.zero, spreadRadius: 1, ), ], borderRadius: BorderRadius.circular(16), ), child: ClipRRect( borderRadius: BorderRadius.circular(16), child: ChewieAudio( controller: chewieController!, ), ), ); } else if (snapshot.hasError) { return const Icon(Icons.error_outline); } return const GlobalLoading(isSmallSize: true); }); }
@override void dispose() { videoPlayerController.dispose(); chewieController?.dispose(); super.dispose(); } }
|