unity调用录屏无反应
524 浏览2023年08月28日作者:zpc97

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public delegate void OnVideoAdCloseCallBack();

public delegate void OnVideoAdErrorCallBack();

public class mysdk : MonoBehaviour

{

double startRecordTime=0;

public double endRecordTime=0;

private static mysdk _instance;

public static mysdk Instance

{

get

{

if (_instance == null)

{

_instance = new GameObject("ByteGameAdManager").AddComponent<mysdk>();

DontDestroyOnLoad(_instance.gameObject);

}

return _instance;

}

}

private StarkSDKSpace.StarkAdManager starkAdManager;

private StarkSDKSpace.StarkGameRecorder starkGamerRecorder;

public string[] rewardId = new string[] { "21cekgjichk05p54ji", "1i46gah1dcbb72n1s8", "2kalwjwarcg5l007hl" };

public string bannerId = "4f08ml2f1a81vsqvbg";

private void Awake()

{

_instance = this;

DontDestroyOnLoad(_instance.gameObject);

starkAdManager = StarkSDKSpace.StarkSDK.API.GetStarkAdManager();

starkGamerRecorder = StarkSDKSpace.StarkSDK.API.GetStarkGameRecorder();

}

/// <summary>

/// 播放激励视频广告

/// </summary>

/// <param name="adId"></param>

/// <param name="closeCallBack"></param>

/// <param name="errorCallBack"></param>

public void ShowVideoAd(System.Action<bool> closeCallBack, System.Action<int, string> errorCallBack)

{

#if UNITY_EDITOR

closeCallBack(true);

return;

#endif

if (starkAdManager != null)

{

int random=Random.Range(0, rewardId.Length);

starkAdManager.ShowVideoAdWithId(rewardId[random], closeCallBack, errorCallBack);

}

}

/// <summary>

/// 播放插屏广告

/// </summary>

/// <param name="adId"></param>

/// <param name="errorCallBack"></param>

/// <param name="closeCallBack"></param>

public void ShowInterstitialAd(string adId, System.Action<int, string> errorCallBack, System.Action closeCallBack)

{

if (starkAdManager != null)

starkAdManager.CreateInterstitialAd(adId, errorCallBack, closeCallBack);

}

public void startRecord()

{

#if UNITY_EDITOR

return;

#endif

if (starkGamerRecorder != null)

{

//Util.showAlertBox("startRecord");

startRecordTime=Util.getNowTime();

bool isStart = starkGamerRecorder.StartRecord(true, 600, () =>

{

Util.showAlertBox("开始录屏");

}, (int err,string msg) => {

Util.showAlertBox("录屏失败"+err + ":" + msg);

}, (string msg) =>

{

Util.showAlertBox("录屏成功"+msg);

});

Util.showAlertBox("是否开始录屏:"+ isStart);

}

}

public void stopRecord()

{

#if UNITY_EDITOR

return;

#endif

if (starkGamerRecorder != null)

{

//Util.showAlertBox("stopRecord");

endRecordTime = Util.getNowTime();

starkGamerRecorder.StopRecord((string msg) => {

Util.showAlertBox("stopRecord Complete:"+msg);

},(int code,string msg) =>

{

Util.showAlertBox("stopRecord fail:"+ code + ":" + msg);

});

}

}

public void shareRecord()

{

#if UNITY_EDITOR

return;

#endif


if (endRecordTime == 0 || startRecordTime == 0)

{

Util.showAlertBox("当前无录屏资源");

return;

}

if (endRecordTime - startRecordTime < 3)

{

Util.showAlertBox("录屏时间小于3s");

return;

}

Util.showAlertBox("shareRecord");

starkGamerRecorder.ShareVideoWithTitleTopics((Dictionary<string,object> aa) => {

Util.showAlertBox("分享成功");

}, (string msg) =>{

Util.showAlertBox("分享失败" + msg);

}, null, "", null);

}

}




代码如上 调用StartRecord无任何反应 调用StopRecord提示 record not start

最后一次编辑于 2023 年 08 月 28 日
4 条评论

相关问答

专题推荐

热门文章

热门问答