好的,最后让我的应用程序有setContentURL方法。但现在它打破了我的应用程序,我非常接近结束:( 这是代码中断的地方:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// please work!!!
NSString *title = [[NSString alloc] initWithFormat:@"bla bla"];
NSURL *newURL = [NSURL URLWithString:title];
[mp setContentURL:newURL];
}
这是首次加载应用时启动的方法,并且在调用setContentURL时加载电影很好,因为这是我的应用崩溃的地方:
- (void) readyPlayer
{
mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if ([mp respondsToSelector:@selector(loadState)])
{
// Set movie player layout
//[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setControlStyle:MPMovieControlStyleNone];
[mp setFullscreen:YES];
// May help to reduce latency
[mp prepareToPlay];
// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
}
else
{
// Register to receive a notification when the movie is in memory and ready to play.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:nil];
}
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
答案 0 :(得分:1)
您通过执行[... alloc]来分配内存,但我没有看到任何自动释放或释放...这可能是应用程序崩溃的原因,因为ObjC没有垃圾收集器而您需要清理起来自己如果内存变高,您的应用将终止。