HarmonyOS 虚拟机上通过C接口创建audiorender失败

HarmonyOS 虚拟机上通过C接口创建audiorender失败

HarmonyOS
2024-08-11 15:02:47
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

可参考demo实现:https://gitee.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/Native/Audio

其中低延时播放器初始化方法如下:

static napi_value AudioRendererLowLatencyInit(napi_env env, napi_callback_info info) 
{ 
  if (audioRenderer) { 
    OH_AudioRenderer_Release(audioRenderer); 
    OH_AudioStreamBuilder_Destroy(rendererBuilder); 
    audioRenderer = nullptr; 
    rendererBuilder = nullptr; 
  } 
  if (g_file) { 
    fclose(g_file); 
    g_file = nullptr; 
  } 
  g_file = fopen(g_filePath.c_str(), "rb"); 
  if (g_file == nullptr) { 
    return 0; 
  } 
  // create builder 
  OH_AudioStream_Type type = AUDIOSTREAM_TYPE_RENDERER; 
  OH_AudioStreamBuilder_Create(&rendererBuilder, type); 
  // set params and callbacks 
  OH_AudioStreamBuilder_SetSamplingRate(rendererBuilder, g_samplingRate); 
  OH_AudioStreamBuilder_SetChannelCount(rendererBuilder, g_channelCount); 
  OH_AudioStreamBuilder_SetLatencyMode(rendererBuilder, AUDIOSTREAM_LATENCY_MODE_FAST); 
  OH_AudioRenderer_Callbacks rendererCallbacks; 
  rendererCallbacks.OH_AudioRenderer_OnWriteData = AudioRendererOnWriteData; 
  OH_AudioStreamBuilder_SetRendererCallback(rendererBuilder, rendererCallbacks, nullptr); 
  // create OH_AudioRenderer 
  OH_AudioStreamBuilder_GenerateRenderer(rendererBuilder, &audioRenderer); 
  g_readEnd = false; 
  g_rendererLowLatency = true; 
  return nullptr; 
}
分享
微博
QQ
微信
回复
2024-08-11 21:34:24
相关问题
虚拟机上运行不了鸿蒙项目
6694浏览 • 1回复 待解决
虚拟机mysql连不上怎么回事?
2232浏览 • 1回复 待解决
api version6 是不是只能在虚拟机
6715浏览 • 2回复 已解决
javaUI 中webview通过布局创建实例失败
5610浏览 • 1回复 待解决
ArkTS层通过接口访问C++层对象
371浏览 • 1回复 待解决
HarmonyOS 创建相机预览失败
596浏览 • 1回复 待解决