Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Self-Destructing Message iPhone App Retrieving and Viewing Data from Parse.com Retrieving Data from Parse.com

Video 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
STAFF
Amit Bijlani
Treehouse Guest Teacher

You 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.

- (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];
}

That is my CameraViewController.m file

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

The 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.