我正在开发一个iPhone应用程序,我将直接从URL存储流视频到本地缓存中,现在我需要在下载期间在movie-player中播放视频。我遵循了这个http://lists.apple.com/archives/cocoa-dev/2011/Jun/msg00844.html,但我无法完全实现。我能够在缓存中下载视频,但我无法从缓存中播放视频。所以我该如何在下载视频的同时播放它?
我正在开发一个iPhone应用程序,我将直接从URL存储流视频到本地缓存中,现在我需要在下载期间在movie-player中播放视频。我遵循了这个http://lists.apple.com/archives/cocoa-dev/2011/Jun/msg00844.html,但我无法完全实现。我能够在缓存中下载视频,但我无法从缓存中播放视频。所以我该如何在下载视频的同时播放它?
只需将您的网址更改为本地路径网址...
尝试这段代码...
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
@property (nonatomic, strong) MPMoviePlayerController *controller;
看一下最后一行。祝你好运
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Man of Steel" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view setFrame:CGRectMake(0,0,500,500)];
[self.view addSubview:moviePlayerController.view];
//moviePlayerController.fullscreen = YES;
//moviePlayerController.scalingMode = MPMovieScalingModeFill;
[moviePlayerController play];
[self setController:moviePlayerController];
}