Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonah Kesoyan
2,055 PointsVideo does not appear on a photo sharing app
I'm following the Ribbit tutorial to create a photo sharing app like Instagram. My photos upload perfectly, its even connected to Parse. But when I make a video and select 'use video' on the app, the preview screen just shows a blank screen, any suggesstions?
4 Answers
Amit Bijlani
Treehouse Guest TeacherYou might want try putting a few breakpoints and stepping through the code to see what is going on. If you still can't figure it out then I'd suggest pasting some code or zipping up your project and providing a link here.
Jonah Kesoyan
2,055 Points- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = YES;
self.imagePicker.videoMaximumDuration = 10;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self clear];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"signUp"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chooseImage = info[UIImagePickerControllerEditedImage];
self.chosenImageView.image = chooseImage;
[self dismissViewControllerAnimated:NO completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:NO completion:nil];
[self.tabBarController setSelectedIndex:0];
}
-(void)clear {
self.chosenImageView.image = nil;
self.videoFilePath = nil;
}
- (IBAction)share:(id)sender {
if (self.chosenImageView.image == nil && [self.videoFilePath length] == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Try again!"
message:@"Please capture or select a photo or video to share!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
else {
[self uploadMessage];
}
[self clear];
[self.tabBarController setSelectedIndex:0];
}
-(void)uploadMessage {
NSData *fileData;
NSString *fileName;
NSString *fileType;
if (self.chosenImageView.image != nil) {
fileData = UIImagePNGRepresentation(self.chosenImageView.image);
fileName = @"image.png";
fileType = @"image";
}
else {
fileData = [NSData dataWithContentsOfFile:self.videoFilePath];
fileName = @"video.mov";
fileType = @"video";
}
PFFile *file = [PFFile fileWithName:fileName data:fileData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"An error occurred" message:@"Please try sending your message again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
else {
PFObject *message = [PFObject objectWithClassName:@"Photo"];
[message setObject:file forKey:@"image"];
message[@"whoTook"] = [PFUser currentUser];
message[@"title"] = self.description.text;
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
[self showError];
}
else {
//Everything was successful
[self clear];
}
}];
}
}];
}
-(void)showError {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Could not post your photo or video, please try again" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.description resignFirstResponder];
}
Jonah Kesoyan
2,055 PointsThat is my CameraViewController.m file
Amit Bijlani
Treehouse Guest TeacherThe code seems fine so I'm not sure what could be wrong. I'm assuming you are testing this on a device. Like I suggested previously you might want to add breakpoints in a few key methods and step through your code. Or just compare your code to the project files.