如果我在documents
中运行应用程序,则directory
ios8
中存储的视频无法播放,但如果我在ios7
中运行
我正在使用documents
在directory
AFNetworking
下载视频。以下是代码。
NSURLRequest *request = [NSURLRequest requestWithURL:urlVideo];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSString *path = [dataPath stringByAppendingPathComponent:[urlVideo lastPathComponent]];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.isDownloadingComplete = YES;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Video Downloading Failed");
}];
[operation start];
我正在播放使用video
下载AVPlayer
的内容。这是代码。
NSURL* playbackURL = [[NSURL alloc] initFileURLWithPath:strPath isDirectory:NO];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:[_pl currentItem]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[_pl currentItem]];
AVAsset *asset = [AVURLAsset URLAssetWithURL:playbackURL options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
_pl = [AVPlayer playerWithPlayerItem:anItem];
_pl.volume = 1.0;
_pl.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:_pl];
layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
layer.frame = CGRectMake(0, 0, 305, 306);
[self.contentView.layer addSublayer: layer];
[_pl play];
我认为问题在于文档目录,因为我运行应用程序,文档路径每次都在变化,但我每次都发送正确的路径。以下是参考:http://pinkstone.co.uk/where-is-the-documents-directory-for-the-ios-8-simulator/
答案 0 :(得分:0)
我终于通过以下代码
解决了这个问题我刚刚更换了
[self.contentView.layer addSublayer: layer];
与
[self.layer addSublayer:layer];
它工作正常,但我仍然没有得到[self.contentView.layer addSublayer: layer];
如果有人有强有力的证据,请告诉我。
由于