HarmonyOS 鸿蒙Next:使用AVPlayer播放音乐在调用OH_AVPlayer_Perpare后触发ONError回调,报错内容:Your GStreamer installation is missing a plug-in

发布于 1周前 作者 phonegap100 来自 鸿蒙OS

HarmonyOS 鸿蒙Next:使用AVPlayer播放音乐在调用OH_AVPlayer_Perpare后触发ONError回调,报错内容:Your GStreamer installation is missing a plug-in

#include “napi/native_api.h” #include <hilog/log.h> #include <multimedia/player_framework/avplayer.h> #include <multimedia/player_framework/avplayer_base.h> #include <multimedia/player_framework/native_averrors.h> #include <rawfile/raw_file.h> #include <rawfile/raw_file_manager.h>

NativeResourceManager* assetManager;

void OnInfo(OH_AVPlayer *player, AVPlayerOnInfoType type, int extra) { const char *url; int ret; switch (type) { case AV_INFO_TYPE_STATE_CHANGE: switch (extra) { case AV_IDLE: { OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] state AV_IDLE”); } break; case AV_INITIALIZED: { OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] state AV_INITIALIZED”); ret = OH_AVPlayer_Prepare(player); } break; case AV_PREPARED: { OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] state AV_PREPARED”); ret = OH_AVPlayer_Play(player); } break; case AV_PLAYING: { OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] state AV_PLAYING”); } break; case AV_PAUSED: { OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] state AV_PAUSED”); } break; case AV_COMPLETED: { OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] state AV_COMPLETED”); ret = OH_AVPlayer_Stop(player); } break; case AV_STOPPED: { OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] state AV_STOPPED”); ret = OH_AVPlayer_Reset(player); } break; } break; case AV_INFO_TYPE_POSITION_UPDATE: break; default: break; } }

void OnError(OH_AVPlayer *player, int errorCode, const char *errorMsg) { //estarx_sdk_log(ESTARX_LOG_ERR, “[AVPlayer] error %d, msg %s”, errorCode, errorMsg); OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] error %{public}d msg %{public}s”, errorCode, errorMsg); }

int create_native_audio(NativeResourceManager* assetManager) { OH_LOG_Print(LOG_APP, LOG_ERROR, 1, “AVPlayer”, “[AVPlayer] create”);

OH_AVPlayer *player = OH_AVPlayer_Create();

AVPlayerCallback callback;
callback.onInfo = OnInfo;
callback.onError = OnError;

int ret = OH_AVPlayer_SetPlayerCallback(player, callback);
if (ret != AV_ERR_OK) {
    OH_LOG_Print(LOG_APP, LOG_ERROR, 1, "AVPlayer", "[AVPlayer] set callback failure");
    return -2;
}
AVPlayerState state;
ret = OH_AVPlayer_GetState(player, &state);
if (ret != AV_ERR_OK) {
    OH_LOG_Print(LOG_APP, LOG_ERROR, 1, "AVPlayer", "[AVPlayer] get state failure");
    return -2;
}
if (state != AV_IDLE)
    OH_AVPlayer_Reset(player);

RawFile *rawFile = OH_ResourceManager_OpenRawFile(assetManager, "1.mp3");
RawFileDescriptor des;
bool res = OH_ResourceManager_GetRawFileDescriptor(rawFile, des);
if (res) {
    OH_LOG_Print(LOG_APP, LOG_ERROR, 1, "AVPlayer", "[AVPlayer] des length %{public}d", des.length);
    ret = OH_AVPlayer_SetFDSource(player, des.fd, 0, des.length);
    if (ret != AV_ERR_OK) {
        OH_LOG_Print(LOG_APP, LOG_ERROR, 1, "AVPlayer", "[AVPlayer] set fd failure");
    }
    OH_ResourceManager_ReleaseRawFileDescriptor(des);
}

return 0;

}

static napi_value Add(napi_env env, napi_callback_info info) { size_t requireArgc = 3; size_t argc = 3; napi_value args[3] = {nullptr};

napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);

napi_valuetype valuetype0;
napi_typeof(env, args[0], &valuetype0);

napi_valuetype valuetype1;
napi_typeof(env, args[1], &valuetype1);

assetManager = OH_ResourceManager_InitNativeResourceManager(env, args[2]);
create_native_audio(assetManager);

double value0;
napi_get_value_double(env, args[0], &value0);

double value1;
napi_get_value_double(env, args[1], &value1);

napi_value sum;
napi_create_double(env, value0 + value1, &sum);

return sum;

}

EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor desc[] = { { “add”, nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); return exports; } EXTERN_C_END

static napi_module demoModule = { .nm_version = 1, .nm_flags = 0, .nm_filename = nullptr, .nm_register_func = Init, .nm_modname = “entry”, .nm_priv = ((void*)0), .reserved = { 0 }, };

extern “C” attribute((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }


更多关于HarmonyOS 鸿蒙Next:使用AVPlayer播放音乐在调用OH_AVPlayer_Perpare后触发ONError回调,报错内容:Your GStreamer installation is missing a plug-in的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

OH 4.0.2.2版本后fd为hap包的fd, offset传0就是从hap包文件头开始读的,此时访问rawfile文件需要{fd, offset, length},需要修改成这样:

ret = OH_AVPlayer_SetFDSource(player, des.fd, des.start, des.length);

更多关于HarmonyOS 鸿蒙Next:使用AVPlayer播放音乐在调用OH_AVPlayer_Perpare后触发ONError回调,报错内容:Your GStreamer installation is missing a plug-in的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


针对您提到的HarmonyOS鸿蒙Next系统中使用AVPlayer播放音乐时,在调用OH_AVPlayer_Prepare后触发OnError回调,并报错“Your GStreamer installation is missing a plug-in”的问题,这通常意味着GStreamer框架中缺少了必要的插件来支持特定的音频或视频格式。

在鸿蒙系统中,GStreamer是处理多媒体播放的核心组件。当尝试播放一个不支持的格式时,系统会因为没有相应的解码插件而报错。

解决此问题的方法通常涉及以下几个步骤:

  1. 确认音频格式:首先确认您尝试播放的音频文件的格式是否被GStreamer支持。

  2. 安装缺失插件:如果确定是因为缺少插件,您需要查找并安装相应的GStreamer插件。在鸿蒙系统中,这可能需要特定的包管理工具或访问特定的软件仓库。

  3. 更新GStreamer:确保您的GStreamer版本是最新的,因为新版本可能包含了更多格式的支持。

  4. 检查系统配置:有时候,系统配置问题也可能导致插件无法正确加载。检查相关配置,确保没有阻止插件的使用。

如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html

回到顶部