iOS 调用音乐播放以及视频播放器
音乐播放
NSString *path = [[NSBundle
mainBundle] pathForResource:@"预谋"
ofType:@"mp3"];
if (path) {
NSURL *url = [NSURL
fileURLWithPath:path];
player= [[AVAudioPlayer
alloc]initWithContentsOfURL:url
error:nil];
[player
setDelegate:self];
player.volume =
;
player.pan =
;
;
if ([player
prepareToPlay]) {
NSLog(@"prepareToPlay:%@",path);
[player
play];
}
else {
NSLog(@"no prepareToPlay");
}
//[player release];
}
一定要注意player的引用,假设直接在函数内部申请一个暂时变量。那么这个player会在函数运行完毕,运行release 会被释放掉,假设须要在函数内部使用。那么请sleep下。只是这样会阻塞主线程的运作
视频播放器
NSURL * movieurl = [NSURL
URLWithString:@"http://v.youku.com/player/getRealM3U8/vid/XNDUwNjc4MzA4/type/video.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController
alloc] initWithContentURL:movieurl];
[self
presentMoviePlayerViewControllerAnimated:player];
最新文章
- iOS设计模式
- varsh4.1 安装清除cache
- C++ 类、构造析构、深拷贝
- C# 多线程详解 Part.03 (定时器)
- java中的异常机制(编译时异常)
- CentOS7.4 chrony时间同步服务器部署(替代NTPD)
- linkin大话数据结构--Set
- iterator和for of 循环
- matplotlib正弦和余弦图
- 基本的java加密算法MD5等等
- rapid7/metasploitable3 CTF摘要
- luogu P2144 [FJOI2007]轮状病毒
- Scala进阶之路-idea下进行spark编程
- Qt简单项目--加法计算器(详细代码注释)
- C#怎么通过一个按钮Button,实现点击这个按钮可以打开一个文件或者文件夹?
- try except else
- 20145122 《Java程序设计》第十周学习总结
- 好久没做.Net开发了,今天配置IIS和.Net Framework 4.0遇到点问题
- [006] largest_common_substring
- rcnn ->;fast rcnn->;faster rcnn物体检测论文