AVSynchronizedLayer 애니메이션은 로컬 파일에서 잘 작동하지만 스트리밍 중에는 작동하지 않습니다.

파라 즈 하산 |

AVSynchronizedLayer를 사용하는 로컬 비디오 파일에서 잘 작동하는 애니메이션이 있습니다. 이제 로컬 파일을 같은 파일의 스트리밍 링크로 바꾸면 애니메이션이 완전히 작동하지 않습니다. 이 문제의 원인이 무엇인지 전혀 알지 못하며 여러 번 시도했으며 로컬 파일에서는 완전히 작동하지만 스트리밍 중에는 작동하지 않습니다. 어떤 아이디어?

편집하다:

- (void)observeValueForKeyPath:(NSString*) path
                  ofObject:(id)object
                    change:(NSDictionary*)change
                   context:(void*)context{
/* AVPlayerItem "status" property value observer. */
if (context == AVPlayerDemoPlaybackViewControllerStatusObservationContext)
{
    [self syncPlayPauseButtons];

    AVPlayerStatus status = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
    switch (status)
    {
            /* Indicates that the status of the player is not yet known because
             it has not tried to load new media resources for playback */
        case AVPlayerStatusUnknown:
        {
            [self removePlayerTimeObserver];
            [self syncScrubber];

            [self disableScrubber];
            [self disablePlayerButtons];
        }
            break;

        case AVPlayerStatusReadyToPlay:
        {
            /* Once the AVPlayerItem becomes ready to play, i.e.
             [playerItem status] == AVPlayerItemStatusReadyToPlay,
             its duration can be fetched from the item. */

            [self initScrubberTimer];

            [self enableScrubber];
            [self enablePlayerButtons];
        }
            break;

        case AVPlayerStatusFailed:
        {
            AVPlayerItem *playerItem = (AVPlayerItem *)object;
            [self assetFailedToPrepareForPlayback:playerItem.error];
        }
            break;
    }
}
/* AVPlayer "rate" property value observer. */
else if (context == AVPlayerDemoPlaybackViewControllerRateObservationContext)
{
    [self syncPlayPauseButtons];
}
/* AVPlayer "currentItem" property observer.
 Called when the AVPlayer replaceCurrentItemWithPlayerItem:
 replacement will/did occur. */
else if (context == AVPlayerDemoPlaybackViewControllerCurrentItemObservationContext)
{
    AVPlayerItem *newPlayerItem = [change objectForKey:NSKeyValueChangeNewKey];

    /* Is the new player item null? */
    if (newPlayerItem == (id)[NSNull null])
    {
        [self disablePlayerButtons];
        [self disableScrubber];
    }
    else /* Replacement of player currentItem has occurred */
    {
        /* Set the AVPlayer for which the player layer displays visual output. */
        [self.playbackView setPlayer:_player];

        /* Specifies that the player should preserve the video’s aspect ratio and
         fit the video within the layer’s bounds. */
        [self.playbackView setVideoFillMode:AVLayerVideoGravityResizeAspect];

        [self syncPlayPauseButtons];
    }
}
else if( context == AVPlayerDemoPlaybackViewControllerCurrentItemObservationContextForDisplay)
{
    AVPlayerLayer *layer = (AVPlayerLayer*) object;
    if (layer.readyForDisplay){
        [layer removeObserver:self forKeyPath:kReadyForAdDisplayKeyT];

        AVPlayerItem *item = _player.currentItem;
        AVSynchronizedLayer *syncedLayer = [AVSynchronizedLayer synchronizedLayerWithPlayerItem:item];
        syncedLayer.frame = CGRectMake(0, 0, 568, 320);
        syncedLayer.backgroundColor = [[UIColor clearColor] CGColor];
        //ADDING THE SYNCHRONIZED LAYER TO MY VIEW
        [self.madnessView addSyncedLayer:syncedLayer player:[self.playbackView player] withGravity:layer.videoGravity];
    }
}
else
{
    [super observeValueForKeyPath:path ofObject:object change:change context:context];
}}

여기에서 애니메이션이 재생되는 사용자 지정 뷰에 AVSynchronized 레이어를 추가합니다. 애니메이션 코드는 다음과 같습니다.

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
anim.beginTime = AVCoreAnimationBeginTimeAtZero;
anim.duration = self.videoDuration;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
anim.values = [self.transforms objectAtIndex:adNumber];
UIImageView* imageView = [self.adViews objectAtIndex:adNumber];
[imageView.layer addAnimation:anim forKey:@"transformAnimation"];
imageView.hidden = NO;
파라 즈 하산 |

문제는 레이어가 생성되었을 때였습니다. 이를 수정하면 (즉, 비디오 플레이어가 재생 될 준비가 된 후 레이어 / 애니메이션 만들기) 예상대로 작동하기 시작했습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관