视频剪辑不再播放(自动释放问题)
我处理了与 alloc 对象相关的内存泄漏,但是我认为我已经弄乱了我的代码,因为现在我的视频剪辑无法播放。我相信我已在剪辑开始之前释放了设备。有人可以帮我重新排列我的代码吗?我将非常感谢一些让播放再次正常工作的提示。这是我正在使用的示例。
@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
moviePlayerController.controlStyle = MPMovieControlStyleNone;
// looping forever
moviePlayerController.repeatMode= MPMovieRepeatModeOne;
[moviePlayerController play];
}
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
moviePlayerController.controlStyle = MPMovieControlStyleNone;
// looping forever
moviePlayerController.repeatMode= MPMovieRepeatModeOne;
[moviePlayerController play];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在
autorelease
moviePlayerController
对象。它没有进一步的保留。因此,该对象必须被释放。通过创建实例变量来维护对它的引用,并在使用完毕后释放它。You are
autorelease
ing themoviePlayerController
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.