Flutter video player 0.10.9+2无法在真实Android项目中初始化
Flutter video player 0.10.9+2 cannot be initialized in real Android project
按照video_player V0.10.9, I got very strange situation, for the same video url的最新说明,它在一个全新的flutter项目上工作,只是为了演示,但在我的真实项目中不起作用,我的意思是我在我的真实项目中遇到了初始化问题Android 项目。我已经仔细检查了两个项目的配置,都是一样的。
两个项目都适用于 iPhone,演示项目适用于 Android phone,但实际项目不适用于相同的 Android ] phone.
我对两个 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 两次,一次针对通道 flutter.io/videoPlayer
上的方法名称 init
,另一次针对方法频道 flutter.io/videoPlayer
上的姓名 create
。此异常在文件 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 环境运行稳定且健康。
[✓] 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.
中删除 flutter_facebook_login: ^3.0.0
解决
降级到 flutter 版本 1.20.4,video_player 插件将正常工作。它的新 flutter 版本会导致 video_player 插件
出现问题
更新:
当前 flutter sdk 稳定版本 & video_player 插件最新版本工作正常
按照video_player V0.10.9, I got very strange situation, for the same video url的最新说明,它在一个全新的flutter项目上工作,只是为了演示,但在我的真实项目中不起作用,我的意思是我在我的真实项目中遇到了初始化问题Android 项目。我已经仔细检查了两个项目的配置,都是一样的。
两个项目都适用于 iPhone,演示项目适用于 Android phone,但实际项目不适用于相同的 Android ] phone.
我对两个 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 两次,一次针对通道 flutter.io/videoPlayer
上的方法名称 init
,另一次针对方法频道 flutter.io/videoPlayer
上的姓名 create
。此异常在文件 platform_channel.dart
.
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 环境运行稳定且健康。
[✓] 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.
中删除flutter_facebook_login: ^3.0.0
解决
降级到 flutter 版本 1.20.4,video_player 插件将正常工作。它的新 flutter 版本会导致 video_player 插件
出现问题更新: 当前 flutter sdk 稳定版本 & video_player 插件最新版本工作正常