小游戏录屏在转发报文件不存在错误
747 浏览2020年01月15日作者:fantasyfancy

报错截图或相关BUG
在此处粘贴截图

复现步骤

  • 录屏结束生成 ttfile://temp/shareVideo.mp4
  • 调用clipVideo接口生成 ttfile://temp/merged.mp4
  • 调用shareAppMessage 提示分享失败 报错信息:{"errMsg":"shareAppMessage:fail file not exist path:ttfile://temp/merged.mp4""}




//录屏分享相关代码

        /**注册录屏相关事件 */
        registerRecord() {
            if (UserInfo.isTT()) {
                this.recorder = this.getWX().getGameRecorderManager();
            } else if (UserInfo.isBaidu()) {
                this.recorder = this.getWX().getVideoRecorderManager();
            }
            LogsManager.echo("yrc registerRecord ", this.recorder);
            this.recorder.onStart(res => {
                this.onStartRecord(res);
            })

            this.recorder.onStop(res => {
                this.onStopRecord(res);
            })

            this.recorder.onError(res => {
                LogsManager.echo("yrc 录屏 onError", JSON.stringify(res));
            })
        }

        /**对开始录屏注册事件 */
        onStartRecord(res: any) {
            LogsManager.echo("yrc 开始录屏")
            LogsManager.echo(res);
            this._startCallback && this._startCallback.call(this._startThisObj);
            this._startCallback = null;
            this._recordStartT = kakura.Client.instance.serverTime;
        }

        /**对结束录屏注册事件 */
        onStopRecord(res: any) {
            LogsManager.echo("yrc 结束录屏", JSON.stringify(res));
            let curT = kakura.Client.instance.serverTime;
            if (curT - this._recordStartT < 4) {
                ToolTip.instance.setFlyText("录屏时间不足,请重新录屏");
                this._recordStartT = 0;
                this._endCallback && this._endCallback.call(this._startThisObj, false);
                return;
            }
            this._videoPath = res.videoPath;
            this._endCallback && this._endCallback.call(this._startThisObj, true);
            if (UserInfo.isTT()) {
                // 头条渠道裁剪视频截取最后N秒内容。百度由于clipVideo耗时过慢不进行裁剪
                this.clipVideo();
            }
        }


        /**开始录屏 */
        recordStart(callback: Function = null, thisObj: any = null, endCallback: Function = null, durT: number = 300, recordTimeRange: any = null) {
            // 录屏时长最大120秒
            if (UserInfo.isTT()) {
                durT = Math.min(durT, 300);
            } else if (UserInfo.isBaidu()) {
                durT = Math.min(durT, 120);
            }
            LogsManager.echo("yrc tt recordStart", durT);
            this._startCallback = callback;
            this._startThisObj = thisObj;
            if (endCallback) {
                this._endCallback = endCallback;
            }
            if (recordTimeRange) {
                this._recordTimeRange = recordTimeRange;
            }
            this.recorder.start({
                duration: durT,
            })
        }
        /**结束录屏 */
        recordStop() {
            if (this.recorder) {
                LogsManager.echo("yrc tt recordStop");
                this.recorder.stop();
            }
        }

        //暂停录屏
        recordPause() {
            this.recorder.pause();
        }

        //继续录屏
        recordResume() {
            this.recorder.resume();
        }

        /**对视频进行剪辑 */
        clipVideo() {
            if (!this.recorder) return;
            if (!this._videoPath) return;
            let videoPath = this._videoPath;
            LogsManager.echo("yrc clipVideo path:", videoPath)
            var thisObj = this
            var clipObj = {
                path: videoPath,
                success(res) {
                    LogsManager.echo("yrc clipvideo succ", JSON.stringify(res));
                    thisObj._videoPath = res.videoPath;
                    UserInfo.platform.isHaveRecord = true;
                }, fail(err) {
                    LogsManager.echo('yrc clipvideo fail', JSON.stringify(err));
                }
            }
            if (this._recordTimeRange) {
                clipObj['timeRange'] = this._recordTimeRange;
            }
            this.recorder.clipVideo(clipObj)
        }

        /**对剪辑的视频进行分享 */
        shareVideo(callBack: Function = null, thisObj = null) {
            LogsManager.echo('shareVideo 开始!', this._videoPath);
            let myThis = this;
            // 随机两个标题
            var title_num = Math.random() > 0.5 ? '1' : '2';
            var title = TranslateFunc.instance.getTranslate("#tid_shareVideoTitle_" + title_num, 'TranslateGlobal');
            if (UserInfo.isBaidu()) {
                this.getWX().shareVideo({
                    videoPath: this._videoPath,
                    title: title,
                    success() {
                        LogsManager.echo('shareVideo 分享成功!');
                        UserInfo.platform.isHaveRecord = false;
                        // myThis._videoPath = null;
                        //分享成功
                        callBack && callBack.call(thisObj, true);
                    },
                    fail(e) {
                        LogsManager.echo('shareVideo 分享失败!', JSON.stringify(e));
                        callBack && callBack.call(thisObj, false);
                        // myThis._videoPath = null;
                    },
                    complete(e) {
                        LogsManager.echo("shareVideo complete", e);
                        // myThis._videoPath = null;
                    }
                });
            } else if (UserInfo.isTT()) {
                var extra = {
                    videoPath: this._videoPath, // 可替换成录屏得到的视频地址
                }
                if (UserInfo.platform.getSystemInfo().appName == "Douyin") {
                    // 话题
                    extra['videoTopics'] = ShareConst.DOUYIN_VIDEO_TOPICS;
                    if (GameConsts.gameName) {
                        extra['videoTopics'].unshift(GameConsts.gameName);
                    }
                } else if (UserInfo.platform.getSystemInfo().appName == "Toutiao") {
                    // 挑战视频
                    extra['createChallenge'] = true;
                }
                this.getWX().shareAppMessage({
                    channel: "video",
                    title: "测试标题",
                    desc: title,
                    extra: extra,
                    success() {
                        LogsManager.echo('shareVideo 分享成功!');
                        UserInfo.platform.isHaveRecord = false;
                        // myThis._videoPath = null;
                        //分享成功
                        callBack && callBack.call(thisObj, true);
                        // 兼容大刀 发送回调
                        Message.instance.send(ControlConst.TT_SHARE_SUCC, this);
                    },
                    fail(e) {
                        LogsManager.echo('shareVideo 分享失败!', JSON.stringify(e));
                        callBack && callBack.call(thisObj, false);
                        // 兼容大刀 发送回调
                        Message.instance.send(ControlConst.TT_SHARE_FAIL, this);
                        // myThis._videoPath = null;
                    }
                });
            }

        }

最后一次编辑于 2020 年 01 月 16 日
1 条评论

相关文章

专题推荐

热门文章

热门问答