ios - How do I correctly use AVPlayer so it doesn't show white screen before playing video? -
every time, when try playing megabyte video using avplayer
, shows white screen second , starts video.
why happening if video cached? there way stop happening, goes straight video without displaying white screen?
i tried using avplayer
's isready
check status of avplayer
, play video when it's ready, still displays white screen.
also every time when try video duration of video that's play through avplayer
keep getting 0.0 seconds initially, not able add timer video either because can't video duration because keeps displaying white screen second.
firstly, avplayer
doesn't show white screen, background white. so, avplayer
starting late. guess press uibutton
, loads file in avplayer
, start playing it. thats problem is. may take time avplayer
buffer enough data , ready play file. using kvo, possible notified changes of player status.
so first need disable play button, load avplayer
, add observer:
play.enabled = no; player = [avplayer playerwithurl:url]; [player addobserver:self forkeypath:@"status" options:0 context:nil];
then enable after checking avplayerstatusreadytoplay
:
- (void)observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)context { if (object == player && [keypath isequaltostring:@"status"]) { if (player.status == avplayerstatusreadytoplay) { play.enabled = yes; } } }
Comments
Post a Comment