本文介绍了initWithPlayerItem时GPUImageMovie不播放视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将GPUImageMovie与initWithPlayerItem一起使用,并且它在startProcessing上未启动电影文件.与initWithUrl一起使用时效果很好,但我需要播放器的播放控件,如中所述线.我正在使用以下代码

I am using GPUImageMovie with initWithPlayerItem and its not starting the movie file on startProcessing. It was working fine with initWithUrl but I need playback controls for the player as told in this thread. I am using the following code

-(void)loadVideo
{
    _playerItem = [[AVPlayerItem alloc]initWithURL:movieURL];
    _player = [AVPlayer playerWithPlayerItem:_playerItem];
    movieFile = [[GPUImageMovie alloc] initWithPlayerItem:_playerItem];

    movieFile.runBenchmark = YES;
    movieFile.playAtActualSpeed = YES;

    filter = [[TSFilter alloc] init];
    _movieView = [[GPUImageView alloc] initWithFrame:self.view.bounds];

    [self.view addSubview:_movieView];
    [self.view sendSubviewToBack:_movieView];

    [movieFile addTarget:filter];
    [filter addTarget:_movieView];

    _player.rate = 1.0;

    [movieFile startProcessing];

    [_player play];

}

推荐答案

最后,在花了很多时间之后,我找到了解决这个愚蠢问题的方法.当我尝试捆绑文件而不是文档目录中的文件时,便想到了该解决方案.我认为这是AVPlayerItem:initWithUrl方法中的错误,无法与文档目录中的NSUrl值一起使用.让我详细解释一下

And finally after spent a lot of time I found the solution to this silly problem. I came to that solution when I tried bundled file instead of a file in a document directory. I think it is the bug in AVPlayerItem:initWithUrl method that is not working with the NSUrl value from document directory. Let me explain it in detail

当我从文档目录获取文件的网址时,其值为

When I get the Url of the file from document directory its value is

/var/mobile/Applications/7B3229B0-D18E-405D-BBA0-E9D57F2842C4/Documents/SkyFall_clip.m4v

/var/mobile/Applications/7B3229B0-D18E-405D-BBA0-E9D57F2842C4/Documents/SkyFall_clip.m4v

但是如果我捆绑了此文件并从[NSBundle mainBundle]获取了url,则其值为

but if I bundled this file and get the url from [NSBundle mainBundle] then its value is

file:///var/mobile/Applications/7B3229B0-D18E-405D-BBA0-E9D57F2842C4/Documents/SkyFall_clip.m4v

file:///var/mobile/Applications/7B3229B0-D18E-405D-BBA0-E9D57F2842C4/Documents/SkyFall_clip.m4v

因此,我发现文档目录文件的URL中缺少"file://"关键字.因此,我只在URL的开头附加"file://",它便开始工作.尽管并非如此,因为两者都是有效的NSUrl,并且适用于UIImage等其他类.

So I found that "file://" keyword is missing in the url for the document directory file. So i just append "file://" in the beginning of the url and it starts working. Although this should not be the case because both are the valid NSUrl and working for other classes like UIImage.

注意:实现字符串附加操作的方式是仅在缺少字符串时才附加.

Note: Implement the string append operation is such a way that it append only if it is missing.

这篇关于initWithPlayerItem时GPUImageMovie不播放视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:46