zoukankan      html  css  js  c++  java
  • iOS开发--利用MPMoviePlayerController播放视频简单实现

    一.包含头文件#import <MediaPlayer/MediaPlayer.h>

    二.重点:给MPMoviePlayerController的view设置frame,并且将view添加到某一个view上

     1 #import "ViewController.h"
     2 #import <MediaPlayer/MediaPlayer.h>
     3 
     4 @interface ViewController ()
     5 
     6 /* 播放器 */
     7 @property (nonatomic, strong) MPMoviePlayerController *player;
     8 - (IBAction)play;
     9 
    10 @end
    11 
    12 @implementation ViewController
    13 
    14 - (void)viewDidLoad {
    15     [super viewDidLoad];
    16 }
    17 
    18 - (MPMoviePlayerController *)player
    19 {
    20     if (_player == nil) {
    21         NSURL *url = [NSURL URLWithString:@"http://v1.mukewang.com/19954d8f-e2c2-4c0a-b8c1-a4c826b5ca8b/L.mp4"];
    22         
    23         _player = [[MPMoviePlayerController alloc] initWithContentURL:url];
    24         
    25         // 设置控制器View所在的位置
    26         _player.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width * 9 / 16);
    27         
    28         // 设置播放器的控制模式
    29         _player.controlStyle = MPMovieControlStyleFullscreen;
    30         
    31         [self.view addSubview:self.player.view];
    32     }
    33     return _player;
    34 }
    35 
    36 - (IBAction)play {
    37     [self.player play];
    38 }
    39 
    40 @end
  • 相关阅读:
    iframe和href中target属性的应用
    跨页面实现多选
    微软EPG老大发给员工的mail
    WebSerivce[连载]
    测试MSSQL保留字
    检正email的格式
    正则常用表达式
    企业库DAAB基本用法
    为什么覆写了Equals,还要覆写GetHashCode呢
    深入熟悉C# (待续)
  • 原文地址:https://www.cnblogs.com/gchlcc/p/5583554.html
Copyright © 2011-2022 走看看