IOS audio and video development, IOS audio and video Development

Source: Internet
Author: User

IOS audio and video development, IOS audio and video Development

Simple usage of Audio and Video:

When using audio, You need to import # import <AVFoundation/AVFoundation. h>


@ Interface ViewController ()

{

 

AVPlayer * player;

}

@ End


@ Implementation ViewController


-(Void) viewDidLoad {

[Super viewDidLoad];


Note: AVPlayer must define a global variable. If it is not defined as a global variable, the variable is released with parentheses.

NSURL * url = [NSURL URLWithString: @ "http://bcs.duapp.com/chenwei520/media/music.mp3"];

Player = [[AVPlayer alloc] initWithURL: url];


[Player play]; start playing


[Player stop]; stop playing


[Player pause]; pause playing


}


When using videos, you need to import # import <MediaPlayer/MediaPlayer. h>

Note: MPMoviePlayerController also needs to define global variables. If it is not defined as a global variable, it will be released out of brackets.


@ Interface ViewController ()

{

MPMoviePlayerController * moviePlayer;


}


@ End


@ Implementation ViewController


-(Void) viewDidLoad {

[Super viewDidLoad];


NSString * mp4 = @ "http://bcs.duapp.com/chenwei520/media/mobile_vedio.mp4 ";

NSURL * url = [NSURL URLWithString: mp4];


MoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: url];

MoviePlayer. view. frame = self. view. bounds;

MoviePlayer. view. backgroundColor = [UIColor grayColor];

[MoviePlayer play];

[Self. view addSubview: moviePlayer. view];

}






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.