如何在ios6中播放视频 [英] How to play video in ios6

查看:178
本文介绍了如何在ios6中播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑:

MPMoviePlayerViewController和MPMoviePlayerController

MPMoviePlayerViewController and MPMoviePlayerController

玩什么是最好的方法ios6本地视频?

what is the best way to play a video locally in ios6?

这是我的代码

NSURL * url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: @ "17" OfType: @ "mov"]];

     MoviePlayer = [[MPMoviePlayerViewController alloc]
                     initWithContentURL: url];
     [self presentMoviePlayerViewControllerAnimated: MoviePlayer];
     [moviePlayer.moviePlayer play];
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @ selector (moviePlayerPlaybackStateChanged :) name: MPMoviePlayerPlaybackStateDidChangeNotification object: nil];
}


-(void)moviePlayerPlaybackStateChanged:(NSNotification *)notification {


}


推荐答案

MPMoviePlayerViewController用于播放全屏视频,主要用于手机。

MPMoviePlayerViewController is for playing fullscreen video and is used mostly on the phone.

MPMoviePlayerController可用于嵌入式视频,即不能在任何iPad上全屏显示。您需要在故事板中将空视图拖到场景中并为其指定所需大小。然后,在代码中,将电影播放器​​放在该子视图中。您的代码的第一部分应该在viewDidLoad中;

MPMoviePlayerController can be used for embedded video, ie not full screen on any of the iPads. You need to pull an empty view onto your scene in storyboard and give it the desired size. Then, in code, place the movieplayer in that subview. The first part of your code should be in viewDidLoad;

//movieplayer initialization
NSString *path = [[NSBundle mainBundle] pathForResource:@"videoName" ofType:@"m4v"];
NSURL *videoURL = [NSURL fileURLWithPath:path];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer setControlStyle:MPMovieControlStyleNone]; // for custom controls, for default controls you can leave this line out.

此部分进入viewWillAppear;

This part goes in viewWillAppear;

moviePlayer.repeatMode = MPMovieRepeatModeOne; // for looping
[moviePlayer.view setFrame: self.videoSuper.bounds]; 
[self.videoSuper addSubview: moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];

其中videoSuper是故事板中添加的子视图。一定要正确地连接它;

where videoSuper is the subview added in storyboard. Be sure to hook it up correctly;

//in .h
@property (weak, nonatomic) IBOutlet UIView *videoSuper;

这篇关于如何在ios6中播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆