One.
Two, engineering drawings.
Three, code.
RootViewController.h
#import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface Rootviewcontroller: uiviewcontroller<avaudioplayerdelegate,uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate>{ Uiimageview * Backimageview; Avaudioplayer *_audioplayer; Nsmutablearray *musicarray; Nsmutablearray *titlearray; int songindex; UIButton * LeftButton; UIButton * Rightbutton; UILabel *titlelabel; UISlider *slider; UISlider *volumeslider; Nstimer * Processtimer; Nstimer * timer1; } @end
Rootviewcontroller.m
#import "RootViewController.h" @interface Rootviewcontroller () @end @implementation rootviewcontroller-(void) viewdidload{[Super Viewdidload]; Self.title = @ "story"; Initialize data [self initdata]; Initialize the background map [self initbackgroundview]; } #pragma-mark-functions//initialization data-(void) initdata{Musicarray=[[nsmutablearray alloc]initwithobjects:@ "7" @ "11" @ "9" , @ "+", @ "5", @ "6", @ "1", @ "8", @ "@", @ "ten", @ "2", @ "a", @ "4", @ "+", @ "+", @ "+", @ "3", @ "+", nil]; Titlearray=[[nsmutablearray alloc]initwithobjects:@ "Three bulls and Lions" @ "Little Red Riding Hood" @ "Tiannvsanhua" @ "Friends Goodbye" @ "Nu wa made Man" @ "The dumb Water of Tenjin" @ "Little frog listen to the story", @ "Tao Tao Desire", @ "polite", @ "Ugly duckling", @ "mouse, bird and sausage", @ "two donkeys", @ "Donkey and Master", @ "four friends", @ "prizes", @ "can't pass", @ "five peas" @ "Peter Pan", nil]; }//Initialization background Map-(void) initbackgroundview{self.navigationController.navigationBar.tintColor =[uicolor Orangecolor]; Self.navigationController.navigationBar.tintColor = [Uicolor colorwithred:69.0/255 green:161.0/255 blue:241.0/255 ALPHA:1]; Background backimageview= [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, 320, 460)]; backimageview.image= [UIImage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [Musicarray Objectatindex:songindex] ]]; [Self.view Addsubview:backimageview]; Play uibutton* button= [UIButton Buttonwithtype:uibuttontypecustom]; Button.frame=cgrectmake (130, 260, 60, 50); button.tag=100; [Button addtarget:self action: @selector (play:) forcontrolevents:uicontroleventtouchupinside]; [Button setimage:[uiimage imagenamed:@ "Play.png"] forstate:uicontrolstatenormal]; [Self.view Addsubview:button]; Previous leftbutton= [UIButton Buttonwithtype:uibuttontypecustom]; Leftbutton.frame=cgrectmake (50, 260, 60, 50); [LeftButton addtarget:self Action: @selector (Prier) forcontrolevents:uicontroleventtouchupinside]; [LeftButton setimage:[uiimage imagenamed:@ "Left.png"] forstate:uicontrolstatenormal]; [Self.view Addsubview:leftbutton]; Next rightbutton= [UIButton Buttonwithtype:uibuttontypecustom]; Rightbutton.frame=cgrectmake (210, 260, 60, 50); [Rightbutton addtarget:self Action: @selector (next) forcontrolevents:uicontroleventtouchupinside]; [Rightbutton setimage:[uiimage imagenamed:@ "Right.png"] forstate:uicontrolstatenormal]; [Self.view Addsubview:rightbutton]; Volume button UIButton *volumebutton= [UIButton Buttonwithtype:uibuttontypecustom]; Volumebutton.frame=cgrectmake (10, 330, 40, 40); [Volumebutton setimage:[uiimage imagenamed:@ "Labalan.png"] forstate:uicontrolstatenormal]; [Volumebutton addtarget:self Action: @selector (Showvolume) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:volumebutton]; Background UIButton *backbutton= [UIButton Buttonwithtype:uibuttontypecustom]; Backbutton.frame=cgrectmake (270, 330, 40, 40); [Backbutton setimage:[uiimage imagenamed:@ "Apple.png"] forstate:uicontrolstatenormal]; [Backbutton addtarget:self Action: @selector (SetBackground) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:backbutton]; Music logo picture uiimageview* musicimageview= [[Uiimageview alloc] Initwithimage: [UIImage imagenamed:@] Musiclogo.png "]]; Musicimageview.frame= CGRectMake (80, 40, 160, 140); [Self.view Addsubview:musicimageview]; Title titlelabel= [[UILabel alloc] Initwithframe:cgrectmake (0, 195, 320, 30)]; titlelabel.font= [Uifont systemfontofsize:25]; Titlelabel.textalignment= Nstextalignmentcenter; titlelabel.textcolor= [Uicolor Bluecolor]; titlelabel.numberoflines=0; titlelabel.backgroundcolor= [Uicolor Clearcolor]; titlelabel.text= [Titlearray objectatindex:0]; [Self.view Addsubview:titlelabel]; Progress Control slider= [[UISlider alloc] Initwithframe:cgrectmake (50, 230, 220, 5)]; slider.maximumvalue=100; slider.minimumvalue=0; slider.value=0; Slider.continuous=no; [Slider addtarget:self Action: @selector (Processset:) forcontrolevents:uicontroleventvaluechanged]; [Slider addtarget:self Action: @selector (Processtimerstop) ForcontrolevEnts:uicontroleventtouchdown]; [Self.view Addsubview:slider]; Volume Control volumeslider= [[UISlider alloc] Initwithframe:cgrectmake (-85, 280, 220, 5)]; volumeslider.maximumvalue=1; volumeslider.minimumvalue=0; Volumeslider.value= 0.5; Volumeslider.hidden=yes; [Volumeslider addtarget:self Action: @selector (VolumeSet:) forcontrolevents:uicontroleventvaluechanged]; volumeslider.transform= cgaffinetransformmakerotation ( -90* m_pi/180); [Self.view Addsubview:volumeslider]; Processtimer=[nstimer scheduledtimerwithtimeinterval:0.1 target:self Selector: @selector (process) Userinfo:nil Repeats:yes]; [Self Loadmusic:[musicarray objectatindex:0] type:@ "MP3"]; uilongpressgesturerecognizer* rightlongpress= [[Uilongpressgesturerecognizer alloc] initwithtarget:self action:@ Selector (rightlongpress:)]; [Rightbutton addgesturerecognizer:rightlongpress]; uilongpressgesturerecognizer* leftlongpress= [[Uilongpressgesturerecognizer alloc] InitwithTarget:self Action: @selector (leftlongpress:)]; [LeftButton addgesturerecognizer:leftlongpress]; }//Progress Control-(void) Processset: (uislider*) slider{Processtimer=[nstimer scheduledtimerwithtimeinterval:0.1 target:self Selector: @selector (process) Userinfo:nil Repeats:yes]; _audioplayer.currenttime=slider.value/100*_audioplayer.duration; if (_audioplayer.playing==yes) [_audioplayer playattime:_audioplayer.currenttime];} -(void) processtimerstop{[Processtimer invalidate];} background-(void) setbackground{uiimagepickercontroller* picker= [[Uiimagepickercontroller alloc] init]; Picker.sourcetype= Uiimagepickercontrollersourcetypesavedphotosalbum; picker.delegate=self; [Self Presentviewcontroller:picker animated:no completion:nil];} #pragma-mark-doclickactions//Right button gesture-(void) Rightlongpress: (uilongpressgesturerecognizer*) longpress{if ( Longpress.state! = Uigesturerecognizerstatebegan) return; if (_audioplayer.playing) {if (_audioplayer.currenttime>_AUDIOPLAYER.DURATION-5) _audioplayer.currenttime=_audioplayer.currenttime; else _audioplayer.currenttime+=5; [_audioplayer Playattime:_audioplayer.currenttime]; }}//left button gesture-(void) Leftlongpress: (uilongpressgesturerecognizer*) longpress{if (longpress.state! = Uigesturerecognizerstatebegan) return; if (_audioplayer.playing) {if (_audioplayer.currenttime<5) _audioplayer.currenttime=0; else _audioplayer.currenttime-=5; [_audioplayer Playattime:_audioplayer.currenttime]; printf ("left\n"); }}//snowflake Function-(void) snow{int startx= random ()%320; int endx= random ()%320; int width= random ()%25; CGFloat time= (Random ()%100)/10+5; CGFloat alp= (random ()%9)/10.0+0.1; uiimage* image= [UIImage imagenamed:@ "Snow.png"]; uiimageview* ImageView = [[Uiimageview alloc] initwithimage:image]; Imageview.frame= CGRectMake (startx,-1*width,width,width); ImageView.alpha=alp; [Self.view Addsubview:imageview]; [UIView Beginanimations:nil context: (__bridge void *) (ImageView)]; [UIView Setanimationduration:time]; if (endx>50&&endx<270) {imageview.frame= CGRectMake (EndX, 270-WIDTH/2, width, width); } else if ((endx>10&&endx<50) | | | (endx>270&&endx<310)) Imageview.frame= CGRectMake (EndX, 400-WIDTH/2, width, width); else imageview.frame= CGRectMake (endx, 480, width, width); [UIView setanimationdidstopselector: @selector (onAnimationComplete:finished:context:)]; [UIView setanimationdelegate:self]; [UIView commitanimations];} -(void) Onanimationcomplete: (nsstring*) Animationid finished: (nsnumber*) finished context: (void*) context{ uiimageview* snowview= (__bridge Uiimageview *) (context); [Snowview Removefromsuperview]; }//Package System load Function-(void) Loadmusic: (nsstring*) name type: (nsstring*) type{nsstring* path= [[NSBundle Mainbundle] Pathforresource:name Oftype:type]; nsurl* url = [Nsurl Fileurlwithpath:path]; _audioplayer= [[Avaudioplayer alloc] Initwithcontentsofurl:url Error:nil]; _audioplayer.delegate=self; _audioplayer.volume= 0.5; [_audioplayer Preparetoplay]; }//volume Setting-(void) VolumeSet: (uislider*) slider{_audioplayer.volume= Slider.value;} -(void) showvolume{volumeslider.hidden=no; [Nstimer scheduledtimerwithtimeinterval:5.0 target:self selector: @selector (hidevolume) Userinfo:nil repeats:no];} -(void) hidevolume{volumeslider.hidden=yes;} Song Progress-(void) process{slider.value= 100*_audioplayer.currenttime/_audioplayer.duration;} #pragma-mark-doclickactions//play-(void) Play: (uibutton*) button{if (_audioplayer.playing) {[Button setimage:[ UIImage imagenamed:@ "Play.png"] forstate:uicontrolstatenormal]; [_audioplayer pause]; [Timer1 invalidate]; } else {[button setimage:[uiimage imagenamed:@ "Stop.png"] forstate:uicontrolstatenormal]; Timer1=[nstimer Scheduledtimerwithtimeinterval:0.1 target:self selector: @selector (Snow) Userinfo:nil Repeats:yes]; [_audioplayer play]; }}//previous-(void) prier{BOOL playflag; if (_audioplayer.playing) {playflag=yes; [_audioplayer stop]; } else {playflag=no; } songindex--; if (songindex<0) songindex= musicarray.count-1; [Self Loadmusic:[musicarray objectatindex:songindex] type:@ "MP3"]; UIImage * image = [UIImage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [Musicarray Objectatindex:songindex]]; [Self setbackground:image]; titlelabel.text= [Titlearray Objectatindex:songindex]; if (playflag==yes) {[_audioplayer play]; }}//Next-(void) next{BOOL playflag; if (_audioplayer.playing) {playflag=yes; [_audioplayer stop]; } else{Playflag=no; } songindex++; if (songindex==musicarray.count) {songindex= 0; } [self Loadmusic:[musicarray objEctatindex:songindex] type:@ "MP3"]; UIImage * image = [UIImage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [Musicarray Objectatindex:songindex]]; [Self setbackground:image]; titlelabel.text= [Titlearray Objectatindex:songindex]; if (playflag==yes) {[_audioplayer play]; }} #pragma-mark-avaudioplayerdelegate//playback complete automatic switching-(void) audioplayerdidfinishplaying: (Avaudioplayer *) player Successfully: (BOOL) flag{songindex++; if (Songindex==musicarray.count) songindex= 0; [Self Loadmusic:[musicarray objectatindex:songindex] type:@ "MP3"]; titlelabel.text= [Titlearray Objectatindex:songindex]; [_audioplayer play]; } #pragma-mark-uiimagepickercontrollerdelegate-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{[self Dismissviewcontrolleranimated:yes completion:nil];} -(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker didfinishpickingimage: (UIImage *) Image Editinginfo :(nsdictionary *) editinginfo{backimageview.image = image; [Self Dismissviewcontrolleranimated:yes completion:nil];} -(void) SetBackground: (UIImage *) image{backimageview.image = image; } @end
"Code Notes" to listen to a story