我们的目标是在有人按下按钮时立即显示3-5秒的视频剪辑。
显示实际视频需要几秒钟的延迟,这是不可接受的。我们需要回放感觉瞬间。
将3到5秒转换成动画PNG是一个很好的选择,但是动画PNG在iPhone应用程序中是行不通的。
现在最好的选择是采取相同的图像来创建动画PNG,并在JavaScript中动画化一系列图像。
有谁能想出更好的选择吗?
发布于 2012-06-15 22:41:37
除非你预先加载它们,否则图像和视频有着同样的问题,在大多数蜂窝上至少有700 as的延迟。
你所能做的就是让一个形象精灵扮演一个电影卷轴,就像谷歌为他们的动画涂鸦所做的那样。基本上,您将整个动画放在一个长图像中,将其作为背景放置,然后使用JavaScript提高每个帧的背景位置。例如,如果您有一个3s200x100图像,您希望每100 3s进行一次升级,您可以这样做:
<div class="thumb" style="background-image: url(vid1.png); width:200px; height:100px" data-frames="30">
</div>
$('.thumb').bind('click', function() {
var $img = $(this);
var startTime = Date.now();
var frames = $img.attr('data-frames');
var width = $img.width();
setInterval(function() {
var frame = Math.round((Date.now() - startTime) / 100) % frames;
$img.css('background-position', -frame * width + 'px 0';
}, 100);
});更新
因为您只是在这里使用一个图像,所以不再受格式的约束。你最好的选择是将电影片重新编码成60%或85%的JPG,大大减少文件大小。既然你是动画,质量就变得不那么重要了。
更新2
我的意思是包括跳过帧的情况下,超时不是完美的。
发布于 2012-06-16 04:31:23
UIImageView支持animationImages。这是一个动画PNG的所有意图和目的。@Brian是正确的,但是,除非预加载,否则您将有一些延迟。
所以我的建议是预装。
视频也是如此。您可以将MPMoviePlayerController全部设置为play,只是在按下按钮之前不要添加视图和播放。
动画图像创意:
- (void)readySet {
NSMutableArray *images = [NSMutableArray array];
for (int i=0; i<kIMAGE_COUNT; i++) {
NSString *fn = [NSString stringWithFormat:@"image%d.png"];
UIImage *image = [UIImage imageNamed:fn];
[images addObject:image];
}
self.myUIImageView.animationImages = [NSArray arrayWithArray:images];
}
// go runs fast if we run readySet first
//
- (void)go {
[self.myUIImageView startAnimating];
}视频创意
// A little more complex because we need to get notified that it's ready to play,
// but the same principal...
- (void)readySet {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
player.shouldAutoplay = NO;
[player prepareToPlay];
self.mp = player;
}
- (void)moviePlayerLoadStateChanged:(NSNotification*)notification {
MPMovieLoadState state = [self.mp loadState];
if (state & MPMovieLoadStatePlaythroughOK) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
self.mp.view.frame = CGRect(/* where it will appear */)
}
}
// go runs fast if we run readySet first (and the movie is ready)
//
- (void)go {
MPMovieLoadState state = [self.mp loadState];
if (state & MPMovieLoadStatePlaythroughOK) {
[self.view addSubview:self.mp.view];
[self.mp play];
} else {
self.mp.shouldAutoplay = YES;
}
}https://stackoverflow.com/questions/11058935
复制相似问题