import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_vr/tools/YSTools.dart'; import 'package:flutter_vr/video/view/YSVideoProgressView.dart'; import 'package:flutter_vr/video/view/YSVideoView.dart'; import 'package:video_player/video_player.dart'; import '../tools/connectManager.dart'; class YSVideoDetail extends StatefulWidget { final Map video; const YSVideoDetail({Key? key, required this.video}) : super(key: key); @override YSVideoDetailState createState() => YSVideoDetailState(); } class YSVideoDetailState extends State { VideoPlayerController? _playerController; late ConnectManager _connectManager; @override void initState() { AppUtil.H(); _listenBlueTools(); Future.delayed(const Duration(seconds: 0)).then((value) { _getPlayer(); }); super.initState(); } _listenBlueTools() { _connectManager = ConnectManager(GattCallback( //1.实例化连接管理类,并监听连接状态 onDeviceNotFind: () { //没找到设备 LogUtil.d('onDeviceNotFind>>>>'); }, onConnected: () { //连接成功回调 LogUtil.d('onConnected>>>>'); }, onDisconnect: () { //连接关闭回调 LogUtil.d('onDisconnect>>>>'); }, onRead: (MessageData data) { //设备发过来的数据 LogUtil.d('onRead>>>>$data'); } )); if(!_connectManager.isConnecting){ _connectManager.start("Xiaomi Smart Band 8 Pro 0154"); //2.开始连接蓝牙设备,T11302002020169为蓝牙设备名称 } } @override void dispose() { AppUtil.V(); _playerController?.dispose(); super.dispose(); } _getPlayer() async{ _playerController = VideoPlayerController.file(File(widget.video['path']))..initialize().then((_) { _playerController?.setLooping(true); _playerController?.play(); setState(() {}); }); setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.black, body: Stack( children: [ if(_playerController!=null)Container( padding: const EdgeInsets.all(50), child: Row( children: [ Expanded(child: YSVideoView(player: _playerController!,)), const SizedBox(width: 50,), Expanded(child: YSVideoView(player: _playerController!,)), ], ), ), Container( padding: EdgeInsets.only(top: ysTOP(context)+5), child: GestureDetector( onTap: (){ Navigator.pop(context); }, behavior: HitTestBehavior.opaque, child: Row( children: [ const Icon(Icons.chevron_left,size: 40,color: Colors.white,), Expanded(child: Text(widget.video['name'],style: const TextStyle(fontSize: 15,color: Colors.white),maxLines: 1,)) ], ), ), ), if(_playerController!=null)YSVideoProgressView(playerController: _playerController!) ], ), ); } }