Polyv Help Center

Help Center

barrageService

Updated: 2023-09-22 17:47:34

1. Create Video Barrage

Description

通过视频id与弹幕信息创建视频弹幕
接口地址(仅做说明使用):https://api.polyv.net/v2/danmu/%s/add

Call Constraints

  1. API calls are rate-limited. Click here for details. For common call exceptions, click here.

  2. The barrage feature requires contacting customer service to enable.

Unit Test

    @Test
    public void testCreateBarrage() throws IOException, NoSuchAlgorithmException {
        VodCreateBarrageRequest vodCreateBarrageRequest = new VodCreateBarrageRequest();
        VodCreateBarrageResponse vodCreateBarrageResponse = null;
        try {
            vodCreateBarrageRequest.setVideoId(super.getTestVideoId())
                    .setMsg("测试弹幕消息")
                    .setTime("00:00:08")
                    .setSessionId("88888888")
                    .setParam2("777777777")
                    .setFontSize(18)
                    .setFontMode("roll")
                    .setFontColor("0xFFFFFF");
            vodCreateBarrageResponse = new VodBarrageServiceImpl().createBarrage(vodCreateBarrageRequest);
            Assert.assertNotNull(vodCreateBarrageResponse);
            if (vodCreateBarrageResponse != null) {
                log.debug("测试创建视频弹幕成功,{}", JSON.toJSONString(vodCreateBarrageResponse));
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. If the request is correct, a VodCreateBarrageResponse object is returned. The B-end processes business logic based on this object.

  2. If request parameter validation fails, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed fields [pic cannot be empty / msg cannot be empty]].

  3. If the server encounters an error, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]

Request Parameter Description

Parameter Name Required Type Description
videoId true String Video ID [Corresponds to the vid field in the API documentation]
msg true String Barrage message
time true String Time when the barrage appears, format HH:mm:ss, e.g., 00:03:11
sessionId false String Session ID
param2 false String Custom parameter
fontSize false Integer Font size, default: 18
fontMode false String Display position, top: top, bottom: bottom, scroll: roll (default)
fontColor false String Font color, format 0xFFFFFF, default: 0xFFFFFF

Return Object Description

Parameter Name Type Description
id String Barrage ID [Corresponds to the Id field in the API documentation]






2. Upload VOD Barrage File

Description

通过视频id上传点播弹幕文件
接口地址(仅做说明使用):https://api.polyv.net/v2/danmu/%s/upload

Call Constraints

  1. API calls are rate-limited. Click here for details. For common call exceptions, click here.

  2. The barrage feature requires contacting customer service to enable.

Unit Test

    @Test
    public void testUploadBarrage() throws IOException, NoSuchAlgorithmException {
        VodUploadBarrageRequest vodUploadBarrageRequest = new VodUploadBarrageRequest();
        Boolean vodUploadBarrageResponse = null;
        try {
            String srtCN = getClass().getResource("/subtitle/srt(zh_CN).srt").getPath();
            vodUploadBarrageRequest.setVideoId(super.getTestVideoId())
                    .setFile(new File(srtCN));
            vodUploadBarrageResponse = new VodBarrageServiceImpl().uploadBarrage(vodUploadBarrageRequest);
            Assert.assertTrue(vodUploadBarrageResponse);
            if (vodUploadBarrageResponse) {
                log.debug("测试上传点播弹幕文件成功");
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. If the request is correct, a Boolean object is returned. The B-end processes business logic based on this object.

  2. If request parameter validation fails, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed fields [pic cannot be empty / msg cannot be empty]].

  3. If the server encounters an error, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]

Request Parameter Description

Parameter Name Required Type Description
videoId true String Video ID [Corresponds to the vid field in the API documentation]
file true File Barrage file, file format is srt, supports utf-8 encoding

Return Object Description

true indicates successful upload of the barrage file, false indicates failure.




3. Query Barrage Information

Description

通过视频id或分页参数查询用户下所有弹幕信息
接口地址(仅做说明使用):https://api.polyv.net/v2/danmu/%s

Call Constraints

  1. API calls are rate-limited. Click here for details. For common call exceptions, click here.

  2. The barrage feature requires contacting customer service to enable.

Unit Test

    @Test
    public void testQueryBarrageList() throws IOException, NoSuchAlgorithmException {
        VodQueryBarrageListRequest vodQueryBarrageListRequest = new VodQueryBarrageListRequest();
        VodQueryBarrageListResponse vodQueryBarrageListResponse = null;
        try {
            vodQueryBarrageListRequest.setVideoId("1b448be32345b255cabc3fe8d65a4d00_1");
            vodQueryBarrageListResponse = new VodBarrageServiceImpl().queryBarrageList(vodQueryBarrageListRequest);
            Assert.assertNotNull(vodQueryBarrageListResponse);
            if (vodQueryBarrageListResponse != null) {
                log.debug("测试查询弹幕信息成功,{}", JSON.toJSONString(vodQueryBarrageListResponse));
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. If the request is correct, a VodQueryBarrageListResponse object is returned. The B-end processes business logic based on this object.

  2. If request parameter validation fails, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed fields [pic cannot be empty / msg cannot be empty]].

  3. If the server encounters an error, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]

Request Parameter Description

Parameter Name Required Type Description
videoId false String Video vid. If provided, queries barrages for that specific video; if not, queries all barrages for the user. [Corresponds to the vid field in the API documentation]
currentPage false Integer Page number, default is 1 [Corresponds to the page field in the API documentation]
pageSize false Integer Number of data items per page, default is 20 items per page

Return Object Description

Parameter Name Type Description
contents Array Returned result set [See BarrageInfo Parameter Description for details]
pageSize Integer Number of data items per page, default is 20 items per page
currentPage Integer Current page [Corresponds to the pageNumber field in the API documentation]
totalItems Integer Total number of records
totalPage Integer Total number of pages [Corresponds to the totalPages field in the API documentation]
BarrageInfo Parameter Description
Parameter Name Type Description
id Integer Unique identifier for the barrage information
videoId String Video ID [Corresponds to the vid field in the API documentation]
userId String User ID [Corresponds to the userid field in the API documentation]
msg String Barrage message content
time String Time point when the barrage appears, format HH:mm:ss, e.g., 00:03:05
fontSize String Font size of the barrage content, e.g., 18 [Corresponds to the fontsize field in the API documentation]
fontMode String Scrolling mode of the barrage content, top: top, bottom: bottom, scroll: roll (default) [Corresponds to the fontmode field in the API documentation]
fontcolor String Font color of the barrage content
createTime Date Full time when the barrage content appeared, format: yyyy-MM-dd HH:mm:ss [Corresponds to the timestamp field in the API documentation]
sessionId String Custom parameter (a string not exceeding 64 characters), custom parameter passed when adding a barrage (e.g., the client's own user ID information) [Corresponds to the sessionid field in the API documentation]
param2 String Custom parameter (a string not exceeding 64 characters), custom parameter passed when adding a barrage (e.g., the client's own user ID information)






4. Batch Delete Barrage Information

Description

通过弹幕id批量删除弹幕信息
接口地址(仅做说明使用):https://api.polyv.net/v2/danmu/%s/delete

Call Constraints

  1. API calls are rate-limited. Click here for details. For common call exceptions, click here.

  2. The barrage feature requires contacting customer service to enable.

Unit Test

    @Test
    public void testDeleteBarrage() throws IOException, NoSuchAlgorithmException {
        VodDeleteBarrageRequest vodDeleteBarrageRequest = new VodDeleteBarrageRequest();
        Boolean vodDeleteBarrageResponse = null;
        try {
            //准备测试数据
            String barrageIds = super.getBarrageIdsByCreate();
            vodDeleteBarrageRequest.setBarrageIds(barrageIds);
            vodDeleteBarrageResponse = new VodBarrageServiceImpl().deleteBarrage(vodDeleteBarrageRequest);
            Assert.assertTrue(vodDeleteBarrageResponse);
            if (vodDeleteBarrageResponse) {
                log.debug("测试批量删除弹幕信息成功");
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. If the request is correct, a Boolean object is returned. The B-end processes business logic based on this object.

  2. If request parameter validation fails, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed fields [pic cannot be empty / msg cannot be empty]].

  3. If the server encounters an error, a PloyvSdkException is thrown. The error message can be obtained via PloyvSdkException.getMessage(), e.g., [Polyv request returned data error, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature.]

Request Parameter Description

Parameter Name Required Type Description
barrageIds true String Multiple barrage information IDs, separated by commas (English comma separator, half-width state), e.g., 123,456 [Corresponds to the danmuIds field in the API documentation]

Return Object Description

true indicates successful batch deletion of barrages, false indicates failure.

联系客服,在线咨询