-
Notifications
You must be signed in to change notification settings - Fork 6
avplayer binding #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
这些绑定经过真机测试码?据我们所知,Marshall.GetFunctionPointerForDelegate是无法在除鸿蒙PC和模拟器以外的鸿蒙系统中工作的 |
WCKYWCKF
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
存疑
|
我真机测试的,可以 |
|
|
||
| namespace OpenHarmony.NDK.Bindings.Media_Kit.AVPlayer | ||
| { | ||
| public unsafe delegate void OH_AVPlayerOnInfo(OH_AVPlayer* player, AVPlayerOnInfoType type, int extra); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你有使用这个回调码?如何使用的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
调用的另外一个,这个可以
public unsafe delegate void OH_AVPlayerOnErrorCallback(OH_AVPlayer* player, int errorCode, nint errorMsg, void* userData);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那个应该是api12开始废弃的接口没测试
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
除了鸿蒙PC和模拟器外鸿蒙不允许为匿名内存申请执行权限。你是怎么使用的这些delegate 声明的回调?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private void PlaySound(string url)
{
_player = OH_AVPlayer.OH_AVPlayer_Create();
OH_AVPlayerOnErrorCallback callback = (p, error, msg, userdata) =>
{
Logger.LogError("music", "error:" + error + " " + Marshal.PtrToStringAnsi(msg));
};
var back = Marshal.GetFunctionPointerForDelegate(callback);
var code = OH_AVPlayer.OH_AVPlayer_SetOnErrorCallback(_player, back, IntPtr.Zero);
if (code != OH_AVErrCode.AV_ERR_OK)
{
Logger.LogError("music", "errorCallBack " + code);
}
OH_AVPlayerOnInfoCallback infoback = (p, type, body, userdata) =>
{
Logger.Log("music", "type:" + type);
};
var infoBack = Marshal.GetFunctionPointerForDelegate(infoback);
code = OH_AVPlayer.OH_AVPlayer_SetOnInfoCallback(_player, infoBack, IntPtr.Zero);
if (code != OH_AVErrCode.AV_ERR_OK)
{
Logger.LogError("music", "infoCallBack " + code);
}
code = OH_AVPlayer.OH_AVPlayer_SetURLSource(_player, url);
if (code != OH_AVErrCode.AV_ERR_OK)
{
Logger.LogError("music", "url " + code);
}
code = OH_AVPlayer.OH_AVPlayer_SetAudioRendererInfo(_player, OH_AudioStream_Usage.AUDIOSTREAM_USAGE_GAME);
if (code != OH_AVErrCode.AV_ERR_OK)
{
Logger.LogError("music", "render " + code);
}
code = OH_AVPlayer.OH_AVPlayer_SetLooping(_player, OpenHarmony.NDK.Bindings.OH_Bool.True);
if (code != OH_AVErrCode.AV_ERR_OK)
{
Logger.LogError("music", "loop " + code);
}
code = OH_AVPlayer.OH_AVPlayer_Prepare(_player);
if (code != OH_AVErrCode.AV_ERR_OK)
{
Logger.LogError("music", "prepare " + code);
}
int duration = 0;
code = OH_AVPlayer.OH_AVPlayer_GetDuration(_player, &duration);
if (code != OH_AVErrCode.AV_ERR_OK)
{
Logger.LogError("music", "GetDuration " + code);
}
else
{
Logger.Log("music", "duration:" + duration);
}
code = OH_AVPlayer.OH_AVPlayer_Play(_player);
if (code != OH_AVErrCode.AV_ERR_OK)
{
Logger.LogError("music", "play " + code);
}
}这么写的
|
不建议将这部分代码提交到仓库中,因为我们将在Marshall问题解决之后通过工具重新生成所有NDK能力的C API绑定。建议将这部分代码暂时的库嵌入到项目中,以免被中断性变更影响项目开发。你可以订阅组织的Discussions获得版本发布通知,届时再依赖OpenHarmony.NDK.Bindings也不迟。 |

No description provided.