(1 July 2013) iOS Basic Development 4 - Multimedia1. iPhone Developer Basic Program
Day 4 View &ViewController (2)
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
2. Course Outline
1. Introduction & Xcode
2. Objective-C & Frameworks
3. View &ViewController
4. View &ViewController (2)
5. Submit App Store
Course Outline
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
3. www.ibluecode.com/training.html
Day 1 - 5 Slide
www.slideshare.net/eakkattiya
Additional Course
eakkattiya@gmail.com
086-6732111
twitter.com/eakkattiya
facebook.com/eakapong.kattiya
Resources
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
6. #import <UIKit/UIKit.h>
@interface MediaViewController : UIViewController
<UIImagePickerControllerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
- (IBAction)selectPhoto:(id)sender;
@end
UIImagePickerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
7. @implementation MediaViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.topViewController.title = @"Media" ;
}
- (IBAction)selectPhoto:(id)sender {
UIImagePickerController *imagePicker = [UIImagePickerController new];
[imagePicker setDelegate:self];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}else{
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[self presentViewController:imagePicker animated:YES completion:nil];
}
@end
UIImagePickerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
8. @implementation MediaViewController
-(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
NSLog(@"info =%@",[info description]);
UIImage *pickedImage = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
self.myImageView.image = pickedImage ;
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissViewControllerAnimated:YES completion:nil];
}
@end
UIImagePickerControllerDelegate
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
10. by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
12. •AV Foundation
Support : .mp3 ,.aac and more..
•MediaPlayer
Support : mov, mp3, mp4, mpv, and 3gp
•Http Live Streaming
Support : .M3U8 and .ts
AUDIO &VIDEO
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
13. Class : MPMoviePlayerController
Framework : MediaPlayer/MediaPlayer.h
Sample Code : MoviePlayer
Init : - initWithContentOfURL : (NSURL*)
Property : Frame
Method : prepareToPlay / play
MPMoviePlayerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
14. การเรียกใช้งาน
1. Add Framework <MediaPlayer>
MPMoviePlayerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
15. การเรียกใช้งาน
1. Add Framework <MediaPlayer>
MPMoviePlayerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
16. การเรียกใช้งาน
1. Add Framework <MediaPlayer>
MPMoviePlayerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
17. การเรียกใช้งาน
1. Add Framework <MediaPlayer>
2. #import <MediaPlayer/MediaPlayer.h>
3. Create NSURL
4. Init MPMoviePlayerViewController
5. call [self presentMoviePlayerViewControllerAnimated:YES] ;
MPMoviePlayerViewController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
18. #import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MediaViewController : UIViewController
<UIActionSheetDelegate>
{
MPMoviePlayerController *mediaPlayer ;
MPMoviePlayerViewController *mediaPlayerVC ;
}
- (IBAction)playMedia:(id)sender;
- (IBAction)pauseMedia:(id)sender;
@end
MPMoviePlayerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
19. by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
@implementation MediaViewController
- (IBAction)playMedia:(id)sender {
UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"Select Media"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Music",
@"Record Sound",
@"Movie",
@"Streaming",
nil];
[action showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
[self playMusic];
}else if(buttonIndex == 1){
[self playRecord];
}else if(buttonIndex == 2){
[self playMovie];
}else if(buttonIndex == 3){
[self playStreaming];
}
}
@end
UIActionSheet & Delegate
Sunday, June 9, 13
20. - (void)playStreaming{
NSURL *url = [NSURL URLWithString:
@"http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"];
mediaPlayerVC = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:mediaPlayerVC];
}
MPMoviePlayerViewController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
21. การเรียกใช้งาน
1. Add Framework <MediaPlayer>
2. #import <MediaPlayer/MediaPlayer.h>
3. Create NSURL
4. Init MPMoviePlayerController
5. call setFrame
6. call addSubView
7. call play
MPMoviePlayerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
22. - (void)playMovie{
NSURL *url = [[NSBundle mainBundle] URLForResource:@"movie"
withExtension:@"m4v"];
mediaPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[mediaPlayer.view setFrame:self.myImageView.bounds];
[mediaPlayer prepareToPlay];
[self.view addSubview:mediaPlayer.view];
}
MPMoviePlayerController
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
23. #import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MediaViewController : UIViewController
<AVAudioPlayerDelegate>
{
AVAudioPlayer *audioPlayer ;
}
- (IBAction)playMedia:(id)sender;
- (IBAction)pauseMedia:(id)sender;
@end
AVFoundation / AVAudioPlayer
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
24. by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
AVFoundation / AVAudioPlayer
@implementation MediaViewController
- (void)playMedia:(id)sender {
NSURL *url = [[NSBundle mainBundle] URLForResource:@"background"
withExtension:@"mp3"];
NSError *error = nil ;
if(!audioPlayer){
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url
error:&error];
}
[audioPlayer play];
}
- (IBAction)pauseMedia:(id)sender {
[audioPlayer pause];
}
@end
Sunday, June 9, 13
25. #import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MediaViewController : UIViewController
<AVAudioRecorderDelegate>
{
AVAudioRecorder *audioRecorder;
}
@property (weak, nonatomic) IBOutlet UIBarButtonItem *recordButton;
- (IBAction)playMedia:(id)sender;
- (IBAction)pauseMedia:(id)sender;
- (IBAction)recordOrStop:(id)sender;
@end
AVFoundation / AVAudioRecoder
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
26. by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
AVFoundation / AudioRecorder
@implementation MediaViewController
- (IBAction) recordOrStop: (id) sender {
NSString *soundPath = [NSHomeDirectory()
stringByAppendingPathComponent:@"Documentsrecord.caf"];
NSURL *url = [NSURL fileURLWithPath:soundPath];
if (audioRecorder.isRecording) {
[self.recordButton setTitle:@"Stop"];
[audioRecorder stop];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
} else {
[self.recordButton setTitle:@"Recording.."];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord
error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSNumber numberWithInt:AVAudioQualityMax], AVEncoderAudioQualityKey, nil];
AVAudioRecorder *newRecorder = [[AVAudioRecorder alloc] initWithURL:url
settings:recordSettings
error:nil];
audioRecorder = newRecorder;
audioRecorder.delegate = self;
[audioRecorder prepareToRecord];
[audioRecorder record];
}
}
@end
Sunday, June 9, 13
27. by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
AudioRecorderDelegate
@implementation MediaViewController
-(void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder
successfully:(BOOL)flag
{
NSLog(@"success recording");
}
-(void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder
error:(NSError *)error
{
NSLog(@"fail recording");
}
@end
Sunday, June 9, 13
29. -(void)initScrollView
{
NSURL *url = [[NSBundle mainBundle]URLForResource:@"gallery"
withExtension:@"plist"];
NSArray *items = [NSArray arrayWithContentsOfURL:url];
UIScrollView *scv = [[UIScrollView alloc]initWithFrame:self.view.frame];
[scv setContentSize:CGSizeMake(320*items.count, 320)];
[scv setPagingEnabled:YES];
[self.view addSubview:scv];
NSInteger i = 0;
for(NSString *imageName in items){
UIImageView *imageView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:imageName]];
[imageView setFrame:CGRectMake(320*i, 0, 320, 320)];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
[scv addSubview:imageView];
i++ ;
}
}
UIScrollView
by Eakapong Kattiya www.ibluecode.com eak.k@ibluecode.com +66 086-673-2111
Sunday, June 9, 13
30. by Eakapong Kattiya
Developing iOS Apps : App Store
Add New Application ( iTunes Connect )
Upload required icon and screenshots
Upload Application Binary ( IPA File )
Waiting for app review by apple ( 7 days - Few months)
Sunday, June 9, 13
31. AppStore
- เปิดตัววันที่ 10 July 2008
- เป็นครั้งแรกและเป็นช่องทางที่ง่ายที่สุดที่จะทําให้นักพัฒนา
สามารถขาย Application ให้กับคน 155 ประเทศทั่วโลก
- ผู้ใช้ 400 ล้านคนที่ีมีบัตร Credit
by Eakapong Kattiya
Sunday, June 9, 13
32. AppStore
5-March-2012
- จํานวน App รวม (iPhone/iPad/iPodTouch) คือ 550,000+
- จํานวน App บน iPad คือ 170,000 +
- ยอด AppStore Download 25,000 ล้านครั้ง
12-June-2012
- ปัจจุบันจํานวน App รวม (iPhone/iPad/iPodTouch) คือ 650,000+
- จํานวน App บน iPad คือ 225,000 +
- ยอด AppStore Download 30,000 ล้านครั้ง
by Eakapong Kattiya
Sunday, June 9, 13
44. In-App Purchases (The SmurfsVillage)
8-Year-Old Girl Racks Up $1400 Bill Buying Smurfberries in
Smurf's Village
by Eakapong Kattiya
Sunday, June 9, 13