我的项目使用 ARC。我想在按下按钮时播放电影。目前我的代码会启动一个电影播放器并正确播放电影。一旦 MPMoviePlayerController 视图被关闭,它就会返回到原始视图。如果我点击原始视图上的后退按钮,它不会被释放并保留在内存中。如果我从不按按钮播放电影,则它已正确释放。
在 .h 中声明
@property (strong,nonatomic) MPMoviePlayerViewController * moviePlayerController;
在 .m 中调出电影:
-(IBAction)playMovie:(NSURL *) theURL
{
NSURL *fileURL = [[NSURL alloc] initWithString:movieTrailerURL];
self.moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[moviePlayerController.moviePlayer prepareToPlay];
//moviePlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self presentViewController:moviePlayerController animated:YES completion:nil];
}
当电影通过结束或按下完成按钮而被关闭时,这被称为
- (void)moviePlaybackComplete:(NSNotification *)notification
{
NSLog(@"I am in movie playback complete!!!");
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
// [moviePlayerController.moviePlayer pause];
// moviePlayerController.moviePlayer.initialPlaybackTime = -1;
// [moviePlayerController.moviePlayer stop];
// moviePlayerController.moviePlayer.initialPlaybackTime = -1;
//[moviePlayerController.moviePlayer.view removeFromSuperview];
// [moviePlayerController.view removeFromSuperview];
// [moviePlayerController.moviePlayer release];
}
我已经尝试了注释掉的部分的每一种组合,试图让我的 moviePlayerController 从内存中释放,以便父视图将释放和解除分配。