gpt4 book ai didi

iphone - MPMoviePlayerController 未播放视频

转载 作者:行者123 更新时间:2023-11-28 22:35:47 25 4
gpt4 key购买 nike

我正在使用带有 MPMoviePlayerController 的图像匹配器 sdk 在匹配后播放视频。

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
`

最佳答案

在您的代码中添加 prepareToPlay(准备播放电影播放器​​。(必需))'

[self.moviePlayer prepareToPlay];
[self.moviePlayer play];

To prepare a new movie player for playback, call the prepareToPlay method, described in MPMediaPlayback Protocol Reference.

关于iphone - MPMoviePlayerController 未播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16104223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com