0

次のエラーが表示されます。

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];
}

何か助けはありますか?

4

1 に答える 1

1

オブザーバーを追加するとき:に、セレクターに がありません:moviePayBlackDidFinish:

次のようにする必要があります。

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

メソッド名の後のコロンは、メソッドがパラメータを取ることを示していることに注意してください。コードがパラメーターを取らない moviePlaybackDidFinish という名前のメソッドを探していたが、そのようなメソッドが存在しないため、エラーが発生していました。

于 2012-04-04T21:06:44.840 に答える