XComponent({id:'xComponent', type: XComponentType.SURFACE,controller:this.xComponentController})
.width(360)
.height(360)
.onLoad (()=> {
this.surfaceID = this.xComponentController.getXComponentSurfaceId()
})需要先从ArkTs侧向Native侧传入Surfaceid
size_t argc = 2;
napi_value args[2] = {nullptr};
int64_t surfaceId;
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
napi_status status = napi_get_value_int64(env, args[1], &surfaceId);
OH_NativeWindow_CreateNativeWindowFromSurfaceId (surfaceId, &DemoNdkPlayer::nativeWindow );Native侧通过Id生成对应的nativeWindow,用到了OH_NativeWindow_CreateNativeWindowFromSurfaceId方法
case AV_INITIALIZED:
ret = OH_AVPlayer_SetVideoSurface(player, DemoNdkPlayer::nativeWindow); // 设置视频播放 surface。
LOG("OH_AVPlayer_SetVideoSurface ret:%{public}d", ret);
ret = OH_AVPlayer_Prepare(player); //设置播放源后触发该状态上报。
if (ret != AV_ERR_OK) {
// 处理异常。
}
break;最后在回调中设置nativeWindow
使用AVPlayer播放视频(C/C++) 查看官方文档中指南即可使用AVPlayer播放视频(C/C++)-播放-媒体开发指导(C/C++)-Media Kit(媒体服务)-媒体 - 华为HarmonyOS开发者 (huawei.com)








































苏公安网备 32011402010933号