All Products
Search
Document Center

:VOD players

Last Updated:May 12, 2023

This topic describes how to use a video on demand (VOD) player on an iOS app.

Procedure

  1. Create a VOD player.

  2. Configure a rendering view and callbacks for the player.

  3. Configure other parameters for the player based on your business requirements, such as the decoding policy and display mode.

  4. Specify a playback source.

    1. Play device recordings by file name: Call the QueryDeviceVodUrl operation to obtain the Real-Time Messaging Protocol (RTMP) playback URL of a recording of a specified name in the storage card of an on-premises network video recorder (NVR) or an IP camera. Then, specify the RTMP playback URL as a playback source for the player.

    2. Play device recordings by time: Call the QueryDeviceVodUrlByTime operation to obtain the RTMP playback URL of one or more recordings whose modification time is within a specified time range in the storage card of an on-premises NVR or an IP camera. Then, specify the RTMP playback URL as a playback source for the player.

    3. Play cloud recordings by file name: Call the QueryRecordUrl operation to obtain the HTTP Live Streaming (HLS) playback URL of a cloud recording of a specified name. Then, specify the RTMP playback URL as a playback source for the player.

  5. Start the playback.

  6. Pause or resume the playback, and seek to a point in time of the playback.

  7. Stop the playback.

  8. Delete the VOD player.

Sample code

Play device recordings on demand

// Create a player instance.
self.player = [[LVVodPlayer alloc] init];
// Configure the required listener.
self.player.vodPlayerDelegate = self;
...
#pragma mark LVVodPlayerDelegate
- (void) onVodPlayerError:(LVVodPlayer *_Nonnull)player error:(NSError *_Nonnull)error{
    [self appendInfoText:[NSString stringWithFormat:@"Playback failed: %@\n", error]];
}

- (void) onVodPlayerStateChange:(LVVodPlayer *_Nonnull)player playerState:(LVPlayerState)state{
    [self appendInfoText:[NSString stringWithFormat:@"Status changed: %d\n", state]];
}

- (void) onVodPlayerRenderedFirstFrame:(LVVodPlayer *_Nonnull)player elapsedTimeInMs:(NSInteger)elapsedTimeInMs{
    [self appendInfoText:[NSString stringWithFormat:@"Image generation time for the first frame: %ldms\n", (long)elapsedTimeInMs]];
    [self appendInfoText:[self.player getStatisticsInfo]];
}

- (void) onVodPlayerVideoSizeChanged:(LVVodPlayer *_Nonnull)player width:(NSInteger)width height:(NSInteger)height{
    [self appendInfoText:[NSString stringWithFormat:@"Image size changes: w=%ld h=%ld\n", (long)width, (long)height]];
}

- (void) onVodPlayerStandardSeiInfoUpdate:(LVVodPlayer *_Nonnull)player sei:(NSData*_Nonnull)data timeStamp:(NSInteger)timeStamp{
    [self appendInfoText:[NSString stringWithFormat:@"sei: %lu %ld\n", (unsigned long)data.length, timeStamp]];
}

- (void) onVodPlayerVideoJitterBufferEmpty:(LVLivePlayer *_Nonnull)player{
}

- (void)onVodPlayerCompletion:(LVVodPlayer * _Nonnull)player {
    [self appendInfoText:@"Playback ends"];
}
...
// Create an object named LVGlkView and add the object to another object named scrollview to enable the image scaling feature.
self.lvGlkView = [[LVGlkView alloc] initWithFrame:CGRectMake(0,0,self.scrollView.frame.size.width, self.scrollView.frame.size.height)];;
[self.scrollView addSubview:self.lvGlkView];
[self.glkView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(@(0));
    make.centerY.equalTo(@(0));
    make.height.equalTo(self.scrollView.mas_height);
    make.width.equalTo(self.scrollView.mas_width);
}];
// Configure a rendering view for the player.
[self.player setWindow:self.lvGlkView];

...
// Specify a Real-Time Messaging Protocol (RTMP) playback URL of a device recording as a playback source. Obtain the RTMP playback URL where the device recording that you want to play on demand resides from IoT Platform and a decryption key.
[self.player setDataSource:@"rtmp://xx.xx.xx.xx/vod/xxx" isEncrypted:(YES) decryptIvBase64:(@"xxxxxxx") decryptKeyBase64:@"xxxxxxx"];
// Specify hardware decoding as the highest-priority decoding policy.
[self.player setDecoderStrategy:LV_DECODER_STRATEGY_HARDWARE_FIRST];
// Specify an aspect ratio-based display mode.
[self.player setVideoScalingMode:LV_MEDIA_VIDEO_SCALING_MODE_FIT];
...
// Start a playback.
[self.player start];
...
// Pause the playback.
[self.player pause];
...
// Resume the playback.
[self.player resume];
...
// Stop the playback.
[self.player stop];

Play cloud recordings on demand

// Create a player instance.
self.player = [[LVVodPlayer alloc] init];
// Configure the required listener.
self.player.vodPlayerDelegate = self;
...
#pragma mark LVVodPlayerDelegate
- (void) onVodPlayerError:(LVVodPlayer *_Nonnull)player error:(NSError *_Nonnull)error{
    [self appendInfoText:[NSString stringWithFormat:@"Playback failed: %@\n", error]];
}

- (void) onVodPlayerStateChange:(LVVodPlayer *_Nonnull)player playerState:(LVPlayerState)state{
    [self appendInfoText:[NSString stringWithFormat:@"Status changed: %d\n", state]];
}

- (void) onVodPlayerRenderedFirstFrame:(LVVodPlayer *_Nonnull)player elapsedTimeInMs:(NSInteger)elapsedTimeInMs{
    [self appendInfoText:[NSString stringWithFormat:@"Image generation time for the first frame: %ldms\n", (long)elapsedTimeInMs]];
    [self appendInfoText:[self.player getStatisticsInfo]];
}

- (void) onVodPlayerVideoSizeChanged:(LVVodPlayer *_Nonnull)player width:(NSInteger)width height:(NSInteger)height{
    [self appendInfoText:[NSString stringWithFormat:@"Image size changes: w=%ld h=%ld\n", (long)width, (long)height]];
}

- (void) onVodPlayerStandardSeiInfoUpdate:(LVVodPlayer *_Nonnull)player sei:(NSData*_Nonnull)data timeStamp:(NSInteger)timeStamp{
    [self appendInfoText:[NSString stringWithFormat:@"sei: %lu %ld\n", (unsigned long)data.length, timeStamp]];
}

- (void) onVodPlayerVideoJitterBufferEmpty:(LVLivePlayer *_Nonnull)player{
}

- (void)onVodPlayerCompletion:(LVVodPlayer * _Nonnull)player {
    [self appendInfoText:@"Playback ends"];
}
...
// Create an object named LVGlkView and add the object to another object named scrollview to enable the image scaling feature.
self.lvGlkView = [[LVGlkView alloc] initWithFrame:CGRectMake(0,0,self.scrollView.frame.size.width, self.scrollView.frame.size.height)];;
[self.scrollView addSubview:self.lvGlkView];
[self.glkView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(@(0));
    make.centerY.equalTo(@(0));
    make.height.equalTo(self.scrollView.mas_height);
    make.width.equalTo(self.scrollView.mas_width);
}];
// Configure a rendering view for the player.
[self.player setWindow:self.lvGlkView];

...
// Specify an HTTP Live Streaming (HLS) playback URL of a cloud recording as a playback source. Obtain the HLS playback URL where the cloud recording is stored from IoT Platform.
[self.player setDataSource:@"https://xx.xx.xx.xx/hls/xxx.m3u8"];
// Specify hardware decoding as the highest-priority decoding policy.
[self.player setDecoderStrategy:LV_DECODER_STRATEGY_HARDWARE_FIRST];
// Specify an aspect ratio-based display mode.
[self.player setVideoScalingMode:LV_MEDIA_VIDEO_SCALING_MODE_FIT];
...
// Start a playback.
[self.player start];
...
// Pause the playback.
[self.player pause];
...
// Resume the playback.
[self.player resume];
...
// Stop the playback.
[self.player stop];