我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”观察者的情况下关闭课程。
任何人都可以向我建议为什么我会遇到这种崩溃?
非常感谢。