MPMoviePlayerViewController
MPMoviePlayerViewController
注意:需要添加MediaPlayer.framework
带有视频播放器的控制器(能够播放mp3、mp4、avi、mov格式的视频,支持本地和远程视频的播放)
实例化方法
- (instancetype)initWithContentURL:(NSURL *)contentURL
MPMoviePlayerViewController:
打开网络视频:
-(void)openmovie
{
MPMoviePlayerViewController *movie = [[MPMoviePlayerViewControlleralloc]initWithContentURL:[NSURLURLWithString:@视频网络地址]];
[movie.moviePlayer prepareToPlay];
[self presentMoviePlayerViewControllerAnimated:movie];
[movie.moviePlayersetControlStyle:MPMovieControlStyleFullscreen];
[movie.viewsetBackgroundColor:[UIColorclearColor]];
[movie.view setFrame:self.view.bounds];
[[NSNotificationCenterdefaultCenter]addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie.moviePlayer];
}
-(void)movieFinishedCallback:(NSNotification*)notify{
// 视频播放完或者在presentMoviePlayerViewControllerAnimated下的Done按钮被点击响应的通知。
MPMoviePlayerController* theMovie = [notifyobject];
[[NSNotificationCenterdefaultCenter]removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[selfdismissMoviePlayerViewControllerAnimated];
}
打开本地视频:
-(void)openmovie
{
NSString *url = [[NSBundlemainBundle]pathForResource:@IMG_0322ofType:@mp4];
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewControlleralloc]initWithContentURL:[NSURLfileURLWithPath:url]];
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewControllermoviePlayer]];
[self.view addSubview:playerViewController.view];
MPMoviePlayerController *player = [playerViewControllermoviePlayer];
[playerplay];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotificationobject];
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:MPMoviePlayerPlaybackDidFinishNotificationobject:player];
[playerstop];
[player.viewremoveFromSuperview];
}
如果对你有帮助,请关注我哦!
MPMoviePlayerViewController的更多相关文章
- iOS开发--利用MPMoviePlayerViewController播放视频简单实现
一.MPMoviePlayerViewController和MPMoviePlayerController区分开,前者继承自NSObject,后者继承自UIViewController 二.MPMov ...
- MPMoviePlayerViewController的使用 (不直接将播放器放到主视图控制器,而是放到一个内部模态视图控制器中)
其实MPMoviePlayerController如果不作为嵌入视频来播放(例如在新闻中嵌入一个视频),通常在播放时都是占满一个屏幕的,特别是在 iPhone.iTouch上.因此从iOS3.2以后苹 ...
- 【转】IOS7 MPMoviePlayerViewController横屏显示
在应用程序中用到MPMoviePlayerViewController时,有时需要保持应用程序为竖屏状态,而视频播放器显示为横屏,如何做呢?如果采用强制横屏的方法,应用审核的时候是不会通过的,因为该方 ...
- 利用MPMoviePlayerViewController 播放视频 iOS
方法一: @property (nonatomic, strong) MPMoviePlayerController *player; NSString *url = [[NSBundle mainB ...
- MPMoviePlayerViewController 视频播放黑屏
MPMoviePlayerViewController 视频播放黑屏 今天用视频做本地视频播放:使用 MPMoviePlayerViewController 老是出现黑屏: 结果发现是一个 很坑爹的问 ...
- MPMoviePlayerViewController不能播放本地mp4的解决办法.
之前一直用MPMoviePlayerViewController进行网络播放,最近下载文件然后本地播放,发现怎么播放都是黑屏.后来发现MPMoviePlayerViewController的本地URL ...
- IOS 播放视频(MPMoviePlayerController、MPMoviePlayerViewController)
● iOS提供了叫 做MPMoviePlayerController.MPMoviePlayerViewController的两个 类,可以用来轻松播放视频 ➢ YouTobe就是用MPMoviePl ...
- MPMoviePlayerViewController和MPMoviePlayerController的使用
ios播放视频文件一般使用 MPMoviePlayerViewController 和 MPMoviePlayerController.前者是一个view,后者是个Controller.差别就是MPM ...
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
--iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制, ...
随机推荐
- [转].net core 通过ViewComponent封装控件 左侧菜单
本文转自:http://www.cnblogs.com/BenDan2002/p/6224816.html 我们在.net core中还使用了ViewComponent方式生成控件.ViewCompo ...
- Jquery-UI使用
=创建form对话框弹出登录 首先引入css样式和js. <link rel="stylesheet" href="<%=path%>/css/demo ...
- pcl曲面重建模块-poisson重建算法示例
poisson曲面重建算法 pcl-1.8测试通过 #include <iostream> #include <pcl/common/common.h> #include &l ...
- Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets. Not ...
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径
Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...
- [LeetCode] Median of Two Sorted Arrays 两个有序数组的中位数
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- NCspider项目总结
下午就要答辩了,想把项目经历再总结一下. 项目分三个阶段. 第一阶段,是信息搜集整理阶段 要想法设法从各个门户网站上抓取到新闻和对应的评论数据.首先要分析网站结构. 1. 从哪里找到网站每日发布的所有 ...
- CentOS安装Redis详细教程
构建 Redis redis 目前没有官方 RPM 安装包,我们需要从源代码编译,而为了要编译就需要安装 Make 和 GCC. 如果没有安装过 GCC 和 Make,那么就使用 yum 安装. yu ...
- 推公式hdu2298
(0,0)点到(x,y)以v射箭 问 最小的角度 不能射到 -1 x=v*cos(a)*t; y=v*sin(a)*t-0.5*g*t*t; 消去t; y=x*tan(a)-0.5*g*x*x/(v* ...