开发者

Not showing videos in iPhone simulator

开发者 https://www.devze.com 2023-04-12 14:03 出处:网络
I have .m4v video files in ~/Library/Application Support/iphone simulator/4.3.2/Applications/ApplicationGUID/Documents folder. But my application crash when I run. And in NSlog, it shows file path nul

I have .m4v video files in ~/Library/Application Support/iphone simulator/4.3.2/Applications/ApplicationGUID/Documents folder. But my application crash when I run. And in NSlog, it shows file path null.

I have following code in applicationDidFinishLaunching:(UIApplication *)application

NSString  *filePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/Sample_ipod.m4v"]];
NSString  *videoF开发者_如何学运维ilepath = [[NSBundle mainBundle] pathForResource:@"VID"  ofType:@"m4v"];
NSLog(@"Filepath is: %@", videoFilepath);

UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
imagePickerController.delegate = self;
imagePickerController.sourceType = 
UIImagePickerControllerSourceTypePhotoLibrary;

imagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];    
[window addSubview:imagePickerController.view];


Check that the file at filePath exists... you've probably got the path wrong, or the file is getting deleted from your bundle, something like that.

Use NSFileManager to check existence.

If that doesn't fix it, please post details about the crash. What line of code is it crashing on, what message does it give?


You don't give us the crash details, so I assume that it crashes because of the null filePath.

There are better ways of getting the Documents folder, e.g.:

NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"Sample_ipod.m4v"];

Using [[NSBundle mainBundle] pathForResource:...] isn't going to find a file in Documents, which is where you say the files are. Use the code I show above for filePath instead.


Okay. I was able to figure it out. I did not implement method(video:didFinishSavingWithError:contextInfo. That's why, my application was crashing. It works good now.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号