如何解决Flutter vlc 播放器:应用程序在启动时崩溃
我想要 flutter vlc 播放器从我的树莓派直播
当我从 git 下载示例文件时,他们的代码工作正常,但在我的应用程序中实现相同的代码时,应用程序立即崩溃并显示
错误:
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:54105/Id2yfbjio-E=/ws
Syncing files to device SM M515F...
D/Dialog ( 6596): mIsSamsungBasicInteraction = false
D/Dialog ( 6596): mIsSamsungBasicInteraction = false,isMetaDataInActivity = false
D/PhoneWindow( 6596): forceLight changed to true from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4274 com.android.internal.policy.DecorView.updateColorViews:1547 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3252 android.view.Window.setFlags:1153 com.android.internal.policy.PhoneWindow.generateLayout:2474
I/MultiWindowDecorSupport( 6596): [INFO] isPopOver = false
I/MultiWindowDecorSupport( 6596): updateCaptionType >> DecorView@d8c1171[],isFloating: false,isApplication: false,hasWindowDecorCaption: false,hasWindowControllerCallback: false
D/MultiWindowDecorSupport( 6596): setCaptionType = 0,DecorView = DecorView@d8c1171[]
W/Gralloc3( 6596): allocator 3.x is not supported
I/ViewRootImpl@9657a73MainActivity: setView = com.android.internal.policy.DecorView@d8c1171 TM=true MM=false
E/AndroidRuntime( 6596): FATAL EXCEPTION: main
E/AndroidRuntime( 6596): Process: com.example.video,PID: 6596
E/AndroidRuntime( 6596): java.lang.AbstractMethodError: abstract method "void io.flutter.plugin.platform.PlatformView.onFlutterViewAttached(android.view.View)"
E/AndroidRuntime( 6596): at io.flutter.plugin.platform.VirtualDisplayController.onFlutterViewAttached(VirtualDisplayController.java:181)
E/AndroidRuntime( 6596): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:233)
E/AndroidRuntime( 6596): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:104)
E/AndroidRuntime( 6596): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
E/AndroidRuntime( 6596): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/AndroidRuntime( 6596): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/AndroidRuntime( 6596): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:738)
E/AndroidRuntime( 6596): at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime( 6596): at android.os.MessageQueue.next(MessageQueue.java:336)
E/AndroidRuntime( 6596): at android.os.Looper.loop(Looper.java:197)
E/AndroidRuntime( 6596): at android.app.ActivityThread.main(ActivityThread.java:8167)
E/AndroidRuntime( 6596): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6596): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
E/AndroidRuntime( 6596): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
I/Process ( 6596): Sending signal. PID: 6596 SIG: 9
Lost connection to device.
Main.dart
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new MaterialApp(home: MyAppScaffold());
}
}
class MyAppScaffold extends StatefulWidget {
@override
State<StatefulWidget> createState() => MyAppScaffoldState();
}
class MyAppScaffoldState extends State<MyAppScaffold> {
String initUrl =
"http://192.168.29.3:8080";
Uint8List image;
VlcPlayerController _videoViewController;
var _scaffoldKey = new GlobalKey<ScaffoldState>();
@override
void initState() {
_videoViewController = new VlcPlayerController(onInit: () {
_videoViewController.play();
});
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
key: _scaffoldKey,appBar: new AppBar(
title: const Text('Plugin example app'),),floatingActionButton: FloatingActionButton(
child: Icon(Icons.camera),onPressed: _createCameraImage,body: Builder(builder: (context) {
return Container(
padding: EdgeInsets.all(10),child: ListView(
shrinkWrap: true,children: <Widget>[
SizedBox(
height: 250,child: new VlcPlayer(
aspectRatio: 16 / 9,url: initUrl,isLocalMedia: false,controller: _videoViewController,// Play with vlc options
),Divider(height: 1),image == null
? Container()
: Container(child: Image.memory(image)),],);
}),);
}
@override
void dispose() {
_videoViewController.dispose();
super.dispose();
}
void _createCameraImage() async {
Uint8List file = await _videoViewController.takeSnapshot();
setState(() {
image = file;
});
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.video">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="video"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
tools:ignore="Instantiatable">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that,this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame,then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
请帮助我获得解决方案。我迫切需要完成我的项目应用
解决方法
惠 对我来说,当我在 android/app/build.gradle 中添加以下内容时它起作用了
minifyEnabled 假 收缩资源错误
虽然检查你有 minSdkVersion 到 17
我为您添加了一个片段来解决该问题。 现在我正在寻找添加 flutter_vlc_player 插件后更小的 apk。
buildTypes {
release {
// Signing with the debug keys for now,so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled false
shrinkResources false
}
}
,
在构建类型中添加一些代码(缩小和混淆)
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now,so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),'proguard-rules.pro'
}
}
然后使用此内容创建名为“proguard-rules.pro”的文件
-keep class org.videolan.libvlc.** { *; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。