IOS Brightcove Player SDK - Set Start Time

I play several videos using the Brighcove SDK for iOS. Basic setting for video playback (based on Brightcove manual):

@interface VideoPlayerViewController() @property (strong, nonatomic) id <BCOVPlaybackController> videoController; @end @implementation VideoPlayerViewController -(void)viewDidLoad { // create an array of videos NSArray *videos = @[ [self videoWithURL:[NSURL URLWithString:@"http://cf9c36303a9981e3e8cc-31a5eb2af178214dc2ca6ce50f208bb5.r97.cf1.rackcdn.com/bigger_badminton_600.mp4"]], [self videoWithURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]] ]; // add the playback controller self.controller = [[BCOVPlayerSDKManager sharedManager] createPlaybackControllerWithViewStrategy:[self viewStrategy]]; self.controller.view.frame = self.view.bounds; // create a playback controller delegate self.controller.delegate = self; self.controller.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; // add the controller view as a subview of the SVPViewController view [self.view addSubview:self.controller.view]; // turn on auto-advance self.controller.autoAdvance = YES; // turn on auto-play self.controller.autoPlay = YES; // add the video array to the controller playback queue [self.controller setVideos:videos]; // play the first video [self.controller play]; } @end 

How to set the start time of the video? I read the SDK documentation and did not find any property or method.

+5
source share
1 answer

This is an interesting question. There is currently no way to use the BrightCove Player SDK for iOS for this, but you can go directly to the AVFoundation level to do this. Here's how:

The playback controller will create a playback session for each video that you give it. Inside each playback session is an AVPlayer containing an AVPlayerItem with your video (in fact, one of the BCOVSource videos). When the AVPlayerItem status property is set to AVPlayerItemStatusReadyToPlay , you can safely use any of the AVPlayer -seekToTime methods to find the video at the right time to start the video. There is a lifecycle event that is dispatched to your delegate (if you implement the appropriate delegate method) that you can listen to receive a notification about this event.

In addition, you probably want to set self.controller.autoPlay = NO so that the video does not start before you can find the desired start time. Then you can simply call -play manually from your search completion handler.

Here's the basic idea (note that this code has not been tested):

 - (void)playbackController:(id<BCOVPlaybackController>)controller session:(id<BCOVPlaybackSession>)session didReceiveLifecycleEvent:(BCOVPlaybackSessionLifecycleEvent *)event { if ([kBCOVPlaybackSessionLifecycleEventReady isEqualToString:event.eventType]) { [session.player seekToTime:desiredStartTime completionHandler:^() { [session.player play]; }]; } } 
+1
source

Source: https://habr.com/ru/post/1205299/


All Articles