在iPhone上以编程方式从缓存中播放视频

15

我正在开发一个iPhone应用程序,我将直接从URL存储流视频到本地缓存中,现在我需要在下载期间在movie-player中播放视频。我遵循了这个http://lists.apple.com/archives/cocoa-dev/2011/Jun/msg00844.html,但我无法完全实现。我能够在缓存中下载视频,但我无法从缓存中播放视频。所以我该如何在下载视频的同时播放它?


缓存的意思是将视频保存在本地吗? - ThE uSeFuL
你是说苹果列表提供的源代码不起作用?无论如何,你正在尝试自制渐进式下载。在我看来,在几乎任何情况下都不明智。我总是建议使用HTTP流媒体。 - Till
你找到任何解决这个问题的方法了吗? - YosiFZ
2个回答

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
如果您正在使用ARC,请在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];
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接