#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface View24 : UIViewController
{
//sdk3.2以后
MPMoviePlayerViewController *_moviePlayViewController;
//sdk3.2以前
MPMoviePlayerController *_moviePlayerController;
}
//远程视频事件
- (IBAction) playURLVideo;
//本地视频事件
- (IBAction) playFileVideo;
@property (nonatomic,retain) MPMoviePlayerViewController *_moviePlayViewController;
@property (nonatomic,retain) MPMoviePlayerController *_moviePlayerController;
-(void) initAndPlay:(NSString *)videoURL;
@end
//本地视频事件
-(IBAction) playFileVideo
{//此方法只是 3。2以后的方法
NSString*path=[[NSBundle mainBundle] pathForResource:@"sophie" ofType:@"mov"];
NSURL*url=[[NSURL alloc] initFileURLWithPath:path];
MPMoviePlayerViewController* tmpMoviePlayViewController=[[MPMoviePlayerViewController alloc]initWithContentURL:url];
if (tmpMoviePlayViewController)
{
self._moviePlayViewController=tmpMoviePlayViewController;
[self presentMoviePlayerViewControllerAnimated:_moviePlayViewController];
_moviePlayViewController.moviePlayer.movieSourceType =MPMovieSourceTypeFile;
[_moviePlayViewController.moviePlayerplay];
}
[tmpMoviePlayViewController release];
[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(playbackDidFinish)name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
//远程视频事件
- (IBAction) playURLVideo
{
NSString*videoPath =@"http://www.subfurther.com/video/running-start-iphone.m4v";
if (videoPath == NULL)
return;
[selfinitAndPlay:videoPath];
}
-(void) initAndPlay:(NSString *)videoURL
{
if([videoURL rangeOfString:@"http://"].location!=NSNotFound||[videoURL rangeOfString:@"https://"].location!=NSNotFound)
{
NSURL *URL = [[NSURLalloc] initWithString:videoURL];
if (URL) {
if([[[UIDevice currentDevice] systemVersion] doubleValue] >=3.2)
{//3。2以后
MPMoviePlayerViewController* tmpMoviePlayViewController=[[MPMoviePlayerViewController alloc]initWithContentURL:URL];
if (tmpMoviePlayViewController)
{
self._moviePlayViewController=tmpMoviePlayViewController;
[self presentMoviePlayerViewControllerAnimated:_moviePlayViewController];
_moviePlayViewController.moviePlayer.movieSourceType =MPMovieSourceTypeFile;
[_moviePlayViewController.moviePlayerplay];
}
[tmpMoviePlayViewController release];
}
elseif([[[UIDevice currentDevice] systemVersion] doubleValue] <3.2)
{//3。2以前
MPMoviePlayerController* tmpMoviePlayController=[[MPMoviePlayerController alloc]initWithContentURL:URL];
if (tmpMoviePlayController)
{
self._moviePlayerController=tmpMoviePlayController;
[_moviePlayerController play];
}
[tmpMoviePlayController release];
}
//视频播放完成通知
[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(playbackDidFinish)name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
[URL release];
}
}
//视频播放完成后事件
- (void) playbackDidFinish
{
[[NSNotificationCenter defaultCenter]removeObserver:selfname:MPMoviePlayerPlaybackDidFinishNotification object:nil];
if(_moviePlayViewController)
{
[self dismissMoviePlayerViewControllerAnimated];
[self._moviePlayViewController.moviePlayerstop];
_moviePlayViewController.moviePlayer.initialPlaybackTime=-1.0;
[_moviePlayViewController release];
_moviePlayViewController=nil;
}
if(_moviePlayerController)
{
[self._moviePlayerController stop];
_moviePlayerController.initialPlaybackTime= -1.0;
[_moviePlayerController release];
_moviePlayerController =nil;
}
}
详细解决方案
iphone之MPMoviePlayer 视频播发(转载 3.2之前与3.3之前)
热度:98 发布时间:2016-04-25 06:29:12.0
相关解决方案
- iphone 模拟器,该如何处理
- c#c++,android,ios(iphone),php,java视屏课程 散分
- 有哪位高手用过JPlayer ,进来一下,IPHONE 等设备播放有关问题
- 单个人去做手机开发选什么平台好?android,iphone?解决办法
- iphone app拖进iTunes生成ipa包出现embedded.mobileprovision异常
- 对于手机android iphone ipad 在线播放视频,服务器需要哪些要求呢?该怎么解决
- >>> PayPal mobile for Android / iPhone 开发包 开放啦!
- OPhone Vs iphone, 作为开发者的我们将何去和从?
- HTML,CSS,Javascript in iPhone (转从 koubei F2E 善朋)
- iphone + html5是个美模式
- 共享两个日前手机项目的HTML5的widget,星星评级以及标签选项卡,样式美观,iphone/android可用
- ipad 和 iphone 上的有关问题
- iPhone 筹建PHP版Push服务器 实例操作
- iphone/ipod网页开发课程及规则
- iphone UIWebView 的运用
- iPhone运用:JSF2 Tag Reference,offline view by iPhone
- iphone 获取UIWebView内Html步骤
- iphone Web App 领航设计探讨
- iPhone Safari Web开发心得
- iPhone Android Web开发(要略)
- JS 判断浏览器客户端门类(ipad,iphone,android)
- iphone ipad android手机访问wcf service出现中文乱码(!)
- iPhone SE销量惨淡?见见这些数据就知道了
- 一九七零年// iPhone “变砖”后可继续正常使用的解决方案
- iPhone 6S 有苹果不愿意讨论的有关问题
- iphone 浏览器自动解析数字为号码解决方法
- 怎么禁止 iPhone Safari video标签视频自动全屏
- iPhone 六的自适应布局
- 腾挪端实现 iphone android 小图标 文字排版
- iPhone:动态获取UILabel的高度跟宽度