import 'package:f0ckapp/models/mediaitem_detail.dart'; import 'package:flutter/material.dart'; import 'package:media_kit/media_kit.dart'; import 'package:media_kit_video/media_kit_video.dart'; class VideoWidget extends StatefulWidget { final MediaItemDetail details; const VideoWidget({super.key, required this.details}); @override State createState() => _VideoWidgetState(); } class _VideoWidgetState extends State { late final Player _player; late final VideoController _controller; double? _aspectRatio; @override void initState() { super.initState(); _player = Player(); _controller = VideoController(_player); _player.open(Media(widget.details.mediaUrl)); _player.setPlaylistMode(PlaylistMode.loop); _player.setVolume(0); //_player.stream.height.first; _player.stream.playing.listen((blah) { setState(() { Future.microtask(() async { int h = await _player.stream.height.first ?? 0; int w = await _player.stream.width.first ?? 0; _aspectRatio = h / w; print(_aspectRatio); }); }); }); } @override void dispose() { _player.dispose(); super.dispose(); } @override Widget build(BuildContext context) { //_aspectRatio = _controller.player.state.height! / _controller.player.state.width!; print(_aspectRatio); return Scaffold( appBar: AppBar( backgroundColor: const Color.fromARGB(255, 43, 43, 43), foregroundColor: const Color.fromARGB(255, 255, 255, 255), title: Text('f0ck #${widget.details.id}'), centerTitle: true, ), body: Column( children: [ if (_aspectRatio != null) AspectRatio( aspectRatio: _aspectRatio!, child: Video( controller: _controller, fit: BoxFit.cover, alignment: Alignment.topCenter, ), ) else SizedBox( width: double.infinity, height: MediaQuery.of(context).size.height * 0.75, child: Video( controller: _controller, fit: BoxFit.cover, alignment: Alignment.topCenter, ), ), const SizedBox(height: 10), Text( 'f0cked by: ${widget.details.username}', style: const TextStyle( fontSize: 16, color: Color.fromARGB(255, 255, 255, 255), ), ), ], ), ); } }