-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
On iOS, leaving a video play long enough causes the app to crash because it runs out of memory.
This wasn't happening with Flutter 1.12-stable. I think this is related to Flutter starting to use Metal.
The following code will cause the crash:
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: VideoHomePage()
);
}
}
class VideoHomePage extends StatefulWidget {
@override
_VideoHomePageState createState() => _VideoHomePageState();
}
class _VideoHomePageState extends State<VideoHomePage> {
VideoPlayerController _videoPlayerController;
@override
void initState() {
super.initState();
// use any video you have
_videoPlayerController = VideoPlayerController.asset("videos/video.mp4");
_videoPlayerController.setLooping(true);
_videoPlayerController.play();
_videoPlayerController.initialize();
}
@override
void dispose() {
_videoPlayerController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
elevation: 0,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Container(
// these are the dimensions of my video
width: 818.0,
height: 864.0,
child: VideoPlayer(_videoPlayerController)
),
),
);
}
}
Running this in Debug on an iPhone 6 or iPad Mini 3 will see it run out of memory and crash in less than 1 minute. Using a BoxFit.cover instead will make it crash in just a couple of seconds.
If running it from XCode, XCode's output shows this:
Message from debugger: Terminated due to memory issue
Using an AspectRatio widget also causes a crash, after it ran for 5 minutes.
This is happening on 1.18.0-dev.3.0-dev or later.
My flutter doctor:
985aeb8ceee6:all danny.valente$ flutter doctor --verbose
[✓] Flutter (Channel dev, v1.18.0, on Mac OS X 10.14.6 18G4032, locale en-US)
• Flutter version 1.18.0 at /Users/danny.valente/Library/flutter/1.18.0-dev.3.0-dev
• Framework revision de1e572 (3 weeks ago), 2020-04-06 16:15:07 -0700
• Engine revision df257e5
• Dart version 2.8.0 (build 2.8.0-dev.20.0 1210d27678)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/danny.valente/Library/Android/sdk
• 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 11C505
! CocoaPods 1.7.5 out of date (1.8.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade:
sudo gem install cocoapods
[✓] 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)