I want my video to be loaded just like instagram or youtube loads i.e part by part(stream video) but my code is first loading the whole video then it plays it. Can you help me? Code:-
VisibilityDetector(
key: Key(url),
onVisibilityChanged: (VisibilityInfo info) {
debugPrint("${info.visibleFraction} of my widget is visible");
if(info.visibleFraction <0.55){
_videoPlayerController.pause();
}
else{
_videoPlayerController.play();
if(!views.contains(currentUser.id))
{
controlViews();
}
}
},
child: ValueListenableBuilder(
valueListenable: _videoPlayerController,
builder: (context,value,child){
return _videoPlayerController.value.initialized?Stack(
children: <Widget>[
GestureDetector(
onDoubleTap: (){controlAudio();},
onTap: (){controlVideoPauseAndPlay();},
child: Container(
color: _darkTheme?Colors.black54:Colors.grey[200],
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height/2
),
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: _videoPlayerController.value.aspectRatio,
child: CachedVideoPlayer(_videoPlayerController,)
),
),
),
Container(padding: EdgeInsets.only(left: 6,top: 6),child: Text((value.duration.inSeconds-value.position.inSeconds).toString()+"s",style: TextStyle(fontSize: 16.5),)),
],
):Center(child: CircularProgressIndicator(),);
},
),
),
And I have initialized the cachedvideoplayer in initState as:-
_videoPlayerController = CachedVideoPlayerController.network(url)..setLooping(true)..initialize().then((_) {
setState(() { });
});