以编程方式从iphone中缓存播放视频

时间:2011-09-13 13:21:23

标签: iphone caching mpmovieplayercontroller mpmovieplayer

我正在开发一个iPhone应用程序,我将URL中的流视频直接存储到本地缓存中,现在我需要在缓存中下载时在电影播放器​​中播放视频。我遵循了这个http://lists.apple.com/archives/cocoa-dev/2011/Jun/msg00844.html,但我无法做到。我可以在缓存中下载视频但我无法从缓存中播放视频。那么下载时怎么玩呢?

2 个答案:

答案 0 :(得分:1)

只需将您的网址更改为本地路径网址

试试这段代码......

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

答案 1 :(得分:1)

如果你使用弧线 添加t .h文件

@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];
}
相关问题