简体   繁体   English

Flutter vlc 播放器:应用程序在启动时崩溃

[英]Flutter vlc player : App crashes on launch

I want flutter vlc player to stream live from my raspberry pi我想要 flutter vlc 播放器到 stream 从我的树莓派直播

when I downloaded the example file from git their code works properly but when implemented the same code in my app the app straight away crashes with an当我从 git 下载示例文件时,他们的代码可以正常工作,但是当在我的应用程序中实现相同的代码时,应用程序立即崩溃并出现

error:错误:

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主.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 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>

Please help me getting the solution.请帮我解决问题。 I desperately need to complete my app for project我迫切需要为项目完成我的应用程序

Hye For me it worked when I added the following ones in my android/app/build.gradle Hye 对我来说,当我在我的 android/app/build.gradle 中添加以下内容时,它起作用了

minifyEnabled false shrinkResources false minifyEnabled false shrinkResources false

While check that you have minSdkVersion to 17同时检查您的 minSdkVersion 是否为 17

I have added a snippet for you to resolve the issue.我已经为您添加了一个片段来解决这个问题。 Now I am looking for to have less size apk after adding flutter_vlc_player plugin.现在我正在寻找添加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
    }
}

add some code in build type (minify and proguard)在构建类型中添加一些代码(缩小和保护)

 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'
    }
}

and then create file with name "proguard-rules.pro" with this content然后使用此内容创建名为“proguard-rules.pro”的文件

-keep class org.videolan.libvlc.** { *; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM