IOS开发音频与视频

来源:互联网 发布:手机淘宝店标尺寸 编辑:程序博客网 时间:2024/05/17 01:39

音频与视频的简单用法:

使用音频的时候需要导入#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];

     

}






0 0
原创粉丝点击