您的位置:首页 > 产品设计 > 产品经理

MPMoviePlayerController  …

2013-08-19 18:22 281 查看
原文地址:MPMoviePlayerController  网络视频加载作者:huifeng3213Iphone中已经自定义好了视频播放类MPMoviePlayerController,我们只需调用既可,我自己封装好了一个视频播放类,下面就直接给大家上代码吧。

#import <UIKit/UIKit.h>

#import
<MediaPlayer/MediaPlayer.h>     
//导入视频播放库

@interface CustomMoviePlayerViewController : UIViewController

{

   
MPMoviePlayerController *mp;

    NSURL
*movieURL;   
   
   
   
   
    //视频地址

   
UIActivityIndicatorView
*loadingAni;   
//加载动画

    UILabel
*label;   
   
   
   
   
   
    //加载提醒

}

@property (nonatomic,retain) NSURL *movieURL;

//准备播放

- (void)readyPlayer;

@end

#import "CustomMoviePlayerViewController.h"

#pragma mark -

#pragma mark Compiler Directives & Static
Variables

@implementation CustomMoviePlayerViewController

@synthesize movieURL;

- (void)viewDidLoad

{

    [super
viewDidLoad];

   

    loadingAni =
[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(140, 150,
37, 37)];

   
loadingAni.activityIndicatorViewStyle =
UIActivityIndicatorViewStyleWhiteLarge;   

    [self.view
addSubview:loadingAni];

   

    label =
[[UILabel alloc] initWithFrame:CGRectMake(130, 190, 80, 40)];

    label.text =
@"加载中...";

   
label.textColor = [UIColor whiteColor];

   
label.backgroundColor = [UIColor clearColor];

   

    [[self view]
setBackgroundColor:[UIColor blackColor]];

   

    [loadingAni
startAnimating];

    [self.view
addSubview:label];

}

- (void)
moviePlayerLoadStateChanged:(NSNotification*)notification

{

    [loadingAni
stopAnimating];

    [label
removeFromSuperview];

   

    // Unless
state is unknown, start playback

    if ([mp
loadState] != MPMovieLoadStateUnknown)

    {

   
    // Remove
observer

   
   
[[NSNotificationCenter
   
defaultCenter] removeObserver:self

   
   
   
   
   
   
   
   
   
   
   
   
   
 name:MPMoviePlayerLoadStateDidChangeNotification

   
   
   
   
   
   
   
   
   
   
   
   
   
object:nil];

   
    // When
tapping movie, status bar will appear, it shows up

   
    // in
portrait mode by default. Set orientation to landscape

   
    //设置横屏

   
   
[[UIApplication sharedApplication]
setStatusBarOrientation:UIInterfaceOrientationLa
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: