Tutorial details

UIPicker With Videos | App Code for Sale | Preview

UIPicker With Videos | iOS Tutorial

How to use picker views with videos

Overview PAGE TOP

Reference: http://www.geekylemon.com/xcode-uipicker-with-videos

In this tutorial i will be showing you how to use picker views with videos

Features:

  • 1 UIPicker
  • 3 Videos

UIPickers are great for selecting large lists of imformations and in this case you can select a video file to play from selecting the file in the picker view, a great alternative from huge lists of options.

ViewController.h PAGE TOP

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController {
IBOutlet UIPickerView *Picker;
NSArray *PickerData;
}
@property (retain, nonatomic) IBOutlet UIPickerView *Picker;
@property (retain, nonatomic) NSArray *PickerData;

@end

ViewController.m PAGE TOP

@implementation ViewController

@synthesize PickerData,Picker,Webview;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *array = [[NSArray alloc] initWithObjects:@"Video1",@"Video2",@"Video3", nil];
self.PickerData = array;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [PickerData count];
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [self.PickerData objectAtIndex:row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
int select = row;
if (select == 0) {

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Video1" ofType:@"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;

} else if (select == 1) {

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Video2" ofType:@"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;

} else if (select == 2) {

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Video3" ofType:@"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
} 
}

@end

Reference PAGE TOP

http://www.geekylemon.com/xcode-uipicker-with-videos

0 Comments Leave a comment

Please login in order to leave a comment.

Newest first
!

Sign-in to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.