来自api的视频网址。我尝试使用视频播放器,但没有播放。.在initState()
上初始化时,它可以工作。但是我需要在Build方法上进行初始化。.
return FutureBuilder(
future: initializingPlayer(snapshot.data[index].content),
builder: (BuildContext context,AsyncSnapshot<VideoPlayerController> snapshot){
if (snapshot.connectionState == ConnectionState.done) {
return InkWell(
onTap: () {
setState(() {
snapshot.data.value.isPlaying
? snapshot.data.pause()
: snapshot.data.play();
});
},
child: snapshot.data.value.initialized
? AspectRatio(
aspectRatio: snapshot.data
.value.aspectRatio,
child: VideoPlayer(snapshot.data),
)
: Container(),
);
}else{
return Center(child: CircularProgressIndicator());
}
}
);
initializingPlayer方法
Future<VideoPlayerController> initializingPlayer(String content) async {
return VideoPlayerController.network(
content
)..initialize();
}
控制台错误
E / ExoPlayerImplInternal(3609):播放错误。 E / ExoPlayerImplInternal(3609): com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.audio.AudioSink $ InitializationException: AudioTrack初始化失败:0,Config(48000,12,48000) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:646) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1355) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:663) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:529) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:300) E / ExoPlayerImplInternal(3609):在 android.os.Handler.dispatchMessage(Handler.java:104) E / ExoPlayerImplInternal(3609):在 android.os.Looper.loop(Looper.java:166)E / ExoPlayerImplInternal( 3609):位于android.os.HandlerThread.run(HandlerThread.java:65) E / ExoPlayerImplInternal(3609):原因: com.google.android.exoplayer2.audio.AudioSink $ InitializationException: AudioTrack初始化失败:0,Config(48000,12,48000) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.DefaultAudioSink.initializeAudioTrack(DefaultAudioSink.java:1128) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.DefaultAudioSink.initialize(DefaultAudioSink.java:532) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:593) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:640) E / ExoPlayerImplInternal(3609):...还有7个W / ACodec(3609):强制 在ExecutingState中收到关机后,OMX状态为空闲 D / SurfaceUtils(3609):与表面0x7485feb010断开连接,原因 connectedFromSurface W / ACodec(3609):将OMX状态强制为空闲 在ExecutingState E / AudioTrack(3609)中收到关机信息时: AudioFlinger无法创建曲目,状态:-12 E / AudioTrack-JNI( 3609):错误-12初始化AudioTrack E / android.media.AudioTrack( 3609):初始化AudioTrack时错误代码-20。 E / ExoPlayerImplInternal(3609):播放错误。 E / ExoPlayerImplInternal(3609): com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.audio.AudioSink $ InitializationException: AudioTrack初始化失败:0,Config(48000,12,48000) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:646) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1355) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:663) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:529) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:300) E / ExoPlayerImplInternal(3609):在 android.os.Handler.dispatchMessage(Handler.java:104) E / ExoPlayerImplInternal(3609):在 android.os.Looper.loop(Looper.java:166)E / ExoPlayerImplInternal( 3609):位于android.os.HandlerThread.run(HandlerThread.java:65) E / ExoPlayerImplInternal(3609):原因: com.google.android.exoplayer2.audio.AudioSink $ InitializationException: AudioTrack初始化失败:0,Config(48000,12,48000) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.DefaultAudioSink.initializeAudioTrack(DefaultAudioSink.java:1128) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.DefaultAudioSink.initialize(DefaultAudioSink.java:532) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:593) E / ExoPlayerImplInternal(3609):在 com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:640) E / ExoPlayerImplInternal(3609):...还有7个W / ACodec(3609):强制 在ExecutingState中收到关机后,OMX状态为空闲 D / SurfaceUtils(3609):与表面0x7485fe8010断开连接,原因 connectedFromSurface W / ACodec(3609):将OMX状态强制为空闲 当在ExecutingState中收到关机信息时