Featured post
objective c - Play Video immediately when UIView is loaded -
howdy! i'm writing ipad app, , need able play video when uiview loads. however, getting bad_exc_access if try message mpmovieplayercontroller anywhere after initialize it. removed mpmediaplayercontroller *.h file, declared entirely in implementation file, , i'm getting message @ bottom below code. there no issues in build , analyze memory leaks (or issues, matter), , cannot find posts this. here's code:
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { } nsstring *url = [[nsbundle mainbundle] pathforresource:@"p0600c0100cmpintro" oftype:@"m4v"]; mpmovieplayercontroller *movie = [[mpmovieplayercontroller alloc] initwithcontenturl:[nsurl fileurlwithpath:url]]; nslog(@"%@", movie); movie.view.frame = cgrectmake(5, 0, 1035, 768); movie.view.contentmode = uiviewcontentmodescaletofill; [[movie view] setcenter:cgpointmake(movie.view.center.x-10, movie.view.center.y)]; [movie setcontrolstyle:mpmoviecontrolstylenone]; [movie setshouldautoplay:yes]; [[self view] addsubview:[movie view]]; return self; }
the nslog of "movie" gives "mpmovieplayercontroller: 0x1b77f0", error message upon crash "* -[mpmovieplayercontroller playbackstate]: message sent deallocated instance 0x1473a0". help?
according documentation looks frame of movie view needs match view of parent. try moving code out of initwithnibname:bundle: viewdidload:
- (void)viewdidload { [super viewdidload]; uiview *moviecontainer = [[uiview alloc] initwithframe:cgrectmake(5, 0, 300, 400)]; //do other positioning of view nsstring *path = [[nsbundle mainbundle] pathforresource:@"p0600c0100cmpintro" oftype:@"m4v"]; nsurl *url = [nsurl fileurlwithpath:path]; mpmovieplayercontroller *movie = [[mpmovieplayercontroller alloc] initwithcontenturl:url]; movie.view.frame = moviecontainer.bounds; //make sure bounds of parent view movie.scalingmode = mpmoviescalingmodefill; movie.controlstyle = mpmoviecontrolstylenone; movie.shouldautoplay = yes; [moviecontainer addsubview:movie.view]; [self.view addsubview:moviecontainer]; [moviecontainer release]; }
one last suggestion keep reference of movie can dealloc once view controller gets deallocated
- Get link
- X
- Other Apps
Comments
Post a Comment