Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Brightcove Player SDK - Set initial time

I'm playing some videos using the Brighcove SDK for iOS. The basic setup for playing the video is (based on the Brightcove guide):

@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's 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's playback queue
[self.controller setVideos:videos];
// play the first video
[self.controller play];    

}

@end

How can i set the initial time of the video? i've read the SDK documentation and haven't found any property or method.

like image 327
Diego Vidal Avatar asked Nov 11 '22 00:11

Diego Vidal


1 Answers

That's an interesting question. There isn't currently a way to use the Brightcove Player SDK for iOS to accomplish this easily, but you can go directly down to the AVFoundation level to do so. Here's how:

The playback controller will create a playback session for each video that you give to it. Inside of each playback session is an AVPlayer, containing an AVPlayerItem with your video's (actually, one of the video's BCOVSource's) URL. Once the AVPlayerItem's status property has a value of AVPlayerItemStatusReadyToPlay, you can safely use any of the AVPlayer's -seekToTime methods to seek the video to the desired start time of the video. There's a lifecycle event that gets sent to your delegate (if you implement the appropriate delegate method) which you can listen to in order to get notified of this event.

Also, you will probably want to set self.controller.autoPlay = NO so that the video doesn't start playing before you've had a chance to seek to the desired start time. Then you can just call -play manually from within your seek completion handler.

Here's the basic idea (note this code is not 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];

        }];
    }
}
like image 67
erikprice Avatar answered Nov 14 '22 22:11

erikprice