按照video_player V0.10.9的最新说明,我遇到了非常奇怪的情况,对于same video url,它在一个仅用于演示的全新flutter项目上工作,但在我的实际项目中不起作用,我是说我已经初始化在我的真实Android项目中出现的问题。而且我已经仔细检查了两个项目的配置,都相同。
两个项目都可以在iPhone上运行,演示项目可以在Android手机上运行,但是实际项目不能在同一台Android手机上运行。
我对两个pubspec.yaml文件都放置了以下引用:
video_player: ">=0.10.9+2 <2.0.0"
在我的演示项目中,它可以正常工作:
class _MyHomePageState extends State<MyHomePage> {
final videoUrl =
'https://captnotes.com/wp-content/uploads/2020/02/demo_video_02.mp4';
VideoPlayerController videoPlayerController;
@override
void initState() {
super.initState();
print('^_^initState()');
videoPlayerController = VideoPlayerController.network(videoUrl)
..initialize().then((_) {
setState(() {
videoPlayerController.play();
print('^_^play()');
});
})
..addListener(() {
print('Is playing: ${videoPlayerController.value.isPlaying}');
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: videoPlayerController.value.initialized
? AspectRatio(
aspectRatio: videoPlayerController.value.aspectRatio,
child: VideoPlayer(videoPlayerController))
: Container(),
),
);
}
}
但是在我的真实项目中,initialize()将始终使MissingPluginException两次,一次在通道init
上表示方法名称flutter.io/videoPlayer
,一次在通道create
上表示方法名称flutter.io/videoPlayer
。在文件platform_channel.dart
的第319行引发此异常。
void initVideoPlayer() {
if (TextUtil.isEmpty(videoUrl)) {
logger.debug('videoUrl is EMPTY.');
return;
}
logger.debug('videoUrl: $videoUrl');
videoPlayerController?.dispose();
videoPlayerController = VideoPlayerController.network(videoUrl)
..initialize()
..addListener(() {
// logger.debug(
// 'isVideoPlaying: $isVideoPlaying, videoPlayerController.value.isPlaying: ${videoPlayerController.value.isPlaying}');
if (isVideoPreparing && videoPlayerController.value.isPlaying) {
isVideoPreparing = false;
isVideoPlaying = true;
} else if (isVideoPlaying && !videoPlayerController.value.isPlaying) {
videoPlayerController.seekTo(Duration(milliseconds: 0));
isVideoPlaying = false;
stopVideo();
setState(() {});
}
});
}
我仔细检查过,两个项目的配置都相同,包括iOS和Android设置,绝对遵循官方说明中的每个步骤。
我什至以为multidex可以起到这种作用,但是在我将其设置为支持multidex之后,演示项目仍然可以正常工作。
任何帮助将不胜感激!
顺便说一句,我的拍打环境稳定且健康。
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.14.6 18G103, locale en-CN)
• Flutter version 1.12.13+hotfix.9 at /Volumes/Transcend/Development/flutter
• Framework revision f139b11009 (5 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Volumes/Transcend/Development/AndroidSDK
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.9.0
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.44.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.1
[✓] Connected device (1 available)
• SM G9500 • 988a1b474239545746 • android-arm64 • Android 9 (API 28)
• No issues found!
已通过从pubspec.yaml