0

我有一些电影的表格视图:

在此处输入图像描述

当我从表中选择行时,我会这样做:

例如找到的电影是:

ht tp://.../movies/video/Adventure (Low-360p).mp4

NSString *URL = [foundMovie.movie stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *mediaURL = [NSURL URLWithString:URL];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];

[self.view addSubview:[mp view]];

[mp prepareToPlay];
[mp play];

没有错误 - 没有任何反应......

4

3 回答 3

0

假设您的项目使用 ARC,您的代码不会保留该MPMoviePlayerController实例。结果,玩家几乎立即离开。

尝试将局部变量更改为mp视图控制器的属性。这样,MPMoviePlayerController实例将在视图控制器的生命周期内保留。

@interface YourViewController ()
@property (nonatomic, strong) MPMoviePlayerController *mp;
@end

// ....

self.mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
于 2013-10-23T21:59:52.187 回答
0
 mp = [[MPMoviePlayerController alloc] init];
[mp prepareToPlay];
mp.shouldAutoplay = YES;
[mp setScalingMode:MPMovieScalingModeAspectFit];
 mp.contentURL = [NSURL URLWithString:YOUR_URL];
mp.controlStyle = YES;
  mp.fullscreen = YES;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish1:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

 [mp play];
于 2013-10-23T14:05:55.800 回答
0

I found a solution that player doesn't show up:

// frame must match parent view!!!!!!!!!
[[mp view] setFrame: [self.view bounds]];
[self.view addSubview: [mp view]];
于 2013-10-24T05:45:58.450 回答