zoukankan      html  css  js  c++  java
  • iOS之视频播放MPMoviePlayerViewController

    需要导入的框架

    #import <MediaPlayer/MediaPlayer.h>

    MediaPlayer.framework

    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_0322"ofType:@"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];

       

    }

  • 相关阅读:
    对小课堂cpp的用户体验
    面试题 02.07. 链表相交 做题小结
    Leetcode 133. 克隆图 做题小结
    Leetcode 889. 根据前序和后序遍历构造二叉树-105. 从前序与中序遍历序列构造二叉树-106. 从中序与后序遍历序列构造二叉树
    图 的矩阵表示 和邻接表表示
    二叉树 常用函数 小结
    LeetCode 100. 相同的树 做题小结
    LeetCode 897. 递增顺序查找树 做题小结
    Leetcode 814. 二叉树剪枝 做题小结
    Leetcode l872. 叶子相似的树 做题小结
  • 原文地址:https://www.cnblogs.com/Sucri/p/4645493.html
Copyright © 2011-2022 走看看