美文网首页
2.5 AVPlayer音频播放

2.5 AVPlayer音频播放

作者: 草根小强 | 来源:发表于2019-04-08 17:00 被阅读0次

AVPlayer

#import "ViewController.h"

#import <AVFoundation/AVFoundation.h>

@interface ViewController ()
{
    AVPlayer *player;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self aboutMedia];
}

- (void)aboutMedia {
    
    // 音频播放,需要导入一个系统库 <AVFoundation/AVFoundation.h>
    // AVPlayer 只能播放本地的文件
    // 通过一个本地的文件进行实例化
    // URL表示本地音频文件的路径
    // 1. 获取音频资源的路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"todo mundo 2014巴西世界杯主题曲 8093948" ofType:@"mp3"];
    // 2. 把这个路径转成NSURL
    // 把一个本地文件的路径转成NSURL
    NSURL *url = [NSURL fileURLWithPath:path];
    
    player = [[AVPlayer alloc] initWithURL:url];
    
    // 预播放(可选)
    
    // [player ];

    // 播放
    [player play];
}

相关文章

网友评论

      本文标题:2.5 AVPlayer音频播放

      本文链接:https://www.haomeiwen.com/subject/srspiqtx.html