我正在为我的颤振应用程序使用官方颤振视频播放器包,但显示器是全黑的,我在屏幕上显示它时也遇到了这个错误:
E/flutter (10774): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: A VideoPlayerController was used after being disposed.
E/flutter (10774): Once you have called dispose() on a VideoPlayerController, it can no longer be used.
或者有时这样:
V/LGCodecAdapter( 515): LG Codec Adapter start
I/ACodec ( 515): Now uninitialized
I/ACodec ( 515): onAllocateComponent
I/OMXClient( 515): MuxOMX ctor
I/ACodec ( 515): [OMX.qcom.video.decoder.avc] Now Loaded
I/ACodec ( 515): Now uninitialized
W/MediaCodecRenderer( 515): Failed to initialize decoder: OMX.qcom.video.decoder.avc
W/MediaCodecRenderer( 515): android.media.MediaCodec$CodecException: Error 0xfffffff4
W/MediaCodecRenderer( 515): at android.media.MediaCodec.native_configure(Native Method)
W/MediaCodecRenderer( 515): at android.media.MediaCodec.configure(MediaCodec.java:1895)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.configure(SynchronousMediaCodecAdapter.java:61)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.configureCodec(MediaCodecVideoRenderer.java:620)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.initCodec(MediaCodecRenderer.java:1110)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1011)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:578)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onInputFormatChanged(MediaCodecRenderer.java:1420)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onInputFormatChanged(MediaCodecVideoRenderer.java:694)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.readToFlagsOnlyBuffer(MediaCodecRenderer.java:965)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:811)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:947)
W/MediaCodecRenderer( 515): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:477)
W/MediaCodecRenderer( 515): at android.os.Handler.dispatchMessage(Handler.java:98)
W/MediaCodecRenderer( 515): at android.os.Looper.loop(Looper.java:154)
W/MediaCodecRenderer( 515): at android.os.HandlerThread.run(HandlerThread.java:61)
E/ExoPlayerImplInternal( 515): Playback error
E/ExoPlayerImplInternal( 515): com.google.android.exoplayer2.ExoPlaybackException: MediaCodecVideoRenderer error, index=0, format=Format(1, null, null, video/avc, avc1.428028, -1, null, [1920, 1080, 28.391167], [-1, -1]), format_supported=YES
E/ExoPlayerImplInternal( 515): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:554)
E/ExoPlayerImplInternal( 515): at android.os.Handler.dispatchMessage(Handler.java:98)
E/ExoPlayerImplInternal( 515): at android.os.Looper.loop(Looper.java:154)
E/ExoPlayerImplInternal( 515): at android.os.HandlerThread.run(HandlerThread.java:61)
E/ExoPlayerImplInternal( 515): Caused by: com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.qcom.video.decoder.avc, Format(1, null, null, video/avc, avc1.428028, -1, null, [1920, 1080, 28.391167], [-1, -1])
这是播放器的代码:
late final VideoPlayerController _videoCtrl;
late final Future<void> _videoCtrlInitializationFuture;
@override
void initState() {
super.initState();
_initVideoCtrl();
}
void _initVideoCtrl() {
_videoCtrl = VideoPlayerController.file(widget.videoFile);
_videoCtrlInitializationFuture = _videoCtrl.initialize();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _videoCtrlInitializationFuture,
builder: (BuildContext context, AsyncSnapshot videoCtrlInitSnap) {
if (videoCtrlInitSnap.connectionState == ConnectionState.done) {
return AspectRatio(
aspectRatio: _videoCtrl.value.aspectRatio,
child: VideoPlayer(_videoCtrl),
);
} else {
return SizedBox.shrink();
}
},
);
}
@override
void dispose() {
_videoCtrl.dispose();
super.dispose();
}
我尝试使用setState(() {})
并将新的小部件传递UniqueKey()
给我的VideoPlayer
小部件以创建新视频,但出现错误,表明控制器在处理后无法使用,尽管是完全不同的两个小部件。