ios - Playing MPMoviePlayerController in UITableViewCell causes app to freeze and crash -
in app working with, adding mpmoveplayercontroller
uitableviewcell
, auto playing it. problem is, calling preparetoplay
and/or play
causes app freeze, cpu maxes out, ram continuously increases, , app of course crash after little while. if comment out preparetoplay
, play
not occur, see black box no playback controls.
we create mpmovieplayercontroller
in cellforrowatindexpath
, store array, may have multiple videos in table, , need able play right video upon tapping 1 or stop 1 on demand. when table loaded first time, videos load , play without issue. users can add video via modal view controller presentation, reload table after adding video data source. problem arrises after users add new video.
i tried storing property player in cell itself, did not resolve issue. i've tried calling stop
before setting contenturl
suggested elsewhere, didn't help. tried 4 different videos each different format, in case corrupt video. i'm not sure problem is.
//table view controller: @interface { nsmutablearray *arrayofmovieplayers; } viewdidload { arrayofmovieplayers = [nsmutablearray new]; } cellforrowatindexpath { mytableviewcell* cell = [tableview dequeuereusablecellwithidentifier:@"cell"]; mpmovieplayercontroller *movieplayer = [[mpmovieplayercontroller alloc]init]; [arrayofmovieplayers addobject:movieplayer]; cell = [[mytableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell" withdictionary:dict withmovieplayer:movieplayer]; return cell; } //cell subclass: -(instancetype)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier withdictionary:(nsdictionary*)dict withmovieplayer:(mpmovieplayer *)movieplayer { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { movieplayer.view.frame = self.contentview.bounds; [self.contentview addsubview:movieplayer.view]; dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_high, 0ul); dispatch_async(queue, ^{ nsstring* fileurl = dict[@"video"][@"url"]; //may remote or local dispatch_async(dispatch_get_main_queue(), ^{ [movieplayer stop]; [movieplayer setcontenturl:[nsurl fileurlwithpath:fileurl]]; //next lines cause high cpu, ram, eventual crash [movieplayer preparetoplay]; [movieplayer play]; }); }); } return self; }
some details of crash:
crashed thread: 0 dispatch queue: com.apple.main-thread exception type: exc_bad_access (sigsegv) exception codes: kern_protection_failure @ 0x00007fff5291bd80
the issue due invalid url video file. while url existed, not correct.
Comments
Post a Comment