iphone - 如何将视频添加到 iPad 模拟器? [英] iphone - How do I add videos to iPad simulator?

查看:31
本文介绍了iphone - 如何将视频添加到 iPad 模拟器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不,将视频拖放到

~/Library/Application Support/iPhone Simulator/3.2/Media/DCIM/100APPLE

不能完全工作,因为模拟器可以在 Photos.app 上看到视频,但是当我尝试使用 UIImagePickerController 选择视频时,我的应用程序崩溃了.

does not work totally, because the simulator can see the video on Photos.app, but when I try to pick a video using UIImagePickerController my application crashes.

我认为这可能与视频必须具有的格式有关.我正在使用 QuickTime 生成视频.我正在使用适用于 iPhone"的设置……所以它生成了一个具有 480x360 像素 H264 的 M4V.我试图创建一个具有相同特性的 MOV 和一个具有 640x480 的 MOV,但没有任何效果.我还掉了一部用 iPhone 3GS 创建的电影,但它仍然崩溃.

I think this may have some relation to the format the video has to have. I am using QuickTime to generate the video. I am using the settings "for iPhone"... so it is generating a M4V with 480x360 pixels H264. I have tried to create a MOV with the same characteristics and one with 640x480 but nothing works. I have also dropped a movie created with iPhone 3GS and it still crashes.

我有一个名为 VID_0001.MOV 的文件,全部大写.

I have the file named as VID_0001.MOV, all uppercase.

这是我崩溃时看到的错误

this is the error I see when it crashes

*** 由于未捕获的异常NSRangeException"而终止应用程序,原因:*** -[NSCFArray objectAtIndex:]: 索引 (1) 超出范围 (0)'

方法 didFinishPickingMediaWithInfo 从未被调用,因此它在模拟器或视频上存在一些问题.我一选择视频,应用就会崩溃.

the method didFinishPickingMediaWithInfo is never called, so its some issue on the simulator or on the video. The app crashes as soon as I pick the video.

这个问题没有解决方案?来吧伙计们!:-)

No solution for this question? c'mon guys! :-)

谢谢.

推荐答案

花了一秒钟(还有一些狡猾)但我想通了.将视频文件放入应用程序的 Documents 目录中,我尝试了 .MOV 但没有用,.m4v 有效.然后把它放在你的应用程序的早期(我只是把它放在应用程序中:didFinishLaunchingWithOptions):

Took a sec (and some deviousness) but I figured it out. Put a video file into your application's Documents directory, I tried a .MOV but that didn't work, a .m4v worked. Then put this early in your app (I just stuck it in application:didFinishLaunchingWithOptions):

    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/myMovie.m4v"]];
    UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);

并添加此函数(以便您可以查看是否发生错误以及原因):

And add this function (so you can see if an error happened and why):

- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    if (error != nil) {
        NSLog(@"Error: %@", error);
    }
}

效果非常好,我现在在模拟器上的已保存照片"中有一段视频.

Worked like a charm, I now have a video in my 'Saved Photos' on the simulator.

这篇关于iphone - 如何将视频添加到 iPad 模拟器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆