我正在使用图像匹配器 sdkMPMoviePlayerController
来在匹配后播放视频。
在NSLog
视频中是过程但不是播放。
这里 .m 文件`
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize moviePlayer;
- (void)viewDidLoad
{
[super viewDidLoad];
_cvView = [[ImageMatcher alloc] initWithAppKey:@"apikey" useDefaultCamera:TRUE];
_cvView.matcherDelegate = self;
[_cvView start];
[_cvView setEnableMedianFilter:YES];
[_cvView setImagePoolMinimumRating:0];
[_cvView setMatchMode:matcher_mode_All];
bool value = [_cvView addImage:[UIImage imageNamed:@"pic2.jpeg"] withUniqeID:[NSNumber numberWithInt:20]];
}
-(void) viewDidAppear:(BOOL)animated
{
[self presentViewController:_cvView animated:YES completion:nil];
}
-(void) imageRecognitionResult:(int)uId
{
if (uId == 20) {
[self startPlayingVideo2:nil];
NSLog(@"ID = %d",uId);
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void) startPlayingVideo1:(id)paramSender{
NSLog(@"function startPlayingVideo make");
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *urlAsString = [mainBundle pathForResource:@"test1" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlAsString];
if(self.moviePlayer != nil){
NSLog(@"if 1 make");
[self stopPlayingVideo:nil];
}
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
if(self.moviePlayer != nil){
NSLog(@"if 2 make");
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(videoHasFinishedPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
moviePlayer.view.frame = CGRectMake(0, 0, 1024, 760);
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
[self.moviePlayer play];
}else{
NSLog(@"fail");
}
}
-(void) startPlayingVideo2:(id)paramSender{
NSLog(@"function startPlayingVideo make");
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *urlAsString = [mainBundle pathForResource:@"sample_mpeg4" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlAsString];
if(self.moviePlayer != nil){
NSLog(@"if 1 make");
[self stopPlayingVideo:nil];
}
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
if(self.moviePlayer != nil){
NSLog(@"if 2 make");
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(videoHasFinishedPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
moviePlayer.view.frame = CGRectMake(0, 0, 1024, 760);
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
[self.moviePlayer play];
}else{
NSLog(@"fail");
}
}
-(void) stopPlayingVideo:(id)paramSender{
if (self.moviePlayer != nil) {
NSLog(@"stopPlayingVideo on");
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
[self.moviePlayer stop];
if([self.moviePlayer.view.superview isEqual:self.view]){
[self.moviePlayer.view removeFromSuperview];
}
}
}
-(void) videoHasFinishedPlaying:(NSNotification *)paramNotification{
NSNumber *reason = [paramNotification.userInfo valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
if (reason != nil) {
NSInteger reasonAsInteger = [reason integerValue];
switch (reasonAsInteger){
case MPMovieFinishReasonPlaybackEnded:{
NSLog(@"MPMovieFinishReasonPlaybackEnded");
break;
}
case MPMovieFinishReasonPlaybackError:{
NSLog(@"MPMovieFinishReasonPlaybackError");
break;
}
case MPMovieFinishReasonUserExited:{
NSLog(@"MPMovieFinishReasonUserExited");
break;
}
}
NSLog(@"finish reason = %ld", (long)reasonAsInteger);
[self stopPlayingVideo:nil];
}
}
@end
`