播放电影文件:

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并添加

在需要使用库的地方添加下面的代码:

  1. #import <MediaPlayer/MediaPlayer.h>

本项目名为MediaPlayerTest,源码如下:

VideoPlayerViewController.h 头文件代码:

  1. #import <UIKit/UIKit.h>
  2. #import <MediaPlayer/MediaPlayer.h>
  3. @interface ViewController : UIViewController
  4. {
  5. UIButton *playBtn;
  6. MPMoviePlayerController *moviePlayer;
  7. }
  8. @property (retain, nonatomic) IBOutlet UIButton *playBtn;
  9. @property (retain, nonatomic) MPMoviePlayerController *moviePlayer;
  10. - (IBAction)playVideo:(id)sender;
  11. @end

VideoPlayerViewController.m 实现文件代码:

  1. #import "ViewController.h"
  2. #import <MediaPlayer/MediaPlayer.h>
  3. @interface ViewController ()
  4. @end
  5. @implementation ViewController
  6. @synthesize playBtn;
  7. @synthesize moviePlayer;
  8. - (void)viewDidLoad
  9. {
  10. [super viewDidLoad];
  11. self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:
  12. [NSURL URLWithString:@"http://v.youku.com/player/getRealM3U8/vid/XNTY2MTAxOTUy/type/video.m3u8"]];
  13. self.moviePlayer.movieControlMode = MPMovieControlModeDefault;
  14. [self.moviePlayer.view setFrame:CGRectMake(0, 0, 320, 380)];
  15. // Do any additional setup after loading the view, typically from a nib.
  16. }
  17. - (void)didReceiveMemoryWarning
  18. {
  19. [super didReceiveMemoryWarning];
  20. // Dispose of any resources that can be recreated.
  21. }
  22. - (IBAction)playVideo:(id)sender
  23. {
  24. NSLog(@"Into playvideo.");
  25. [self.view insertSubview:[self.moviePlayer view] atIndex:10];
  26. [self.moviePlayer play];
  27. }
  28. @end

MainStoryboard.storyboard:

将ViewController的playBtn和IB的Button关联起来

将Button的Touch Up Inside事件和View Controller的playVideo操作关联起来

运行结果:

参考:

IOS 6编程-使用MPMoviePlayerController类实现视频播放器

iOS开发之多媒体播放

简单iPhone视频播放器

IOS上MediaPlayer framework实现视频播放的更多相关文章

  1. iOS中 MediaPlayer framework实现视频播放 韩俊强的博客

    iOS开发中播放音乐可以使用MPMusicPlayerController类来实现,播放视频可以使用MPMoviePlayerController和MPMoviePlayerViewControlle ...

  2. iOS使用Security.framework进行RSA 加密解密签名和验证签名

    iOS 上 Security.framework为我们提供了安全方面相关的api: Security框架提供的RSA在iOS上使用的一些小结 支持的RSA keySize 大小有:512,768,10 ...

  3. 细数iOS上的那些安全防护

    细数iOS上的那些安全防护  龙磊,黑雪,蒸米 @阿里巴巴移动安全 0x00 序 随着苹果对iOS系统多年的研发,iOS上的安全防护机制也是越来越多,越来越复杂.这对于刚接触iOS安全的研究人员来说非 ...

  4. 微信双开是定时炸弹?关于非越狱iOS上微信分身高危插件ImgNaix的分析

    作者:蒸米@阿里移动安全 序言 微信作为手机上的第一大应用,有着上亿的用户.并且很多人都不只拥有一个微信帐号,有的微信账号是用于商业的,有的是用于私人的.可惜的是官方版的微信并不支持多开的功能,并且频 ...

  5. 关于iOS上的静态库

    最近再进行项目的真机调试,然后发现了一个天坑.就此研究了一些iOS上的静态库的使用: 首先我们是直接拿一个可以运行的项目来制作静态库的,网上大部分都是先创建静态库然后再写内容,看看我的方法. 1.把子 ...

  6. 在iOS上实现二维码功能

    http://blog.csdn.net/abcmx/article/details/8011904 如今二维码随处可见,无论是实物商品还是各种礼券都少不了二维码的身影.而手机等移动设备又成为二维码的 ...

  7. ios上position:fixed失效问题

    手机端上的猫腻真是多啊~~~ 此起彼伏! 最近又遇到了 固定定位的底部导航在ios上被弹出去 此时内心1w+个草泥马奔过~~~~~~~~ 直接上解决方案: <div class="ma ...

  8. :active 为什么在ios上失效

    :active是针对鼠标,而手机上是没有鼠标,而是touchstart,所以早成了ios上不兼容 解决方法是: window.onload = function(){ document.body.ad ...

  9. 解决protobuf不能直接在IOS上使用,利用protobuf-net在IOS上通讯

    ---------------------------------------------------------------------------------------------------- ...

随机推荐

  1. BestCoder Round #56/hdu5463 Clarke and minecraft 水题

    Clarke and minecraft 问题描述 克拉克是一名人格分裂患者.某一天,克拉克分裂成了一个游戏玩家,玩起了minecraft.渐渐地,克拉克建起了一座城堡. 有一天,克拉克为了让更多的人 ...

  2. 在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 ...

  3. SpringMVC_RESTRUL_CRUD

    编写POJO Departmet: package org.springmvc.curd.entity; public class Department { private int id; priva ...

  4. ios19---xib

    // // ViewController.m #import "ViewController.h" @interface ViewController () @end @imple ...

  5. python-----列表生成式和列表生成器表达

    列表表达式: 程序一: 常规写法: L = [] for x in range(1, 11): L.append(x * x) print(L) #[1, 4, 9, 16, 25, 36, 49, ...

  6. ModuleNotFoundError: No module named 'PIL'

    错误:ModuleNotFoundError: No module named 'PIL' 解决办法: pip install Pillow

  7. 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 ...

  8. 通过CSS控制页面中的内容垂直居中的方法

    方法一:通过行高(line-height)定位 line-height通常是用于调节一段文字的行与行之间的距离,或者说两行文字之间的距离,如果行高是500px,那么每一行中的文字距离本行的顶部就是25 ...

  9. IE6的3像素BUG产生条件及解决方法

    1.IE6中第一个元素浮动第二个元素不浮动,这两个元素之间就会产生3像素BUG 2.解决方案: 2.1若若宽度一定则给第二个元素添加 float 样式即可: 2.2若宽度自适应: 2.2.1  _ma ...

  10. E20180124-hm

    introspection n.自我反省; 反省,内省; capacity n. 容量; 性能; 才能; 生产能力; synthesize vt. 综合; 人工合成; (通过化学手段或生物过程) 合成 ...