问题
I am developing an iPhone application in which I will store stream video from URL directly to cache in local, now I need to play video in movie-player while it was in downloading in cache. I followed this http://lists.apple.com/archives/cocoa-dev/2011/Jun/msg00844.html, but I couldn't do exact. I am able to download video in cache but I couldn't play video from cache. So how can I play while its downloading?
回答1:
Just change your web url to local path url...
Try this code...
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];
回答2:
if you are using arc add in t .h file
@property (nonatomic, strong) MPMoviePlayerController *controller;
and take a look at the last line. good luck
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];
}
来源:https://stackoverflow.com/questions/7402579/play-video-from-cache-in-iphone-programmatically