方法一:

@property (nonatomic, strong) MPMoviePlayerController *player;

    NSString *url = [[NSBundle mainBundle] pathForResource:@"zz_video" ofType:@"mp4"];
self.player = [[MPMoviePlayerController alloc]
initWithContentURL: [NSURL fileURLWithPath:url]];
self.player.controlStyle = MPMovieControlStyleNone;
self.player.view.frame = self.view.frame;
[self.view addSubview:self.player.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.player]; [self.player play]; //开始播放
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player stop];
}

方法二:

1、要使用MPMoviePlayerViewController首先要加入MediaPlayer.framework. 
2、加入如下代码:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
NSString *url = [[NSBundle mainBundle] pathForResource:@"TaylorSwift-LoveStory" ofType:@"mp4"]; MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
//-- add to view---
[self.view addSubview:playerViewController.view]; //---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play]; } - (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player stop];
[self.view removeFromSuperView];
[player autorelease];
}

3、支持横屏修改shouldAutorotateToInterfaceOrientation:interfaceOrientation方法使其返回YES。

备注:实测 用上面的方法直接播放本地m3u8格式或者线上的视频也是可以的。

NSURL可直接初始化:

NSURL*videoPathURL=[NSURL URLWithString:urlStr];//urlStr是视频播放地址

如果是播放本地视频的话。这样初始化:

NSURL*videoPathURL=[[NSURL alloc] initFileURLWithPath:urlStr];

转:http://re-reference.iteye.com/blog/1106324

利用MPMoviePlayerViewController 播放视频 iOS的更多相关文章

  1. iOS开发--利用MPMoviePlayerViewController播放视频简单实现

    一.MPMoviePlayerViewController和MPMoviePlayerController区分开,前者继承自NSObject,后者继承自UIViewController 二.MPMov ...

  2. iOS开发--利用MPMoviePlayerController播放视频简单实现

    一.包含头文件#import <MediaPlayer/MediaPlayer.h> 二.重点:给MPMoviePlayerController的view设置frame,并且将view添加 ...

  3. 播放视频 IOS 与安卓的不同

    安卓:video IOS:canvas 具体原因请见上传文件“宝马视频安卓与IOS的区别”

  4. SDL的基础知识以及利用SDL播放视频

    原文地址:http://blog.csdn.net/i_scream_/article/details/52714378 此博文相关知识点从雷神的博客以及视频学习,截图也是用了他的课件, 雷神博客地址 ...

  5. 利用VideoView播放视频

    package com.qianhua.ui; 002   003 import android.app.Activity; 004 import android.content.Intent; 00 ...

  6. 在iOS开发中如何播放视频

     技术博客http://www.cnblogs.com/ChenYilong/  新浪微博http://weibo.com/luohanchenyilong  如何播放视频 •iOS提供了叫做MPMo ...

  7. Unity3D基础学习 利用NGUI的Texture播放视频

    利用NGUI播放视频,首先你得导入你的视频 你的电脑中必须安装QuickTime软件,没有,去下一个,如果是Windows系统,安装完之后重启. 接下来转换你的视频格式,如果你的视频在QuickTim ...

  8. IOS 播放视频(MPMoviePlayerController、MPMoviePlayerViewController)

    ● iOS提供了叫 做MPMoviePlayerController.MPMoviePlayerViewController的两个 类,可以用来轻松播放视频 ➢ YouTobe就是用MPMoviePl ...

  9. iOS开发-- 利用AVPlayer播放远程音乐和视频

    一.简单的播放音乐和视频,播放视频的工具栏需要自己写 二.利用老师封装的框架实现视频播放 链接:http://pan.baidu.com/s/1hrEKlus 密码:8e7g

随机推荐

  1. mysql 字符编码设置

    安装mysql时如果字符编码为默认值latin1,则需要修改为utf8以便支持中文数据. 命令如下: 1.显示数据库字符集 mysql> show create database test;+- ...

  2. Linux:安装mysql

    #install mysql$ rpm -ivh MySQL-client-5.5.28-1.rhel5.x86_64.rpm --nodeps$ rpm -ivh MySQL-server-5.5. ...

  3. android调节声音大小

    android调节声音大小 1.背景音乐的一些知识 网上好多关于背景音乐添加用到的类: MediaPlayer,SoundPool,AudioManager的资料,可是有时候解决不了我们在开发中遇到的 ...

  4. 前后端分离之mockjs实战demo

    基于vue-cli+webpack的demo 项目结构 axios文件夹用来创建axios相关配置: import axios from 'axios' import vue from 'vue' a ...

  5. 线上SQL优化

    最近在线上发现很多性能有问题的sql,开发写sql语句的时候,没充分考虑是否用上索引了,所以这个坑得DBA来填,好了,废话不多说,把一些线上的优化经验跟大家分享. 由于是线上的表,所以就不公开具体的表 ...

  6. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配

    因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #de ...

  7. hadoop2.6.4的HA集群搭建超详细步骤

    hadoop2.0已经发布了稳定版本了,增加了很多特性,比如HDFS HA.YARN等.最新的hadoop-2.6.4又增加了YARN HA 注意:apache提供的hadoop-2.6.4的安装包是 ...

  8. 家庭房产L2-007

    较为麻烦的并查集 主要是我的模板是错的检查了好久.... 先是输入 把每个家庭连在一起 输出的家庭编号为该家庭所有编号的最小值  在并查集里面完成 第一次 0~n-1遍历储存好 家庭编号 和房子面积和 ...

  9. 007.LVM查看命令

    一 PV查看 [root@kauai ~]# pvdisplay #显示有关物理卷的信息 --- Physical volume --- PV Name /dev/sdb5 #PV名称 VG Name ...

  10. 循序渐进学.Net Core Web Api开发系列【15】:应用安全

    系列目录 循序渐进学.Net Core Web Api开发系列目录 本系列涉及到的源码下载地址:https://github.com/seabluescn/Blog_WebApi 一.概述 本篇介绍W ...