开发者

video clip no longer plays (autorelease issue)

I took care of a memory leak related to the alloc object, however I think I have fouled up my code as now my video clip does not play. I believe that I have caused the device to release before the clip starts. Could someone help me to rearrange my code? I would be greatly appreciative of a few hints to get playback working again. Here is a sample of what I am working with.

@implementation ELECTRIC_GROOVEYViewController

-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"1960" ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController =
[[[MPMoviePlayerController alloc] initWithContentURL:fileURL]autorelease];     
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.scalingMode = MPMovieScalingModeAspectFill;

[[NSNotificationCenter  defaultCenter] removeObserver:self
                                                 name:MPMoviePlayerLoadStateDidChangeNotification 
                                               object:nil];
// no moviecontrolls
moviePla开发者_开发知识库yerController.controlStyle = MPMovieControlStyleNone;
// looping forever
moviePlayerController.repeatMode= MPMovieRepeatModeOne;


[moviePlayerController play];

}


You are autoreleaseing the moviePlayerController object. It has no further retention. Hence the object must be getting deallocated. Maintain a reference to it by creating an instance variable and release it after you are done with it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜