在iPhone中流视频

时间:2013-10-23 13:54:03

标签: ios iphone video video-streaming mpmovieplayercontroller

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

enter image description here

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

找到电影的例子是:

h t 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];

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

3 个答案:

答案 0 :(得分: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];

答案 1 :(得分:0)

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

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

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

// ....

self.mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];

答案 2 :(得分:0)

我找到了一个玩家没有出现的解决方案:

// frame must match parent view!!!!!!!!!
[[mp view] setFrame: [self.view bounds]];
[self.view addSubview: [mp view]];