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];
}