我有5-6个视频,并在滑块设置它们。在从一个视频导航到另一个视频的过程中,一切工作正常,但有时dart会产生以下错误,然后视频不会播放。我正在使用video_player标准播放器来运行视频。我在visual studio代码编辑器的调试控制台中遇到以下错误。
I/ExoPlayerImpl(30180): Release 80d07 [ExoPlayerLib/2.9.6] [mido, Redmi Note 4, Xiaomi, 24] [goog.exo.core]
I/ExoPlayerImpl(30180): Init d652959 [ExoPlayerLib/2.9.6] [mido, Redmi Note 4, Xiaomi, 24]
I/OMXClient(30180): MuxOMX ctor
I/MediaCodec(30180): [OMX.qcom.video.decoder.avc] setting surface generation to 30904353
I/ExtendedACodec(30180): setupVideoDecoder()
I/ExtendedACodec(30180): vpp-enable search is 0 and value is 0
I/ExtendedACodec(30180): Decoder will be in frame by frame mode
D/SurfaceUtils(30180): set up nativeWindow 0x7f5dbedc10 for 640x362, color 0x7fa30c06, rotation 0, usage 0x2002900
I/OMXClient(30180): MuxOMX ctor
I/ACodec (30180): codec does not support config priority (err -2147483648)
I/ACodec (30180): codec does not support config priority (err -2147483648)
D/SurfaceUtils(30180): set up nativeWindow 0x7f5dbedc10 for 640x368, color 0x7fa30c06, rotation 0, usage 0x2002900
E/AudioTrack(30180): AudioFlinger could not create track, status: -12
E/AudioTrack-JNI(30180): Error -12 initializing AudioTrack
E/android.media.AudioTrack(30180): Error code -20 when initializing AudioTrack.
E/ExoPlayerImplInternal(30180): Playback error.
E/ExoPlayerImplInternal(30180): com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.audio.AudioSink$InitializationException: AudioTrack init failed: 0, Config(44100, 12, 56576)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:646)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1355)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:663)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:529)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:300)
E/ExoPlayerImplInternal(30180): at android.os.Handler.dispatchMessage(Handler.java:98)
E/ExoPlayerImplInternal(30180): at android.os.Looper.loop(Looper.java:165)
E/ExoPlayerImplInternal(30180): at android.os.HandlerThread.run(HandlerThread.java:61)
E/ExoPlayerImplInternal(30180): Caused by: com.google.android.exoplayer2.audio.AudioSink$InitializationException: AudioTrack init failed: 0, Config(44100, 12, 56576)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.audio.DefaultAudioSink.initializeAudioTrack(DefaultAudioSink.java:1128)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.audio.DefaultAudioSink.initialize(DefaultAudioSink.java:532)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:593)
E/ExoPlayerImplInternal(30180): at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:640)
E/ExoPlayerImplInternal(30180): ... 7 more
I/ExoPlayerImpl(30180): Release d652959 [ExoPlayerLib/2.9.6] [mido, Redmi Note 4, Xiaomi, 24] [goog.exo.core]
我已经花了10多个小时来解决这个简单的问题,但还没有成功。
请建议我什么是问题,以及我们如何解决它。非常感谢。
发布于 2020-11-23 20:03:09
我已经解决了这个问题。当您调用dispose时,VideoPlayer小部件仍在使用您的控制器。首先,您需要确保不再使用它(将state中的controller设置为null),然后调用dispose。
我不确定如何通过Provider进行状态管理,但我会给你一个使用regular State进行管理的示例。
VideoPlayerController _controller;
void _initController(String link) {
_controller = VideoPlayerController.network(link)
..initialize().then((_) {
setState(() {});
});
}
Future<void> _onControllerChange(String link) async {
if (_controller == null) {
// If there was no controller, just create a new one
_initController(link);
} else {
// If there was a controller, we need to dispose of the old one first
final oldController = _controller;
// Registering a callback for the end of next frame
// to dispose of an old controller
// (which won't be used anymore after calling setState)
WidgetsBinding.instance.addPostFrameCallback((_) async {
await oldController.dispose();
// Initing new controller
_initController(link);
});
// Making sure that controller is not used by setting it to null
setState(() {
_controller = null;
});
}
}
这个解决方案对我很有效。谢谢。
https://stackoverflow.com/questions/64729350
复制相似问题