ForwardPlaybackEndTime not working

AVPlayerItem has this property forwardPlaybackEndTime

The value indicates the end time of playback when the playback speed is positive (see the AVPlayers speed property).

The default value is kCMTimeInvalid, which means the end time for direct playback. In this case, the effective end of the forward playback time is the duration of the elements.

But I do not know why this does not work. I tried to set it to a AVPlayerItemStatusReadyToPlaylong available callback ... but it has no effect, it just plays to the end

I think that is forwardPlaybackEndTimeused to limit playback, right? In my application, I want to play from the beginning to half the movie only

My code is as follows

- (void)playURL:(NSURL *)URL
{
    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:URL];

    if (self.avPlayer) {
        if (self.avPlayer.currentItem && self.avPlayer.currentItem != playerItem) {
            [self.avPlayer replaceCurrentItemWithPlayerItem:playerItem];
        }
    } else {
        [self setupAVPlayerWithPlayerItem:playerItem];
    }

    playerItem.forwardPlaybackEndTime = CMTimeMake(5, 1);

    // Play
    [self.avPlayer play];
}

How to do the job forwardPlaybackEndTime?

0
4

   AVPlayerItem.forwardPlaybackEndTime = CMTimeMake(5, 1);
   Here 5 is the time till the AVPlayerItem will play.
0

AVPlayer :

AVPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidPlayToEndTime:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];

, ,

- (void) playerItemDidPlayToEndTime:(NSNotification*)notification
{
// do something here
}

forwardPlaybackEndTime

AVPlayer.currentItem.forwardPlaybackEndTime = CMTimeAdd(AVPlayer.currentItem.currentTime, CMTimeMake(5.0, 1));

avplayer

AVPlayer.rate = 1.0;

, . seekToTime - .

NSArray *array = [NSArray arrayWithObject:[NSValue valueWithCMTime:CMTimeMakeWithSeconds(5.0, 1)]];


    __weak OTHD_AVPlayer* weakself = self;
    self.observer_End = [self addBoundaryTimeObserverForTimes:array queue:NULL usingBlock:^{ if( weakself.rate >= 0.0 )     [weakself endBoundaryHit]; }];
0

:

- (void)playURL
{

NSURL *url = [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"];

self.playerItem = [AVPlayerItem playerItemWithURL:url];

self.playerItem.forwardPlaybackEndTime = CMTimeMake(10, 1);

self.avPlayer = [AVPlayer playerWithPlayerItem:self.playerItem];

[videoView setPlayer:self.avPlayer];

// Play
[self.avPlayer play];
}

, .

: AVFoundation Framework

0
source

I think you need to upgrade avPlayer current playerItem.

So,

 playerItem.forwardPlaybackEndTime = CMTimeMake(5, 1);

it should be:

 self.avPlayer.currentItem.forwardPlaybackEndTime = CMTimeMake(5, 1);
0
source

All Articles