betterplayer
betterplayer copied to clipboard
[BUG] [Android] PlatformException - Unknown textureId
History check Please confirm that you've checked issues history and you didn't find anything which may solve your issue.
Describe the bug
[Android only]
After call controller.dispose()
, it shows an error below:
PlatformException(Unknown textureId, No video player associated with texture id 2, null, null)
libapp +0x1009258 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607)
libapp +0x0484c1c MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167)
To Reproduce Steps to reproduce the behavior:
- Open an activity or screen
- Error shown while doing nothing
Flutter doctor [✓] Flutter (Channel stable, 2.10.4, on macOS 12.3.1 21E258 darwin-x64, locale en-ID) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) [✓] Chrome - develop for the web [✓] Android Studio (version 4.2) [✓] VS Code (version 1.66.2) [✓] Connected device (2 available) [✓] HTTP Host Availability
Better Player version
- Version: 0.0.81
Smartphone (please complete the following information):
- Device: POCO M3
- OS: Android 11
Additional context Same issue with https://github.com/fluttercommunity/chewie/issues/148
@nandawperdana Can you provide sample code for that?
@nandawperdana Can you provide sample code for that?
So basically I set the ID for every BetterPlayerController attached to video model that will be shown and played on screen. Like this:
class VideoServiceState {
BetterPlayerController? playerController;
StreamController<BetterPlayerEvent> playerEvent;
VideoModel? videoModel;
dynamic Function(BetterPlayerEvent) eventListener;
VideoServiceState(this.playerController, this.progressController,
this.playerEvent, this.videoModel, this.eventListener);
}
class VideoService {
final Map<int, VideoServiceState> _states = {};
}
and use the _states
to control the video based on ID. Let say for playing the video:
Future<void> play(int id) async {
try {
await _states[id]?.playerController?.play();
} catch (e, s) {}
}
and, dispose the controller for specific video ID, like this:
void dispose(int id) {
try {
final controller = _states[id]?.playerController;
final isPlaying = controller?.isPlaying() ?? false;
if (isPlaying) controller?.pause();
controller?.dispose();
_states[id]?.progressController.close();
_states[id]?.playerEvent.close();
_states.remove(id);
} catch (e) {}
}
actually, the error shown even before the video played or started, is there any background processes causing error?