首次尝试将视频集成到应用中。我已经按照了几本教程和一本书中的代码进行了操作,但我只是得到一个没有视频的空白屏幕(或其他任何内容)。我还应该提一下,我试图在模拟器中运行它,如果这很重要的话。
我在我的Build Phases中将MediaPlayer.framework
链接为二进制库。这是我的代码:
我无法理解我在俯视什么。谁能看到它?谢谢!
MoviePlayerViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface MoviePlayerViewController : UIViewController
@end
MoviePlayerViewController.m
#import "MoviePlayerViewController.h"
@interface MoviePlayerViewController ()
@end
@implementation MoviePlayerViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url=[[NSURL alloc] initWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
// MPMoviePlayerController *player = [notification object];
//
// [[NSNotificationCenter defaultCenter] removeObserver:self
// name:MPMoviePlayerPlaybackDidFinishNotification
// object:player];
//
// if ([player respondsToSelector:@selector(setFullscreen:animated:)])
// {
// [player.view removeFromSuperview];
// }
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:0)
(1)尝试将电影源类型指定为流媒体:
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
(2)即使它处于全屏模式,我认为你必须为你的播放器设置一个初始帧,例如,如果你想让它占据全屏模式:
[moviePlayer.view setFrame:self.view.bounds];
答案 1 :(得分:0)
尝试使用moviePlayer变量是iVar
NSURL *movieURL = [NSURL URLWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
self.moviePlayer = [[MPMoviePlayerController alloc] init];
[self.moviePlayer setShouldAutoplay:YES];
[self.moviePlayer setContentURL:movieURL.absoluteURL];
[self.moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
[self.moviePlayer setControlStyle:MPMovieControlModeDefault];
[self.moviePlayer setFullscreen:NO];
[self.moviePlayer setScalingMode:MPMovieScalingModeNone];
self.moviePlayer.view.frame = CGRectMake(40, 40, 240, 350);
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];