feat:更新视频播放组件

This commit is contained in:
2026-01-30 15:15:57 +08:00
parent 5287f5f7cd
commit f8d639b3d5
5 changed files with 61 additions and 102 deletions

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:omni_video_player/omni_video_player.dart';
import 'package:flutter_common/utils/showVideoPlay.dart';
class PlayVideoPage extends StatefulWidget {
@@ -13,7 +12,6 @@ class PlayVideoPage extends StatefulWidget {
}
class _PlayVideoPageState extends State<PlayVideoPage> {
OmniPlaybackController? _controller;
@override
void initState() {
// TODO: implement initState
@@ -24,42 +22,10 @@ class _PlayVideoPageState extends State<PlayVideoPage> {
void dispose() {
// TODO: implement dispose
super.dispose();
_controller?.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Container(
padding: EdgeInsets.only(bottom: 50.h,top: 150.h),
color: Colors.black,
child: OmniVideoPlayer(
configuration: VideoPlayerConfiguration(
videoSourceConfiguration: VideoSourceConfiguration.network(
videoUrl: Uri.parse(widget.videoUrl),
preferredQualities: [OmniVideoQuality.high1080],
),
), callbacks: VideoPlayerCallbacks(
onControllerCreated: (controller) {
setState(() {
controller.play();
});
},
),
),
),
Positioned(
top: 60.h,
left: 20.w,
child: IconButton(
icon: Icon(Icons.arrow_back_ios, color: Colors.white,),
onPressed: () => Navigator.of(context).pop(),
),
),
],
),
);
return ShowVideoPlayPage(url: widget.videoUrl);
}
}

View File

@@ -0,0 +1,58 @@
import 'dart:collection';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class ShowVideoPlayPage extends StatefulWidget {
final String url;
const ShowVideoPlayPage({super.key, required this.url});
@override
State<ShowVideoPlayPage> createState() => _ShowVideoPlayPageState();
}
class _ShowVideoPlayPageState extends State<ShowVideoPlayPage> {
InAppWebViewController? webViewController;
InAppWebViewSettings settings = InAppWebViewSettings(
isInspectable: kDebugMode,
mediaPlaybackRequiresUserGesture: false,
allowsInlineMediaPlayback: true,
iframeAllow: "camera; microphone",
iframeAllowFullscreen: true);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: GestureDetector(
onTap: () => Navigator.pop(context),
child: Icon(
Icons.navigate_before,
color: Colors.white,
size: 32,
),
),
backgroundColor: Colors.black,
),
body: Container(
color: Colors.black,
child:InAppWebView(
initialUrlRequest: URLRequest(url: WebUri(widget.url)),
initialUserScripts: UnmodifiableListView<UserScript>([]),
initialSettings: settings,
onWebViewCreated: (controller) async {
webViewController = controller;
},
onLoadStart: (controller, url) {
setState(() {
});
},
onConsoleMessage: (controller, consoleMessage) {
print(consoleMessage);
},
),
),
);
}
}