iOS流媒体视频错误

时间:2012-04-04 20:56:59

标签: ios video streaming

我收到以下错误:

2012-04-04 23:46:18.374 istiqlaltv[17121:e903] -[istiqlaltvViewController moviePlayBackDidFinish]: unrecognized selector sent to instance 0x6136ee0
2012-04-04 23:46:18.380 istiqlaltv[17121:e903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[istiqlaltvViewController moviePlayBackDidFinish]: unrecognized selector sent to instance 0x6136ee0'

这是代码,我在iOS中很新,我只想在按下播放按钮时播放流媒体视频。

-(void)playVideo{
NSURL *url = [[NSURL alloc] initFileURLWithPath:@"http://blabla.com/playlist.m3u8"];

NSString *strVersion = [[UIDevice currentDevice] systemVersion];
float version = [strVersion floatValue];

if(version < 4.0){
    MPMoviePlayerController *themovie = [[MPMoviePlayerController alloc] initWithContentURL:url];
    themovie.scalingMode = MPMovieScalingModeAspectFill;
    [themovie play];
}else{
    MPMoviePlayerViewController *themovie = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:themovie.moviePlayer];
    [self presentMoviePlayerViewControllerAnimated:themovie];
}
}

-(void) moviePlayBackDidFinish:(NSNotification *)notification{
    MPMoviePlayerController *player = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
    [player stop];
    [self dismissMoviePlayerViewControllerAnimated];
}

任何帮助?

1 个答案:

答案 0 :(得分:1)

添加观察者时,您遗漏了:选择器中的moviePayBlackDidFinish:

应该是:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:themovie.moviePlayer];

请注意,方法名称后面的冒号表示该方法采用参数。您收到错误是因为您的代码正在查找名为moviePlaybackDidFinish的方法,该方法不接受参数,但不存在此类方法。