vapplugin 0.0.1
vapplugin: ^0.0.1 copied to clipboard
Vap animation player plugin
example/lib/main.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:vapplugin/queue_util.dart';
import 'package:vapplugin/vapplugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
decoration: const BoxDecoration(
color: Color.fromARGB(255, 140, 41, 43),
image: DecorationImage(image: AssetImage("static/bg.jpeg")),
),
child: Stack(
alignment: Alignment.bottomCenter,
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// CupertinoButton(
// color: Colors.purple,
// child: Text(
// "download video source${isDownload ? "(✅)" : ""}"),
// onPressed: _download,
// ),
// CupertinoButton(
// color: Colors.purple,
// child: Text("File1 play"),
// onPressed: () => _playFile(downloadPathList[0]),
// ),
// CupertinoButton(
// color: Colors.purple,
// child: Text("File2 play"),
// onPressed: () => _playFile(downloadPathList[1]),
// ),
CupertinoButton(
color: Colors.purple,
child: const Text("asset play"),
onPressed: () => _playAsset("static/video1.mp4"),
),
CupertinoButton(
color: Colors.purple,
child: const Text("stop play"),
onPressed: () => Vapplugin.stop(),
),
// CupertinoButton(
// color: Colors.purple,
// child: Text("queue play"),
// onPressed: _queuePlay,
// ),
// CupertinoButton(
// color: Colors.purple,
// onPressed: _cancelQueuePlay,
// child: const Text("cancel queue play"),
// ),
],
),
const IgnorePointer(
// VapView可以通过外层包Container(),设置宽高来限制弹出视频的宽高
// VapView can set the width and height through the outer package Container() to limit the width and height of the pop-up video
child: VapView(),
),
],
),
),
),
);
}
Future<Map<dynamic, dynamic>?> _playFile(String path) async {
if (path == null) {
return null;
}
var res = await Vapplugin.playPath(path);
if (res!["status"] == "failure") {
if (kDebugMode) {
print(res["errorMsg"]);
}
}
return res;
}
Future<Map<dynamic, dynamic>?> _playAsset(String asset) async {
if (asset == null) {
return null;
}
var res = await Vapplugin.playAsset(asset);
if (res!["status"] == "failure") {
if (kDebugMode) {
print(res["errorMsg"]);
}
}
return res;
}
//
// _queuePlay() async {
// // 模拟多个地方同时调用播放,使得队列执行播放。
// // Simultaneously call playback in multiple places, making the queue perform playback.
// QueueUtil.get("vapQueue")
// ?.addTask(() => FlutterVap.playPath(downloadPathList[0]));
// QueueUtil.get("vapQueue")
// ?.addTask(() => FlutterVap.playPath(downloadPathList[1]));
// }
_cancelQueuePlay() {
QueueUtil.get("vapQueue")?.cancelTask();
}
}