iOS Programming
Objective C + iOS
Profile
Ankit Desai
 Ph.D. Scholar, IET, Ahmedabad University
 Education: M. Tech. CE, B.E. I. T.
 Experience: 7.5 Years (Academic and Research)
 Research Interest: IoT, Big Data Analytics,
Machine Learning, Data Mining.
Create GUI for Video
Playback
Drag and Drop TableView on xib , Link DataSource and Delegate with
ViewController.
Drag Some songs (.mp3s) to
Project
Add library
ViewController.m
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController :
UIViewController<UITableViewDelegate,UITableViewDataSource>
{
NSArray *playlist;
MPMoviePlayerViewController *mp;
NSInteger i;
}
@end
ViewDidLoad Method
- (void)viewDidLoad
{
playlist =[[NSArray
alloc]initWithObjects:@"hawaa",@"sos",@"jobhimain",
@"isqrisk",@"ranitumeinraja",@"balma", nil];
[super viewDidLoad];
}
Orientation Support
-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfac
eOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation !=
UIInterfaceOrientationPortraitUpsideDown);
}
Make sure about
orientations under project’s
properties
Delegate Method 1
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section{
return [playlist count];
}
Delegate Method 2
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
}
cell.textLabel.text = [playlist objectAtIndex:indexPath.row];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
self.title = @"SONGS";
tableView.backgroundColor=[UIColor cyanColor];
return cell;
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
i=indexPath.row;
for (i=0;i<=5 ;i++)
{
NSURL *url=[NSURL fileURLWithPath:[[NSBundle
mainBundle]pathForResource:[playlist objectAtIndex:indexPath.row]
ofType:@"mp3"]];
mp = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:mp];
mp.moviePlayer.movieSourceType=MPMovieSourceTypeFile;
[mp.moviePlayer play];
break;
}
}
Delegate Method 3
Output
Load App Protrait
Thank you
 For further communication or queries:
 Contact me:
 desaiankitb@gmail.com
 www.fb.com/desaiankitb

Presentation14 audio play