Multimedia Audio Video and ipad basic usage

Source: Internet
Author: User

Multimedia Audio Video and ipad basic use one, multimedia playback

1. Configure the library--avfoundation.framework

Header file #import <AVFoundation/AVFoundation.h>

2. Play audio (1) Play local audio
@interface Viewcontroller () {  //  avaudioplayer *_player;    UISlider *_volumeslider;  // Volume Control //     uiprogressview *_playprogressview;   // Play Progress  **playprogressview;
#pragmaMark-Play local music file-(void) playlocationaudio{NSData*data = [[NSData alloc] Initwithcontentsoffile:[[nsbundle Mainbundle] Pathforresource:@"Lalala.mp3"Oftype:nil]]; _player= [[Avaudioplayer alloc] Initwithdata:data Error:nil];//Initialize__weaktypeof(self) weakself =Self ; [Self.view Addsystembuttonwithframe:cgrectmake ( -, -, -, -) Title:@"Play"action:^ (UIButton *button) {        //[Weakself.player play];  }]; //Add button -to play[Self.view Addsystembuttonwithframe:cgrectmake ( -, Max, -, -) Title:@"Stop"action:^ (UIButton *button) {        //[Weakself.player stop];//Note: Stop, pause pausesWeakSelf.player.currentTime =0;//set playback from scratchWeakSelf.playProgressView.progress =0;  }]; //Add button --Stop//Progress Control (Uiprogressview)_playprogressview = [[Uiprogressview alloc] Initwithframe:cgrectmake ( -, $,280, -)];        [Self.view Addsubview:_playprogressview]; [Nstimer scheduledtimerwithtimeinterval:0.1target:self selector: @selector (dealtimer:) Userinfo:nil Repeats:yes]; //Add gesturesUITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Dealtap:)];        [_playprogressview Addgesturerecognizer:tap]; //Volume Control (uislider)_volumeslider = [[UISlider alloc] Initwithframe:cgrectmake ( -, -,280, -)];    [Self.view Addsubview:_volumeslider]; _volumeslider.maximumvalue=Ten; _volumeslider.minimumvalue=0; [_volumeslider addtarget:self Action: @selector (Dealslider:) forcontrolevents:uicontroleventvaluechanged];}#pragmaMark-Volume Control-(void) Dealslider: (UISlider *) silder{_player.volume= _volumeslider.value;//adjust the current volume to match the slider}#pragmaMark-Progress Control-(void) Dealtimer: (Nstimer *) timer{if(_player.duration! =0){        //progress = Current time/Total time_playprogressview.progress = _player.currenttime/_player.duration; }}-(void) Dealtap: (UITapGestureRecognizer *) tap{Cgpoint Point=[Tap Locationinview:_playprogressview]; NSLog (@"point.x =%f", Point.x); //set the value to click on    DoubleTime = _player.duration * (Point.x/_playprogressview.frame.size.width); NSLog (@"Time =%f", time); _player.currenttime= time;//    }
(2) Play online audio
#pragmaMark-Play Online music-(void) audiopalyurlmusicusedemo{//  http://yinyueshiting.baidu.com/data2/music/239130183/1226741191429509661128.mp3?xcode= 401EE63DCC7ECE3E28EE0F6F3C6EA015C3BA3C8B80064E3BNSString *urlstr =@"http://yinyueshiting.baidu.com/data2/music/239130183/1226741191429509661128.mp3?xcode= 401EE63DCC7ECE3E28EE0F6F3C6EA015C3BA3C8B80064E3B"; _streamer=[[Audiostreamer alloc] Initwithurl:[nsurl Urlwithstring:urlstr]]; __weaktypeof(self) weakself =Self ; [Self.view Addsystembuttonwithframe:cgrectmake ( -, -, -, -) Title:@"Play"action:^ (UIButton *button) {        //[Weakself.streamer start];  }]; //Add button -to play[Self.view Addsystembuttonwithframe:cgrectmake ( -, Max, -, -) Title:@"Stop"action:^ (UIButton *button) {        //[Weakself.streamer stop];  }]; //Add button --Stop//..........}
(3) Play video
// ----------------3. Play the video    ----------------------------------- // play local video files     // 1. Gakou-->mediaplayer.framework  , header file
#pragmaMark-Play Video File-(void) audiomediousedemo{//play local video files__weaktypeof(self) weakself =Self ; [Self.view Addsystembuttonwithframe:cgrectmake ( -, -, -, -) Title:@"Play local file"action:^ (UIButton *button) {        //get local video files --playNSString *path = [[NSBundle mainbundle] Pathforresource:@"Dzs.mp4"Oftype:nil]; Mpmovieplayerviewcontroller*movieplayer =[[Mpmovieplayerviewcontroller alloc] Initwithcontenturl:[nsurl Fileurlwithpath:path]]; [Weakself presentviewcontroller:movieplayer Animated:yes Completion:^{           //        }];  }]; //Add button -to play    }#pragmaMark-Play URL video file-(void) audiourlmediousedemo{//Play network video files__weaktypeof(self) weakself =Self ; [Self.view Addsystembuttonwithframe:cgrectmake ( -, -, -, -) Title:@"Play URL file"action:^ (UIButton *button) {        //NSString *urlstring =@"Http://k.youku.com/player/getFlvPath/sid/842953390607212440d37_00/st/mp4/fileid/ 0300080400552fc1bc6e56087ac0925dedebdd-a820-cf65-a99f-02ef5d8626dd? k=d576e3f832ea0e35261e4bfe&ctype=12&ev=1&oip=1931322792&token=8474&ep= eiawe0yovcca4ypyij8byyjiihqixp4j9h%2bfidjmalshterj6j%2bjtjvfs%2flchv5oasipeu6f3qssgdrgyyflq2gqrdiuppqr9% 2fmv5a1rseyfehewcmujwfswrzf1"; Mpmovieplayerviewcontroller*movieplayer =[[Mpmovieplayerviewcontroller alloc] Initwithcontenturl:[nsurl urlwithstring:urlstring]]; [Weakself presentviewcontroller:movieplayer Animated:yes Completion:^{            //        }];  }]; //Add button -to play        /** * * * Play live File **********/    //Live URL:http://219.232.160.141: 5080/hls/c64024e7cd451ac19613345704f985fa.m3u8[Self.view Addsystembuttonwithframe:cgrectmake ( -, $, -, -) Title:@"Play Live File"action:^ (UIButton *button) {        //NSString *urlstring =@"http://219.232.160.141:5080/hls/c64024e7cd451ac19613345704f985fa.m3u8"; Mpmovieplayerviewcontroller*movieplayer =[[Mpmovieplayerviewcontroller alloc] Initwithcontenturl:[nsurl urlwithstring:urlstring]]; [Weakself presentviewcontroller:movieplayer Animated:yes Completion:^{            //        }];  }]; //Add button -to play}
Second, ipad programming
//1.ipad, the difference between iphone-size, lack of hardware (phone, SMS ...) ), adaptable, with 2 more controls//ipad-->sizeCgsize size =[UIScreen mainscreen].bounds.size; NSLog (@"%f,%f", size.width,size.height);//ipad2:768*1024//IPad air:768*1024//IPad retina:768*1024//adaptation issue: Better get an ipad version        /*2.iPad Unique Controls (2) Uisplitviewcontroller-Split View Controller---Interface transfer value-----Reverse value

Uipopovercontroller--Eject controller
*/
#import "AppDelegate.h"#import "MasterViewController.h"#import "DetailViewController.h"@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Override point for customization after application launch.Masterviewcontroller*master = [[Masterviewcontroller alloc] init];// Main ViewDetailviewcontroller *DVC =[[Detailviewcontroller alloc] init]; Uinavigationcontroller*NVC =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:DVC]; Uisplitviewcontroller*svc =[[Uisplitviewcontroller alloc] init]; Svc.viewcontrollers=@[master,nvc]; Svc.Delegate=DVC; Self.window.rootViewController=Svc; returnYES;}

Multimedia Audio Video and ipad basic use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.