MPMoviePlayerViewController实现横屏播放
2012-05-21 16:00
423 查看
phonegap 视频插件:https://github.com/eiffelqiu/phonegap-videoplayer-plugin
此插件默认只能设置横屏(NO)/坚屏(YES),要弄成自动适应:(将相关内容注释掉)
实现播放视频的时候自动横屏必须重写MPMoviePlayerViewController,具体代码如下:
1.重写MPMoviePlayerViewController
Java代码
//
// DirectionMPMoviePlayerViewController.h
// Direction
//
// Created by apple on 12-4-10.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <MediaPlayer/MediaPlayer.h>
@interface DirectionMPMoviePlayerViewController : MPMoviePlayerViewController
@end
Java代码
//
// DirectionMPMoviePlayerViewController.m
// Direction
//
// Created by apple on 12-4-10.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "DirectionMPMoviePlayerViewController.h"
@implementation DirectionMPMoviePlayerViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIDeviceOrientationIsLandscape(interfaceOrientation);
}
@end
2.初始化播放器,播放
Java代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self customTitleView];
NSString *mystr = @"http://114.112.50.220:8080/res/20120331/2FFCE63A-C997-4D8C-4C4F-4127D78A958E.m3u8";
NSURL *myURL = [[NSURL alloc] initWithString:mystr];
[self playMovieAtURL:myURL];
}
-(void)playMovieAtURL:(NSURL*)theURL
{
playerView = [[DirectionMPMoviePlayerViewController alloc] initWithContentURL:theURL];
playerView.view.frame = self.view.frame;//全屏播放(全屏播放不可缺)
playerView.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;//全屏播放(全屏播放不可缺)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerView];
[playerView.moviePlayer play];
[self presentMoviePlayerViewControllerAnimated:playerView];
}
// When the movie is done, release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
DirectionMPMoviePlayerViewController* theMovie = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie release];
}
此插件默认只能设置横屏(NO)/坚屏(YES),要弄成自动适应:(将相关内容注释掉)
实现播放视频的时候自动横屏必须重写MPMoviePlayerViewController,具体代码如下:
1.重写MPMoviePlayerViewController
Java代码
//
// DirectionMPMoviePlayerViewController.h
// Direction
//
// Created by apple on 12-4-10.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <MediaPlayer/MediaPlayer.h>
@interface DirectionMPMoviePlayerViewController : MPMoviePlayerViewController
@end
Java代码
//
// DirectionMPMoviePlayerViewController.m
// Direction
//
// Created by apple on 12-4-10.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "DirectionMPMoviePlayerViewController.h"
@implementation DirectionMPMoviePlayerViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIDeviceOrientationIsLandscape(interfaceOrientation);
}
@end
2.初始化播放器,播放
Java代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self customTitleView];
NSString *mystr = @"http://114.112.50.220:8080/res/20120331/2FFCE63A-C997-4D8C-4C4F-4127D78A958E.m3u8";
NSURL *myURL = [[NSURL alloc] initWithString:mystr];
[self playMovieAtURL:myURL];
}
-(void)playMovieAtURL:(NSURL*)theURL
{
playerView = [[DirectionMPMoviePlayerViewController alloc] initWithContentURL:theURL];
playerView.view.frame = self.view.frame;//全屏播放(全屏播放不可缺)
playerView.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;//全屏播放(全屏播放不可缺)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerView];
[playerView.moviePlayer play];
[self presentMoviePlayerViewControllerAnimated:playerView];
}
// When the movie is done, release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
DirectionMPMoviePlayerViewController* theMovie = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie release];
}
相关文章推荐
- MPMoviePlayerViewControllerIOS6下实现横屏播放
- MPMoviePlayerViewController实现横屏播放
- MPMoviePlayerViewController的自动横屏播放
- [基础]MPMoviePlayerViewController实现MP4播放
- iOS开发--利用MPMoviePlayerViewController播放视频简单实现
- MPMoviePlayerViewController播放视频横屏播放
- 利用MPMoviePlayerViewController实现简单的mp4播放
- MPMoviePlayerViewController播放在线视频
- IOS7 MPMoviePlayerViewController横屏显示
- 使用MPMoviePlayerViewController播放视频
- ios MPMoviePlayerViewController播放结束时的回调方法
- 使用MPMoviePlayerViewController播放视频
- MPMoviePlayerViewController视频播放
- MPMoviePlayerViewController播放本地视频一直Loading问题
- Swift3 MPMoviePlayerViewController的使用,iOS播放视频
- MPMoviePlayerViewController的使用方法和横屏显示
- 使用封装号的MPMoviePlayerViewController播放MP4视频
- 用 MPMoviePlayerController 实现简单的视频下载播放功能
- kidd风的IOS日志之播放音乐(MPMoviePlayerViewController和MPMoviePlayerController)
- MPMoviePlayerViewController 播放本地视频一直loading