zoukankan      html  css  js  c++  java
  • MPMoviePlayerViewController和MPMoviePlayerController的使用

    ios播放视频文件一般使用 MPMoviePlayerViewController 和 MPMoviePlayerController。前者是一个view,后者是个Controller。差别就是MPMoviePlayerViewController里面包括了一个MPMoviePlayerController

    先说MPMoviePlayerController

    首先要包括 #import <MediaPlayer/MediaPlayer.h>头文件和MediaPlayer.framework。

     - (void)createMPPlayerController:(NSString *)sFileNamePath {

      NSURL *movieURL = [NSURL fileURLWithPath:sFileNamePath];

     MPMoviePlayerController *movewController =[[MPMoviePlayerController alloc] initWithContentURL:movieURL];

     [movewController prepareToPlay];

     [self.view addSubview:movewController.view];//设置写在加入之后   // 这里是addSubView

     movewController.shouldAutoplay=YES;

     [movewController setControlStyle:MPMovieControlStyleDefault];

     [movewController setFullscreen:YES];

     [movewController.view setFrame:self.view.bounds];

     这里注冊相关操作的通知

     [[NSNotificationCenter defaultCenteraddObserver:self

                                                 selector:@selector(movieFinishedCallback:)

                                                     name:MPMoviePlayerPlaybackDidFinishNotification

                                                   object:moveViewController.movewController]; //播放完后的通知


     [movewController release];

    }

    -(void)movieFinishedCallback:(NSNotification*)notify {

        MPMoviePlayerController* theMovie = [notify object];

        [[NSNotificationCenter defaultCenterremoveObserver:self

                                                        name:MPMoviePlayerPlaybackDidFinishNotification

                                                      object:theMovie];

        [theMovie.view removeFromSuperview];

        [theMovie release];

    }

    //////////////////////////////// end

    2.介绍下MPMoviePlayerViewController。 

    注意:MPMoviePlayerViewController 必须 presentMoviePlayerViewControllerAnimated方式加入,否则Donebutton是不会响应通知MPMoviePlayerPlaybackDidFinishNotification事件的。

    - (void)createMPPlayerController:(NSString *)sFileNamePath {

        MPMoviePlayerViewController *moviePlayer =[[MPMoviePlayerViewController allocinitWithContentURL:[NSURL fileURLWithPath:sFileNamePath]];

        [moviePlayer.moviePlayer prepareToPlay];

        [self presentMoviePlayerViewControllerAnimated:moviePlayer]; // 这里是presentMoviePlayerViewControllerAnimated

        [moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];

        [moviePlayer.view setBackgroundColor:[UIColor clearColor]];

        [moviePlayer.view setFrame:self.view.bounds];

        [[NSNotificationCenter defaultCenteraddObserver:self

                                                 selector:@selector(movieFinishedCallback:)

                                                     name:MPMoviePlayerPlaybackDidFinishNotification

                                                   object:moviePlayer.moviePlayer];

        [moviePlayer release];

    }

    -(void)movieStateChangeCallback:(NSNotification*)notify  {

       //点击播放器中的播放/ 暂停button响应的通知

    }

    -(void)movieFinishedCallback:(NSNotification*)notify{

       // 视频播放完或者在presentMoviePlayerViewControllerAnimated下的Donebutton被点击响应的通知。

        MPMoviePlayerController* theMovie = [notify object];

        [[NSNotificationCenter defaultCenterremoveObserver:self

                                                        name:MPMoviePlayerPlaybackDidFinishNotification

                                                      object:theMovie];

        [self dismissMoviePlayerViewControllerAnimated];

    }


    下面是资料

     moviePlayer.moviewControlMode = MPMovieControlModeDefault;

     MPMovieControlModeDefault            显示播放/暂停、音量和时间控制

     MPMovieControlModeVolumeOnly         仅仅显示音量控制

     MPMovieControlModeHidden             没有控制器

     

     moviePlayer.scallingMode = MPMovieScallingModeAspectFit;

     你能够使用下列宽高比值:

     MPMovieScallingModeNone            不做不论什么缩放

     MPMovieScallingModeAspectFit       适应屏幕大小,保持宽高比

     MPMovieScallingModeAspectFill      适应屏幕大小,保持宽高比。可裁剪

     MPMovieScallingModeFill            充满屏幕,不保持宽高比

     

     你会观察到下面通知:

     MPMoviePlayerContentPreloadDidFinishNotification

     当电影播放器结束对内容的预载入后发出。

    由于内容能够在仅载入了一部分的情况下播放。所以这个通知可能在已经播放后才发出。

     MPMoviePlayerScallingModeDidChangedNotification

     当用户改变了电影的缩放模式后发出。用户能够点触缩放图标,在全屏播放和窗体播放之间切换。

     MPMoviePlayerPlaybackDidFinishNotification

     当电影播放完成或者用户按下了Donebutton后发出。

  • 相关阅读:
    Navicat for MySQL破解版安装
    LACP学习笔记
    MUX VLAN
    Beyond Compare用于文件比较还是蛮好的选择,特别是我们程序袁用于比较两个项目的时候,最初使用的是Beyond Compare3一直用着挺好的,几年前更新了版本4,用着用着就提示试用期30天已过期,于是我尝试如下步骤:
    思科交换机如何进行备份与还原?
    vSphere ESXi 6.7 注册码(有效)
    VMware ESXi 6.7密码正确不能登录
    Esxi 6.5 6.7的root密码经过一段时间就不可用的解决方法
    Windows Server 2012 R2 安装密钥
    ubuntu 16 添加多个IP
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10860254.html
Copyright © 2011-2022 走看看