-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Garbage collector problem #35
Comments
I think the controller instance you created is not pointed by any variable anymore, Could you try to assign the controller instance to a static / global variable (though it is not a good idea), |
I am creating 2 instances of a class with the video controller. `class PHFPlayerVideoPlayer extends PHFPlayer{ VideoPlayerController? videoPlayerController; @OverRide @OverRide |
I hope it is related to the fact that after some iterations of this switch beetween different videos, the app crashes with no specific error log |
I write the following simple test code, Did this solve your problem? Note: Please remember to edit the import 'dart:io';
import 'package:flutter/material.dart';
import 'package:video_player_win/video_player_win.dart';
void main() {
runApp(const MyApp());
}
const gFileList = [
"E:\\test_4k.mp4",
"E:\\test_align.mp4",
"E:\\test_av1.mp4",
"E:\\test_clock.mp4",
"E:\\test_youtube.mp4",
];
class PHFPlayerVideoPlayer {
WinVideoPlayerController? controller;
Future<void> initializeVideoSlide(String path) async {
controller?.dispose();
controller = WinVideoPlayerController.file(File(path));
await controller!.initialize();
}
void play() {
controller!.play();
}
void closeVideoPlayer() {
controller?.dispose();
controller = null;
}
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var nowPlayer = PHFPlayerVideoPlayer();
var nextPlayer = PHFPlayerVideoPlayer();
int nowIndex = 0;
@override
void initState() {
super.initState();
nowIndex = 0;
nowPlayer.initializeVideoSlide(gFileList[nowIndex]).then((value) {
nowPlayer.play();
setState(() {}); // update UI
});
prepareNext();
}
void prepareNext() {
int nextIndex = (nowIndex + 1) % gFileList.length; // loop the list
nextPlayer.initializeVideoSlide(gFileList[nextIndex]);
}
void onNextButtonClicked() {
nowPlayer.closeVideoPlayer();
// swap 2 player pointer
var tmp = nextPlayer;
nextPlayer = nowPlayer;
nowPlayer = tmp;
nowIndex = (nowIndex + 1) % gFileList.length; // loop the list
nowPlayer.play();
prepareNext();
setState(() {}); // update UI
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(children: [
WinVideoPlayer(nowPlayer.controller!),
ElevatedButton(
onPressed: onNextButtonClicked, child: const Text("Next")),
]),
));
}
}
|
It is still happening, and i don't understand why |
First, Second, |
@jakky1 Here you have it import 'dart:io'; void main() { const gFileList = [ class MyApp extends StatefulWidget { @OverRide class _MyAppState extends State { @OverRide
} @OverRide
} abstract class PHFPlayer { late int libraryType; Future initializeVideoSlide(videoFile); Widget getVideoWidget(useBlur); static PHFPlayer createVideoPlayer(int libraryType, index) { } } class PHFPlayerVideoPlayer extends PHFPlayer{ VideoPlayerController? videoPlayerController; @OverRide @OverRide } |
Thanks for reporting this issue, and the sample code. It seems there is really something wrong in this package. It is confirmed that if any VideoPlayerController created but not displayed, Now it is fixed,
|
The GC issue seems now resolved But not there is another problem. [ERROR:flutter/shell/platform/windows/external_texture_d3d.cc(107)] Binding D3D surface failed. |
Because it rarely occurs, I have no way to fix this before I can duplicate this issue on my PC. |
import 'dart:async'; import 'package:flutter/material.dart'; void main() { const gFileList = [ class MyApp extends StatefulWidget { @OverRide class _MyAppState extends State { @OverRide
} switchPlayer() async{
} @OverRide
} class PHFPlayerVideoPlayer { int index = 0; initializeVideoSlide(videoFile) async{ Widget getVideoWidget(useBlur){ } |
@jakky1 do you have any update on this? |
I have run your code in debug mode (5 hours) and release mode (8 hours) |
if i initialize a video player and dont use it (i want to prepare it for later), this message occur:
[video_player_win] gc free a player that didn't dispose() yet !!!!!
And the player is no more initialized
The text was updated successfully, but these errors were encountered: