我想创建一个快速的图片/电影查看器 - 用于庆祝生日。 首先,我想展示一些图片 - 然后是电影 - 再展示一些图片。第一个图片动画显示正常,电影开始正常,并抓住AVPlayerItemDidPlayToEndTimeNotification再次启动图片,但第二个动画永远不会开始 - 我无法解决这个问题? - DoShow1无法正常工作 - 请在那里建议任何人?
- (void)DoShow
{
NSArray *imageNames = @[@"1.jpg", @"2.jpg", @"3.png", @"4.png",
@"5.png", @"6.png",@"7.png", @"8.png",
@"9.png", @"10.png", @"11.png",@"12.png",
@"13.png"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
_imageview.animationImages = images;
_imageview.animationDuration = 10;
_imageview.animationRepeatCount = 1;
[_imageview startAnimating];
[self performSelector:@selector(playmovie) withObject:nil afterDelay: 10];
}
- (void)DoShow1
{
NSArray *imageNames = @[@"14.jpg", @"16.jpg", @"18.jpg", @"19.jpg",
@"20.jpg", @"22.jpg",@"23.jpg", @"24.jpg"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
_imageview2.animationImages = images;
_imageview2.animationDuration = 2;
_imageview2.animationRepeatCount = 100;
[_imageview2 startAnimating];
}
- (void) playmovie
{
MyMusicPlayerManager *sharedManager = [MyMusicPlayerManager sharedManager];
[sharedManager ChkPaused];
NSBundle *Bundle = [NSBundle mainBundle];
NSString *moviePath = [Bundle pathForResource:@"stine_ane" ofType:@"mp4"];
NSLog(@"String is %@", moviePath);
NSURL *url = [NSURL fileURLWithPath:moviePath];
AVPlayerItem *video = [[AVPlayerItem alloc] initWithURL:url];
AVQueuePlayer *queue = [[AVQueuePlayer alloc] initWithItems:@[video]];
video = [[AVPlayerItem alloc] initWithURL:url];
[queue insertItem:video afterItem:nil];
self.avmovieplayer = [[AVPlayerViewController alloc] init];
self.avmovieplayer.player = queue;
[self presentViewController:self.avmovieplayer animated:YES completion:nil];
self.avmovieplayer.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[avmovieplayer.player currentItem]];
[self.avmovieplayer setShowsPlaybackControls:YES];
[self.avmovieplayer.player play];
}
- (void)myMovieFinishedCallback:(NSNotification *)notification {
[self dismissViewControllerAnimated:YES completion:Nil];
[self DoShow1];
}
- (IBAction)DoStart:(id)sender {
[self DoShow];
}
答案 0 :(得分:0)
[self dismissViewControllerAnimated:YES completion:Nil];
[self DoShow1];
这可能是连续调用,动画不会在视图被解散的同时开始。
在视图之后调用的完成处理程序中尝试它 驳回
[self dismissViewControllerAnimated:YES completion:^{
[self DoShow1];
}];