iphone - Release MPMoviePlayer when using a tabbarcontroller -


i'm using tabbarcontroller in 1 of views has mpmovieplayer. works fine, except if change tab, movie doesn't stop , keeps playing in background. if try tab movie tab, crashes.

i think code have release mpmovieplayer when it's finished playing, want released when change views instead. if go movie tab, start fresh.

in .h file have set as:


import < uikit/uikit.h>  import < mediaplayer/mediaplayer.h>   @interface secondviewcontroller : uiviewcontroller {     mpmovieplayercontroller *player; }  @end   

and in .m file have:


- (void)viewdidload {   nsstring *url = [[nsbundle mainbundle]  pathforresource:@"vid"  oftype:@"m4v"];   player = [[mpmovieplayercontroller alloc]  initwithcontenturl:[nsurl fileurlwithpath:url]];   [[nsnotificationcenter defaultcenter]   addobserver:self  selector:@selector(moviefinishedcallback:)  name:mpmovieplayerplaybackdidfinishnotification  object:player];   //--called when movie view , add view window--  player.view.frame = cgrectmake(10, 10, 300, 300);  [self.view addsubview:player.view];      //--play movie--     [player pause];      [super viewdidload]; }  //--called when movie done playing-- - (void) moviefinishedcallback:(nsnotification*) anotification {     mpmovieplayercontroller *movieplayer = [anotification object];     [[nsnotificationcenter defaultcenter]      removeobserver:self      name:mpmovieplayerplaybackdidfinishnotification      object:movieplayer];     [movieplayer.view removefromsuperview];     [player release]; } 

any suggestions? thank :)

if want release mpmovieplayer @ tab switch, in viewwilldisappear or viewdiddisappear. it's left alive @ background, described. when come tab, try create again.

difficult exact reason crash, there seems several possibilities. next time write "why did crash" question call stack.

maybe think pause/resume, wouldn't need reallocate new movieplayer every time user changes tabs? alloc/release in viewdidload , viewdidunload, play/pause in viewwillappear , viewwilldisappear.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -