진단 할 수없는 메모리 누수가 있습니다. AVPlayerLooper 외에, 내가 만났고 시도한 모든 접근법은 AVPlayerItemDidPlayToEndTimeNotification
을보고 나서 AVPlayer의 경우에는 비디오의 시작 부분을 찾거나 (AVPlayer의 경우) 관찰자를 만드는 작업과 관련이 있습니다. 루프 될 비디오를 비디오 대기열에 삽입합니다 (AVQueuePlayer의 경우). 둘 다 비슷한 성능을 갖고있는 것처럼 보이지만, 둘 다 seekToTime 메소드 (AVPlayer의 경우) 및 insertItem 메소드 (AVQueuePlayer의 경우)와 관련하여 일관된 메모리가 유지됩니다. 최종 목표는 기본적으로 루프하는 SKVideoNode의 하위 클래스를 만드는 것입니다. 아래는 서브 클래스 내 코드입니다 :루핑으로 인한 메모리 누수 SKVideoNode (실제 장치에서만)
#import "SDLoopingVideoNode.h"
#import <AVFoundation/AVFoundation.h>
@interface SDLoopingVideoNode()
@property AVQueuePlayer *avQueuePlayer;
@property AVPlayerLooper *playerLooper;
@end
@implementation SDLoopingVideoNode
-(instancetype)initWithPathToResource:(NSString *)path withFiletype:(NSString *)filetype
{
if(self == [super init])
{
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:path ofType:filetype];
NSURL *videoURL = [NSURL fileURLWithPath:resourcePath];
AVAsset *videoAsset = [AVAsset assetWithURL:videoURL];
AVPlayerItem * videoItem = [AVPlayerItem playerItemWithAsset:videoAsset];
self.avQueuePlayer = [[AVQueuePlayer alloc] initWithItems:@[videoItem]];
NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
[noteCenter addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
AVPlayerItem *video = [[AVPlayerItem alloc] initWithURL:videoURL];
[self.avQueuePlayer insertItem:video afterItem:nil];
NSLog(@"Video changed");
}];
self = (SDLoopingVideoNode*)[[SKVideoNode alloc] initWithAVPlayer: self.avQueuePlayer];
return self;
}
return nil;
}
@end
가 그리고 여기에 서브 클래스가 didMoveToView에 초기화 방법은 다음과 같습니다
SDLoopingVideoNode *videoNode = [[SDLoopingVideoNode alloc]initWithPathToResource:@"147406" withFiletype:@"mp4"];
[videoNode setSize:CGSizeMake(self.size.width, self.size.height)];
[videoNode setAnchorPoint:CGPointMake(0.5, 0.5)];
[videoNode setPosition:CGPointMake(0, 0)];
[self addChild:videoNode];
[videoNode play];
내가 알아 차 렸던 또 다른 이상한 점은 -이 메모리 누출은 단지 장치에 표시된다는 것입니다. 시뮬레이터에서 실행될 때 메모리 누출이 없습니다. –