你好,我正在尝试从NSCachesDirectory播放视频文件。但是,播放器在videoView层面无法加载来自NSCachesDirectory的文件。
是否有可能从cacheDirectory内存中播放视频? 请给我建议...
我已经尝试过以下方法:
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [myPathList objectAtIndex:0];
NSString *songPath = [[NSString alloc] initWithString: [cachesDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Song.%@", downloadURL]]];
NSURL *pathurl = [[NSURL alloc] initFileURLWithPath:songPath];
NSLog(@"--pathurl---%@",pathurl);
avPlayer =[AVPlayer playerWithURL:pathurl];
self.avPlayerLayer =[AVPlayerLayer playerLayerWithPlayer:avPlayer];
if ( !([avPlayer status] == AVPlayerStatusReadyToPlay) && (dataReceivedSoFar.length >10000))
{
avPlayerLayer.frame =CGRectMake(0, 0, 320, 450);
[[self.videoView layer] addSublayer:avPlayerLayer];
[avPlayer play];
NSLog(@"Video IS Playing");
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
if ( !([avPlayer status] == AVPlayerStatusReadyToPlay) && (dataReceivedSoFar.length >10000))
。只需尝试在代码中创建AVPlayerLayer后附加它并调用[avPlayer play]即可。 - awolCZ