1 #import "RootViewController.h"2 #import <MediaPlayer/MediaPlayer.h> 3 #import <mobilecoreservices/ Mobilecoreservices.h> //constants that hold system calls4 @interfaceRootviewcontroller () <uinavigationcontrollerdelegate,uiimagepickercontrollerdelegate>5 6 @end7 8 @implementationRootviewcontroller9 Ten- (void) Viewdidload { One [Super Viewdidload]; A //Do any additional setup after loading the view. - [self createui]; - } the-(void) createui{ -Nsmutablearray *titleary=[[nsmutablearray Alloc] Initwithobjects:@"Take Pictures",@"albums",@"Video", nil]; - for(intI=0; i<titleary.count; i++) { -UIButton *btn=[[uibutton Alloc] Initwithframe:cgrectmake ( -, -+i* -, $, -)]; +Btn.backgroundcolor=[Uicolor Blackcolor]; - [btn Settitle:titleary[i] forstate:uicontrolstatenormal]; +btn.tag=1+i; A [btn addtarget:self Action: @selector (Btn_click:) forcontrolevents:uicontroleventtouchupinside]; at [Self.view addsubview:btn]; - } - -Uiimageview *iv=[[uiimageview Alloc] Initwithframe:cgrectmake ( -, -, $, $)]; -iv.tag= -; - [Self.view Addsubview:iv]; in -}
1-(void) Btn_click: (UIButton *) sender{2Nsinteger i=Sender.tag;3 Switch(i) {4 Case 1:5 //Achieve Photo6 if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) { 7// camera available 8 [self Loadimagepickerwithtype:uiimagepickercontrol Lersourcetypecamera]; 9}Else{TenNSLog (@"photo feature not available"); One } A Break; - Case 2:{ - //Implementing Albums the if ([Uiimagepickercontroller issourcetypeavailable: Uiimagepickercontrollersourcetypephotolibrary]) {// albums available [self loadimagepickerwithtype:uiimagepickercontrollersourcetypephotolibrary]; -}Else{ +NSLog (@"cannot get System album"); - } + } A Break; at Case 3:{ - //Implement video playback - nsstring *strpath=[[nsbundle Mainbundle] Pathforresource:@ "1" ofType:@ " . mp4 " ]; - [self playvedio:strpath]; - } - Break; in default: - // to Break; + } - } the //functions called by photo and album function (Uiimagepickercontrollersourcetype is enum not class do not *) *-(void ) Loadimagepickerwithtype: (uiimagepickercontrollersourcetype) type{ $ uiimagepickercontroller *ipc=[[Uiimagepickercontroller alloc] init]; Panax notoginseng ipc.sourcetype=type; the IPC. delegate= self; the // if it is a photo album feature, set Allow to edit pictures ipc.allowsediting=YES; A [self PRESENTVIEWCONTROLLER:IPC animated:no completion:nil]; the } +-(void) Playvedio: (NSString * ) path { - //enable playback of video files $ if(path.length==0) { $NSLog (@"Please enter a valid file path"); - return; - } the //determine if the file is a local file or a remote file -Nsurl *URL;Wuyi if ([path rangeofstring:@ "/http"].location!=nsnotfound | | [Path rangeofstring:@ "http:"].location!= Nsnotfound) { the //Local File -Url=[Nsurl Urlwithstring:path]; Wu}Else{ - AboutUrl=[Nsurl Fileurlwithpath:path]; $ } - //Create a video playback object - mpmovieplayerviewcontroller *mpvc=[[Mpmovieplayerviewcontroller alloc] initwithcontenturl:url]; - //Set Playback type A mpvc.movieplayer.moviesourcetype= mpmoviesourcetypefile; + //Show Playback window the [self PRESENTVIEWCONTROLLER:MPVC animated:no completion:nil]; - //Play File $ [[MPVC MoviePlayer] play]; the } the #pragmaMark-Protocol function for photo and photo album functions the-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{ the [Picker Dismissviewcontrolleranimated:no completion:nil]; - } in-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: ( Nsdictionary * ) Info { the //In this function get the picture selected by the album theNSString *type=Info[uiimagepickercontrollermediatype]; About //you need to introduce a constant class of systems that defines a variety of constants the if([type isequaltostring: (NSString *) kuttypeimage]) {take// get the picture, handle the picture UIImage *image= Info[uiimagepickercontrollereditedimage]; +Uiimageview *iv= (Uiimageview *) [Self.view Viewwithtag: -]; -Iv.image=image; the }Bayi [Picker Dismissviewcontrolleranimated:no completion:nil]; the}
Multimedia call camera album and video playback