CS185c
Chris Pollett
Dec 1, 2010
#import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface AudioTestIPhoneViewController : UIViewController { IBOutlet UIButton *playButton; IBOutlet UIButton *stopButton; AVAudioPlayer *audioPlayer; } @property (nonatomic, retain) IBOutlet UIButton *playButton; @property (nonatomic, retain) IBOutlet UIButton *stopButton; @property (nonatomic, retain) AVAudioPlayer *audioPlayer; -(IBAction)play; -(IBAction)stop; @end
// // AudioTestIPhoneViewController.m // AudioTestIPhone // // Created by Chris Pollett on 12/1/10. // Copyright 2010 San Jose State University. All rights reserved. // #import "AudioTestIPhoneViewController.h" @implementation AudioTestIPhoneViewController @synthesize playButton; @synthesize stopButton; @synthesize audioPlayer; - (void)viewDidLoad { [super viewDidLoad]; // Get the file path to the song to play. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"warworlds" ofType:@"mp3"]; // Convert the file path to a URL. NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath]; //Initialize the AVAudioPlayer. self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]; // Preloads the buffer and prepares the audio for playing. [self.audioPlayer prepareToPlay]; [filePath release]; [fileURL release]; } -(IBAction)play { // Make sure the audio is at the start of the stream. self.audioPlayer.currentTime = 0; [self.audioPlayer play]; } -(IBAction)stop { [self.audioPlayer stop]; } - (void)dealloc { [super dealloc]; } @end
// // VideoDemoViewController.m // VideoDemo // // Created by Chris Pollett on 12/1/10. // Copyright 2010 San Jose State University. All rights reserved. // #import "VideoDemoViewController.h" #import <MediaPlayer/MediaPlayer.h> @implementation VideoDemoViewController - (void)viewDidLoad { NSString *url = [[NSBundle mainBundle] pathForResource:@"fredott" ofType:@"mp4"]; MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; //---play movie--- [player play]; [super viewDidLoad]; } - (void) movieFinishedCallback:(NSNotification*) aNotification { MPMoviePlayerController *player = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; [player autorelease]; } @end
// // CameraIPhoneViewController.h // CameraIPhone // // Created by Chris Pollett on 12/1/10. // Copyright 2010 San Jose State University. All rights reserved. // #import@interface CameraIPhoneViewController : UIViewController { IBOutlet UIImageView *imageView; IBOutlet UIButton *takePictureButton; IBOutlet UIButton *selectFromCameraRollButton; } @property (nonatomic, retain) UIImageView *imageView; @property (nonatomic, retain) UIButton *takePictureButton; @property (nonatomic, retain) UIButton *selectFromCameraRollButton; - (IBAction)getCameraPicture:(id)sender; - (IBAction)selectExistingPicture; @end
// // CameraIPhoneViewController.m // CameraIPhone // // Created by Chris Pollett on 12/1/10. // Copyright 2010 San Jose State University. All rights reserved. // #import "CameraIPhoneViewController.h" @implementation CameraIPhoneViewController @synthesize imageView; @synthesize takePictureButton; @synthesize selectFromCameraRollButton; - (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. } - (void)dealloc { [imageView release]; [takePictureButton release]; [selectFromCameraRollButton release]; [super dealloc]; } #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]; [picker release]; } -(IBAction)selectExistingPicture { if([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentModalViewController:picker animated:YES]; [picker release]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Darn!" otherButtonTitles:nil]; [alert show]; [alert release]; } } -(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