IOS上MediaPlayer framework实现视频播放
播放电影文件:
iOS sdk中可以使用MPMoviePlayerController来播放电影文件。但是在iOS设备上播放电影文件有严格的格式要求,只能播放下面两个格式的电影文件。
• H.264 (Baseline Profile Level 3.0)
• MPEG-4 Part 2 video (Simple Profile)
MPMoviePlayerController可以播放本地视频文件,也可以播放互联网上的视频文件。
首先在项目中需要引入Media Player 框架
项目-->Targets-->Build Phases-->Link Binary With Libraries
点击左下角的+号

找到MediaPlayer.framework并添加

在需要使用库的地方添加下面的代码:
- #import <MediaPlayer/MediaPlayer.h>
本项目名为MediaPlayerTest,源码如下:
VideoPlayerViewController.h 头文件代码:
- #import <UIKit/UIKit.h>
- #import <MediaPlayer/MediaPlayer.h>
- @interface ViewController : UIViewController
- {
- UIButton *playBtn;
- MPMoviePlayerController *moviePlayer;
- }
- @property (retain, nonatomic) IBOutlet UIButton *playBtn;
- @property (retain, nonatomic) MPMoviePlayerController *moviePlayer;
- - (IBAction)playVideo:(id)sender;
- @end
VideoPlayerViewController.m 实现文件代码:
- #import "ViewController.h"
- #import <MediaPlayer/MediaPlayer.h>
- @interface ViewController ()
- @end
- @implementation ViewController
- @synthesize playBtn;
- @synthesize moviePlayer;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:
- [NSURL URLWithString:@"http://v.youku.com/player/getRealM3U8/vid/XNTY2MTAxOTUy/type/video.m3u8"]];
- self.moviePlayer.movieControlMode = MPMovieControlModeDefault;
- [self.moviePlayer.view setFrame:CGRectMake(0, 0, 320, 380)];
- // Do any additional setup after loading the view, typically from a nib.
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)playVideo:(id)sender
- {
- NSLog(@"Into playvideo.");
- [self.view insertSubview:[self.moviePlayer view] atIndex:10];
- [self.moviePlayer play];
- }
- @end
MainStoryboard.storyboard:
将ViewController的playBtn和IB的Button关联起来
将Button的Touch Up Inside事件和View Controller的playVideo操作关联起来
运行结果:
参考:
IOS 6编程-使用MPMoviePlayerController类实现视频播放器
IOS上MediaPlayer framework实现视频播放的更多相关文章
- iOS中 MediaPlayer framework实现视频播放 韩俊强的博客
iOS开发中播放音乐可以使用MPMusicPlayerController类来实现,播放视频可以使用MPMoviePlayerController和MPMoviePlayerViewControlle ...
- iOS使用Security.framework进行RSA 加密解密签名和验证签名
iOS 上 Security.framework为我们提供了安全方面相关的api: Security框架提供的RSA在iOS上使用的一些小结 支持的RSA keySize 大小有:512,768,10 ...
- 细数iOS上的那些安全防护
细数iOS上的那些安全防护 龙磊,黑雪,蒸米 @阿里巴巴移动安全 0x00 序 随着苹果对iOS系统多年的研发,iOS上的安全防护机制也是越来越多,越来越复杂.这对于刚接触iOS安全的研究人员来说非 ...
- 微信双开是定时炸弹?关于非越狱iOS上微信分身高危插件ImgNaix的分析
作者:蒸米@阿里移动安全 序言 微信作为手机上的第一大应用,有着上亿的用户.并且很多人都不只拥有一个微信帐号,有的微信账号是用于商业的,有的是用于私人的.可惜的是官方版的微信并不支持多开的功能,并且频 ...
- 关于iOS上的静态库
最近再进行项目的真机调试,然后发现了一个天坑.就此研究了一些iOS上的静态库的使用: 首先我们是直接拿一个可以运行的项目来制作静态库的,网上大部分都是先创建静态库然后再写内容,看看我的方法. 1.把子 ...
- 在iOS上实现二维码功能
http://blog.csdn.net/abcmx/article/details/8011904 如今二维码随处可见,无论是实物商品还是各种礼券都少不了二维码的身影.而手机等移动设备又成为二维码的 ...
- ios上position:fixed失效问题
手机端上的猫腻真是多啊~~~ 此起彼伏! 最近又遇到了 固定定位的底部导航在ios上被弹出去 此时内心1w+个草泥马奔过~~~~~~~~ 直接上解决方案: <div class="ma ...
- :active 为什么在ios上失效
:active是针对鼠标,而手机上是没有鼠标,而是touchstart,所以早成了ios上不兼容 解决方法是: window.onload = function(){ document.body.ad ...
- 解决protobuf不能直接在IOS上使用,利用protobuf-net在IOS上通讯
---------------------------------------------------------------------------------------------------- ...
随机推荐
- BestCoder Round #56/hdu5463 Clarke and minecraft 水题
Clarke and minecraft 问题描述 克拉克是一名人格分裂患者.某一天,克拉克分裂成了一个游戏玩家,玩起了minecraft.渐渐地,克拉克建起了一座城堡. 有一天,克拉克为了让更多的人 ...
- 在Ubuntu 12.04 LTS下成功访问Windows域共享(mount //192.168.1.102/share -o user=DOMIAN\\user,pass=passwd /mnt)
Ubuntu 12.04 LTS下成功访问Windows域共享: 1,在命令行模式下 mount //192.168.1.102/share -o user=DOMIAN\\user,pass=pas ...
- SpringMVC_RESTRUL_CRUD
编写POJO Departmet: package org.springmvc.curd.entity; public class Department { private int id; priva ...
- ios19---xib
// // ViewController.m #import "ViewController.h" @interface ViewController () @end @imple ...
- python-----列表生成式和列表生成器表达
列表表达式: 程序一: 常规写法: L = [] for x in range(1, 11): L.append(x * x) print(L) #[1, 4, 9, 16, 25, 36, 49, ...
- ModuleNotFoundError: No module named 'PIL'
错误:ModuleNotFoundError: No module named 'PIL' 解决办法: pip install Pillow
- bzoj2060
树形dp dp[x][0]表示x点父亲没选,dp[x][1]表示x点父亲选了,然后dp[x][0]=max(sigma(dp[c[x]][0]),sigma(dp[c[x]][1])) dp[x][1 ...
- 通过CSS控制页面中的内容垂直居中的方法
方法一:通过行高(line-height)定位 line-height通常是用于调节一段文字的行与行之间的距离,或者说两行文字之间的距离,如果行高是500px,那么每一行中的文字距离本行的顶部就是25 ...
- IE6的3像素BUG产生条件及解决方法
1.IE6中第一个元素浮动第二个元素不浮动,这两个元素之间就会产生3像素BUG 2.解决方案: 2.1若若宽度一定则给第二个元素添加 float 样式即可: 2.2若宽度自适应: 2.2.1 _ma ...
- E20180124-hm
introspection n.自我反省; 反省,内省; capacity n. 容量; 性能; 才能; 生产能力; synthesize vt. 综合; 人工合成; (通过化学手段或生物过程) 合成 ...