MPMoviePlayerController
と呼ばれる私が構築したクラス内で使用していMYVideo
ます。コードは次のとおりです。
#import <MediaPlayer/MediaPlayer.h>
#import "MYVideo.h"
@interface MYVideo()
@property (strong, nonatomic) UIView * viewRef;
@property (strong, nonatomic) NSDictionary * contentData;
@property (strong, nonatomic) MPMoviePlayerController * videoController;
@end
@implementation MYVideo
@synthesize contentData,videoController,viewRef;
- (MYVideo*) initIntoView: (UIView*) view withContent:(NSDictionary*)contentDict{
self=[super init];
viewRef=view;
contentData = contentDict;
NSString *rawUrl = [[NSString alloc] initWithFormat:@"http://....com/app/%@.mp4", [contentDict objectForKey:@"cnid"]];
NSURL *videoUrl = [[NSURL alloc]initWithString:rawUrl];
videoController = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
videoController.movieSourceType=MPMovieSourceTypeFile;
videoController.view.frame = viewRef.bounds;
[videoController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
videoController.controlStyle=MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:videoController];
[viewRef addSubview:videoController.view];
return self;
}
- (void) playbackFinished: (NSNotification*) notification {
NSLog(@"playback finished");
if(videoController){
[videoController play];
}
}
- (void) play: (int) offset {
videoController.initialPlaybackTime=offset;
[videoController play];
}
- (void) stop {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:@"playbackFinished"
object:nil];
if(videoController){
[videoController stop];
}
}
- (void) destroy {
if(videoController){
[videoController stop];
[videoController.view removeFromSuperview];
}
}
@end
私の問題は、時々次のエラーが発生することです。
playback finished
-[__NSCFString playbackFinished:]: unrecognized selector sent to instance 0x1664e6a0
MPMoviePlayerController
これは、このビデオ クラスが既にリリースされているときに「playbackFinished」通知が発生したことが原因であると推測しています。私はこれを考えるのが正しいですか?
このMYVideo
クラスは、ビデオの再生中にまだ存在している必要があります。このエラーは、ビデオの再生中にのみ発生し、コンソールログでは、「再生が終了しました」という NSLogging がクラッシュの直前に記録されます。また、最初に「playbackFinished」オブザーバーを削除せずにクラスをシャットダウンすることはありません。
なぜこのクラッシュが発生するのか、誰かが私に提案できますか?
どうもありがとう。