Polyv Help Center

Help Center

10 Anti-Screen Recording Marquee

Updated: 2023-04-17 15:27:58

This document explains the marquee feature integration using version 2.15.0 of the on-demand service as an example. The marquee is a video anti-screen recording strategy that displays text moving irregularly across the video, used for copyright tracing and anti-theft purposes.

It includes the following three classes:

  • PLVMarqueeView Marquee view, used to display the marquee
  • PLVMarqueeModel Marquee model, used to define the marquee style and animation
  • PLVMarqueeAnimationManager Marquee animation manager, responsible for providing animations to the marquee

For usage examples of the marquee, refer to the PLVCourseDetailController example in the demo.

10.1 Using the Marquee

10.1.1 Adding the Marquee

Add PLVMarqueeView to any location where the marquee needs to be displayed, for example, on the maskView in PLVVodSkinPlayerController (already added in the demo).

- (void)viewDidLoad {
    [super viewDidLoad];
    。。。。。。
  
    // 设置新版跑马灯(2.0)
    self.marqueeView = [[PLVMarqueeView alloc]init];
    self.marqueeView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    self.marqueeView.frame = self.maskView.bounds;
    [self.maskView addSubview:self.marqueeView];
    。。。。。。
}

10.1.2 Setting the Marquee Style and Animation Definition

Use PLVMarqueeModel to set the marquee style.

__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
      
    PLVMarqueeModel *marqueeModel = [[PLVMarqueeModel alloc]init];
    marqueeModel.style = PLVMarqueeModelStyleRoll;
    marqueeModel.content = @"Polyv跑马灯";
    marqueeModel.fontSize = 30;
    marqueeModel.fontColor = @"#000000";
    marqueeModel.outline = YES;
    marqueeModel.outlineColor = @"#000000";
    marqueeModel.shadowAlpha = 1;
    marqueeModel.shadowBlurRadius = 4;
    marqueeModel.shadowOffsetX = 2;
    marqueeModel.shadowOffsetY = 2;
    marqueeModel.alpha = 1;
    marqueeModel.tweenTime = 1;
    marqueeModel.interval = 5;
    marqueeModel.lifeTime = 3;
    marqueeModel.speed = 20;
    [weakSelf.player.marqueeView setPLVMarqueeModel:marqueeModel];
    weakSelf.player.marquee = nil; //移除旧版本的跑马灯
});

10.1.3 Controlling the Marquee

Monitor the player status callbacks to control starting, pausing, and stopping the marquee.

__weak typeof (self) weakSelf = self;
self.player.playbackStateHandler = ^(PLVVodPlayerViewController *player) {
    //跑马灯的控制
    if (player.playbackState == PLVVodPlaybackStatePlaying) {
        [weakSelf.player.marqueeView start];
    }else if (player.playbackState == PLVVodPlaybackStatePaused) {
        [weakSelf.player.marqueeView pause];
    }else if (player.playbackState == PLVVodPlaybackStateStopped) {
        [weakSelf.player.marqueeView stop];
    }
};

10.2 Supported Marquee Styles and Animation Definitions

Use PLVMarqueeModel to define the marquee style. Its properties are as follows:

#pragma mark - 内容属性

/// 跑马灯内容,默认”PLV跑马灯“
@property (nonatomic, strong) NSString *content;
/// 字体大小,默认30
@property (nonatomic, assign) NSUInteger fontSize;
/// 字体颜色,默认#000000
@property (nonatomic, strong) NSString *fontColor;
/// 自定义播放错误提示信息(跑马灯校验失败)
@property (nonatomic, strong) NSString *errorMessage;


#pragma mark - 描边属性

/// 是否描边,默认NO
@property (nonatomic, assign) BOOL outline;
/// 描边颜色,默认#000000
@property (nonatomic, strong) NSString *outlineColor;
/// 阴影透明度,(范围:0~1),默认1
@property (nonatomic, assign) float shadowAlpha;
/// 阴影半径,默认4
@property (nonatomic, assign) NSUInteger shadowBlurRadius;
/// 阴影水平偏移量,默认2
@property (nonatomic, assign) NSUInteger shadowOffsetX;
/// 描边垂直偏移量.默认2
@property (nonatomic, assign) NSUInteger shadowOffsetY;


#pragma mark - 动画相关属性

/// 文本透明度(范围:0~1),默认1
@property (nonatomic, assign) float alpha;
/// 文本渐隐渐现时间 (单位:秒),默认1,有效样式:Flash、PartFlash、DoubleFlash、RollFade
@property (nonatomic, assign) NSUInteger tweenTime;
/// 文本隐藏间隔时间 (单位:秒),默认5,有效样式:Flash、PartFlash、DoubleFlash
@property (nonatomic, assign) NSUInteger interval;
/// 文本显示时间 (单位:秒),默认3,有效样式:Flash、PartFlash、DoubleFlash
@property (nonatomic, assign) NSUInteger lifeTime;
/// 文字移动指定像素所需时间/显示时间(单位:秒),默认20,有效样式:Roll、RollFade、PartRoll、DoubleRoll
@property (nonatomic, assign) NSUInteger speed;


/// 暂停跑马灯的时候,是否隐藏。默认为YES
@property (nonatomic, assign) BOOL isHiddenWhenPause;
/// 跑马灯运行的时候,是否一直完整显示跑马灯。为YES时interval不生效。默认为NO
@property (nonatomic, assign) BOOL isAlwaysShowWhenRun;

Use PLVMarqueeModelStyle to define the movement type of the marquee. Its enumeration is as follows:

typedef NS_ENUM(NSUInteger, PLVMarqueeModelStyle) {
    /// 滚动(自屏幕右方至左方一直滚动)
    PLVMarqueeModelStyleRoll = 1,
    /// 闪烁(屏幕内随机位置闪烁)
    PLVMarqueeModelStyleFlash,
    /// 滚动+闪烁(自屏幕右方至左方一直滚动,渐隐渐现)
    PLVMarqueeModelStyleRollFade,
    /// 局部滚动(上下15%的视频区域之间滚动)
    PLVMarqueeModelStylePartRoll,
    /// 局部闪烁(上下15%的视频区域随机闪烁文字)
    PLVMarqueeModelStylePartFlash,
    /// 滚动(自屏幕右方至左方一直滚动)双跑马灯
    PLVMarqueeModelStyleDoubleRoll,
    /// 闪烁(屏幕内随机位置闪烁))双跑马灯
    PLVMarqueeModelStyleDoubleFlash,
};
联系客服,在线咨询