vdocipher_flutter 2.2.4 vdocipher_flutter: ^2.2.4 copied to clipboard
A VdoCipher plugin for flutter apps. This Plugin will help to serve content on supported platform app with Hollywood grade security to prevent video piracy.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:vdocipher_flutter/vdocipher_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.blue.shade700, // status bar color
));
return MaterialApp(
debugShowCheckedModeBanner: false,
home: const MyHome(),
navigatorObservers: [
VdoPlayerController.navigatorObserver('/player/(.*)')
],
theme: ThemeData(
primaryColor: Colors.blue,
textTheme: const TextTheme(bodyText1: TextStyle(fontSize: 14.0))),
);
}
}
class MyHome extends StatefulWidget {
const MyHome({Key? key}) : super(key: key);
@override
MyHomeState createState() => MyHomeState();
}
class MyHomeState extends State<MyHome> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('VdoCipher Example'),
centerTitle: true,
),
body: const VdoPlaybackView(
controls: true,
));
}
}
const EmbedInfo sample_1 = EmbedInfo.streaming(
otp: '20160313versASE323gks3zap5vOsyQXbEf6IgQ5j3jEFtAOn3uWQaCpLXKgnRif',
playbackInfo:
'eyJ2aWRlb0lkIjoiMjY0ZDUxMWM1NDJhNGQyM2IwY2M3MzE3ODY3YWM0ODMifQ==');
class VdoPlaybackView extends StatefulWidget {
final bool controls;
const VdoPlaybackView({Key? key, this.controls = true}) : super(key: key);
@override
VdoPlaybackViewState createState() => VdoPlaybackViewState();
}
class VdoPlaybackViewState extends State<VdoPlaybackView> {
VdoPlayerController? _controller;
final double aspectRatio = 16 / 9;
final ValueNotifier<bool> _isFullScreen = ValueNotifier(false);
@override
Widget build(BuildContext context) {
String? mediaId = ModalRoute.of(context)?.settings.arguments as String?;
EmbedInfo embedInfo = sample_1;
if (mediaId != null && mediaId.isNotEmpty) {
embedInfo = EmbedInfo.offline(mediaId: mediaId);
}
return Scaffold(
body: SafeArea(
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Flexible(
child: Stack(
alignment: Alignment.center,
children: [
SizedBox(
width: MediaQuery.of(context).size.width,
height: _isFullScreen.value
? MediaQuery.of(context).size.height
: _getHeightForWidth(MediaQuery.of(context).size.width),
child: VdoPlayer(
embedInfo: embedInfo,
aspectRatio: aspectRatio,
onError: _onVdoError,
onFullscreenChange: _onFullscreenChange,
onPlayerCreated: _onPlayerCreated,
controls: widget.controls,
onPictureInPictureModeChanged: _onPictureInPictureModeChanged,
),
)
],
)),
]),
));
}
_onVdoError(VdoError vdoError) {
if (kDebugMode) {
print("Oops, the system encountered a problem: ${vdoError.message}");
}
}
_onPlayerCreated(VdoPlayerController? controller) {
setState(() {
_controller = controller;
_onEventChange(_controller);
});
}
_onPictureInPictureModeChanged(bool isInPictureInPictureMode) {}
_onEventChange(VdoPlayerController? controller) {}
_onFullscreenChange(isFullscreen) {
setState(() {
_isFullScreen.value = isFullscreen;
});
}
double _getHeightForWidth(double width) {
return width / aspectRatio;
}
}