Multimedia on iPhone




CS175

Chris Pollett

Nov 24, 2014

Outline

Multimedia on iPhone

Audio app

The Storyboard and Implementation

Quiz

Which of the following is true?

  1. A gesture event is always a single user touch of the screen by one finger followed by an immediate release.
  2. If we handle both single and double taps then our code can detect immediately without a delay that only a single tap occurred.
  3. An Android MediaPlayer object can be used to play an mp3.

VideoDemoViewController.m

Video Demo in Action

Demo of video being played

The Camera and Photo Library

CameraIPhoneViewController.h



#import <UIKit/UIKit.h>

@interface CameraIPhoneViewController : UIViewController 
 <UIImagePickerControllerDelegate, UINavigationControllerDelegate> 
@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, weak) UIButton *takePictureButton;
@property (nonatomic, weak) UIButton *selectFromCameraRollButton;
- (IBAction)getCameraPicture:(id)sender;
- (IBAction)selectExistingPicture;
@end

The Storyboard file

CameraIPhoneViewController.m


#import "CameraIPhoneViewController.h"

@implementation CameraIPhoneViewController

- (void)viewDidLoad {
   if(![UIImagePickerController 
		isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
	   takePictureButton.hidden = YES;
	   selectFromCameraRollButton.hidden = YES;
   }
}

 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}


#pragma mark -
-(IBAction)getCameraPicture: (id)sender {
	UIImagePickerController *picker = [[UIImagePickerController alloc] init];
	picker.delegate = self;
	picker.allowsImageEditing = YES;
	picker.sourceType = (sender == takePictureButton) ?
		UIImagePickerControllerSourceTypeCamera :
		UIImagePickerControllerSourceTypeSavedPhotosAlbum;
	[self presentModalViewController:picker animated: YES];
}

-(IBAction)selectExistingPicture {
	if([UIImagePickerController isSourceTypeAvailable:
		UIImagePickerControllerSourceTypePhotoLibrary]) {
		UIImagePickerController *picker = 
			[[UIImagePickerController alloc] init];
		picker.delegate = self;
		picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
		[self presentModalViewController:picker animated:YES];
	} else {
		UIAlertView *alert = [[UIAlertView alloc]
			initWithTitle:@"Error accessing photo library" 
			message:@"Device does not support a photo library" 
			delegate:nil 
			cancelButtonTitle:@"Darn!" 
							  otherButtonTitles:nil];
	}
}

-(void)imagePickerController:(UIImagePickerController *)picker
		didFinishPickingImage:(UIImage *)image
				 editingInfo:(NSDictionary *)editingInfo {
	imageView.image = image;
	UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
	[picker dismissModalViewControllerAnimated:YES];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
	[picker dismissModalViewControllerAnimated:YES];
}

@end