first commit
This commit is contained in:
51
lib/widgets/video_widget.dart
Normal file
51
lib/widgets/video_widget.dart
Normal file
@ -0,0 +1,51 @@
|
||||
import 'package:f0ckapp/models/mediaitem_detail.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
class VideoWidget extends StatefulWidget {
|
||||
final MediaItemDetail details;
|
||||
//const VideoWidget({super.key, required this.details}): super(key: key);
|
||||
const VideoWidget({Key? key, required this.details}) : super(key: key);
|
||||
|
||||
@override
|
||||
_VideoWidgetState createState() => _VideoWidgetState();
|
||||
}
|
||||
|
||||
class _VideoWidgetState extends State<VideoWidget> {
|
||||
late VideoPlayerController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_controller = VideoPlayerController.networkUrl(
|
||||
Uri.parse(widget.details.mediaUrl)
|
||||
)..initialize().then((_) {
|
||||
setState(() {});
|
||||
});
|
||||
_controller.play();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: Center(
|
||||
child: _controller.value.isInitialized
|
||||
? AspectRatio(
|
||||
aspectRatio: _controller.value.aspectRatio,
|
||||
child: VideoPlayer(_controller),
|
||||
)
|
||||
: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
92
lib/widgets/video_widget.dart.old
Normal file
92
lib/widgets/video_widget.dart.old
Normal file
@ -0,0 +1,92 @@
|
||||
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<VideoWidget> {
|
||||
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),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user