Gan*_*esh 6 iphone ipod objective-c ipad avplayer
我正在使用AVPlayer逐帧慢慢播放视频.我用这个编码.我无法播放视频.请注意我的问题.
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];
newView.backgroundColor = [UIColor yellowColor];
NSString *videoName = [fileNameArray objectAtIndex:indexPath.section];
NSString *url = [Utilities documentsPath:[NSString stringWithFormat:@"OSC/%@/%@.mov",videoName,videoName]];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:url]];
//AVPlayer *avPlayer = [[AVPlayer playerWithURL:[NSURL URLWithString:url]] retain];
AVPlayer *avPlayer = [[AVPlayer playerWithPlayerItem:playerItem] retain];
AVPlayerLayer *avPlayerLayer = [[AVPlayerLayer playerLayerWithPlayer:avPlayer] retain];
avPlayerLayer.frame = self.view.frame;
[newView.layer addSublayer:avPlayerLayer];
[self.view addSubview:newView];
[avPlayer play];
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[avPlayer currentItem]];
Run Code Online (Sandbox Code Playgroud)
Ami*_*Kh. 11
因为您使用本地文件,所以最好[NSURL fileURLWithPath:url]将NSString转换为NSURL.所以将代码更改为:
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:url]];
Run Code Online (Sandbox Code Playgroud)
小智 4
我不知道逐帧缓慢的情况,但你正在做一些你不需要做的事情。在 iPhone 文档中,苹果公司的人完全搞乱了内存管理,使其变得比需要的更加复杂,所以我将告诉你让它发挥作用的关键事项:
首先,保留播放器,而不是图层。如果您不知道原因,请阅读书籍或视图手册。(里面充满了同音字式的错别字,但比买一本厚书容易多了)。
第二,你没有投射图层并使用setPlayer:,确切的行在Apple的文档中。您必须使用类型转换来转换 self.layer 。
| 归档时间: |
|
| 查看次数: |
10803 次 |
| 最近记录: |