IOS開發音頻與視頻,IOS開發音頻視頻
音頻與視頻的簡單用法:
使用音訊時候需要匯入#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
{
AVPlayer *player;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
注意:AVPlayer需要定義全域變數,如果不定義為全域變數的話,出了括弧,它就被釋放掉了
NSURL *url = [NSURL URLWithString:@"http://bcs.duapp.com/chenwei520/media/music.mp3"];
player = [[AVPlayer alloc] initWithURL:url];
[player play]; 開始播放
[player stop]; 停止播放
[player pause]; 暫停播放
}
使用視頻的時候需要匯入#import <MediaPlayer/MediaPlayer.h>
注意:MPMoviePlayerController也需要定義全域變數,如果不定義為全域變數的話,出了括弧,它就被釋放掉了
@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];
}