Monday, 15 July 2013

ios - MPMoviePlayerController sometimes plays audio, not video when fading in -



ios - MPMoviePlayerController sometimes plays audio, not video when fading in -

i've got issue where, in uiscrollview have number of views (videocontrollers in below) deed pages video content (initially thumbnail view shown).

sometimes (but not always) when scroll next page, sound video starts playing no visual. doesn't seem happen when i'm not fading view in.

video init code is:

mpmovieplayercontroller* movieplayer = [[mpmovieplayercontroller alloc] init]; self.movieplayer = movieplayer; [movieplayer setcontrolstyle:mpmoviecontrolstylenone]; [movieplayer setrepeatmode:mpmovierepeatmodeone]; [movieplayer.view setframe:cgrectmake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; movieplayer.backgroundview.backgroundcolor = [uicolor clearcolor]; movieplayer.moviesourcetype = mpmoviesourcetypestreaming; movieplayer.contenturl = [nsurl urlwithstring:[videodata.video src]]; [self.videocontroller.view addsubview:self.movieplayer.view]; [self.videocontroller.view bringsubviewtofront:movieplayer.view]; [movieplayer.view setalpha:0.0f]; // film observer [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(checkmoviestatus:) name:mpmovieplayerloadstatedidchangenotification object:nil]; // add together tap handler uitapgesturerecognizer *singlefingertap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(onplayertapped:)]; singlefingertap.numberoftapsrequired = 1; singlefingertap.delegate = self; [self.movieplayer.view addgesturerecognizer:singlefingertap]; [movieplayer preparetoplay];

and play code (to seek avoid black flash @ start of video) is:

- (void)checkmoviestatus:(nsnotification *)notification { if(self.movieplayer.readyfordisplay && (mpmovieloadstateplayable | mpmovieloadstateplaythroughok)) { [self.movieplayer play]; [[nsnotificationcenter defaultcenter] removeobserver:self name:mpmovieplayerloadstatedidchangenotification object:nil]; [uiview animatewithduration:0.4f animations:^{ [self.movieplayer.view setalpha:1.0f]; } completion:^(bool finished) { //[self.movieplayer play]; // tried here }]; } }

code remove video view on scroll is:

- (void)removemovieplayer { if(self.movieplayer) { [self.movieplayer stop]; [self.movieplayer.view removefromsuperview]; self.movieplayer = nil; } }

i found rather unusual prepare problem. in case swipe video , sound play , there no picture. if swiped away , came back, worked fine fun of tried

mpmovieplayercontroller *mp = [self.arrayofscrollview objectatindex:xx]; [mp play]; [mp stop]; [mp play];

strangely worked. since posted 6 months ago, if found workaround, i'd love know it.

ios objective-c uiscrollview mpmovieplayercontroller

No comments:

Post a Comment