Skip to content

Commit

Permalink
video_player dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisovAV committed May 13, 2024
1 parent c73327e commit fb689fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
43 changes: 32 additions & 11 deletions lib/ui/widgets/video_player.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:custom_native_video_player_ios/native_video_player.dart';
import 'package:flutter/material.dart';
import 'package:flutter_tv/ui/widgets/platform.dart';
import 'package:video_player/video_player.dart';

class PlayerPage extends StatefulWidget {
const PlayerPage({Key? key, required this.path}) : super(key: key);
Expand All @@ -12,28 +12,49 @@ class PlayerPage extends StatefulWidget {
}

class _PlayerPageState extends State<PlayerPage> {
NativeVideoPlayerView? player;
late VideoPlayerController _controller;

@override
void initState() {
super.initState();
print(widget.path);
_controller = VideoPlayerController.asset(
widget.path,
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
);

_controller.addListener(() {
setState(() {});
});
_controller.setLooping(true);
_controller.initialize().then((_) => setState(() {}));
_controller.play();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: SizedBox(
height: MyPlatform.isTv || MediaQuery.of(context).orientation == Orientation.landscape
? double.infinity
: MediaQuery.of(context).size.height / 3,
child: NativeVideoPlayerView(
onViewReady: (controller) async {
final videoSource = await VideoSource.init(
type: VideoSourceType.asset,
path: widget.path,
);
await controller.loadVideoSource(videoSource);
await controller.play();
},
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
VideoPlayer(_controller),
VideoProgressIndicator(_controller, allowScrubbing: true),
],
),
),
),
);
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}
}
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation

import video_player_avfoundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
}

0 comments on commit fb689fd

Please sign in to comment.