AVPlayer不播放本地网址。

时间:2016-08-07 03:23:17

标签: ios avplayer avplayerviewcontroller

我无法播放保存在我的文档文件夹中的网址。我首先从服务器下载视频,然后将视频路径保存到我的应用文档文件夹中。当我从设备上拉出路径时,AVplayer只是空白。这是我的代码:

VideoPlayer *vidPlayer = (VideoPlayer *)[self.view viewWithTag:500];




NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filepath = [path stringByAppendingPathComponent:@"Data.dat"];
NSMutableArray *listOfVideos = [NSKeyedUnarchiver unarchiveObjectWithFile:filepath];




NSURL *fileURL = listOfVideos[0][@"video"];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:fileURL options:nil];
AVPlayerItem *firstItem = [[AVPlayerItem alloc] initWithAsset:asset];


_queuePlayer =[[AVQueuePlayer alloc]initWithPlayerItem:firstItem];
AVPlayerLayer *layer = (AVPlayerLayer *)vidPlayer.layer;
layer.player = _queuePlayer;
[_queuePlayer play];

0 个答案:

没有答案