diff --git a/ohos-project/entry/oh-package.json5 b/ohos-project/entry/oh-package.json5 index 6f851a79ebe31f104ce352d7dd6f7b0ce313fd26..e1de7ce8bc19844daa970a81defa3b8f407f94e7 100644 --- a/ohos-project/entry/oh-package.json5 +++ b/ohos-project/entry/oh-package.json5 @@ -1,12 +1,11 @@ { "license": "", - "devDependencies": { - "@types/libnativerender.so": "file:./src/main/cpp/types/libnativerender" - }, "author": "", "name": "entry", "description": "Please describe the basic information.", "main": "", "version": "1.0.0", - "dependencies": {} + "dependencies": { + "@types/libSDL2d.so": "file:./src/main/cpp/types/libSDL2d" + } } diff --git a/ohos-project/entry/src/main/cpp/types/libSDL2d/index.d.ts b/ohos-project/entry/src/main/cpp/types/libSDL2d/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..b8ee7f0661ffda237f763cf5f67cc5e4d2a863f6 --- /dev/null +++ b/ohos-project/entry/src/main/cpp/types/libSDL2d/index.d.ts @@ -0,0 +1,3 @@ +export const nativeSetupNAPI: () => void; +export const registerCallback: () => void; +export const sdlAppEntry: () => void; \ No newline at end of file diff --git a/ohos-project/entry/src/main/cpp/types/libSDL2d/oh-package.json5 b/ohos-project/entry/src/main/cpp/types/libSDL2d/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..840d1469d4cb464328508e4cf54729b7243af728 --- /dev/null +++ b/ohos-project/entry/src/main/cpp/types/libSDL2d/oh-package.json5 @@ -0,0 +1,6 @@ +{ + "name": "libSDL2d.so", + "types": "./index.d.ts", + "version": "", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ohos-project/entry/src/main/ets/service/InvokeNative.ts b/ohos-project/entry/src/main/ets/service/InvokeNative.ts index ab6525d5dc370f82559b323d38bdab61c804ef87..7df0a5caba75a0442e8ea27708dbd6fc2823df33 100644 --- a/ohos-project/entry/src/main/ets/service/InvokeNative.ts +++ b/ohos-project/entry/src/main/ets/service/InvokeNative.ts @@ -22,7 +22,7 @@ export function onNativeSoftReturnKey() { export function nativeSendQuit() { console.log("nativeSendQuit") - sdl.nativeSendQuit + sdl.nativeSendQuit() } export function nativeQuit() { @@ -32,22 +32,22 @@ export function nativeQuit() { export function onNativeResize() { console.log("OnNativeResize") - sdl.onNativeResize + sdl.onNativeResize() } export function onNativeKeyboardFocusLost() { console.log("sdl.OnNativeKeyboardFocusLost"); - sdl.onNativeKeyboardFocusLost + sdl.onNativeKeyboardFocusLost() } export function nativePause() { console.log("OHOS_NAPI_nativePause") - sdl.nativePause + sdl.nativePause() } export function nativeResume() { console.log("NativeResume"); - sdl.nativeResume + sdl.nativeResume() } export function onNativeOrientationChanged(orientation: number) { diff --git a/ohos-project/entry/src/main/module.json5 b/ohos-project/entry/src/main/module.json5 index 38a933366098daa55025871eb25f76a7b08c6bd9..a88f0c4d3ec1da76c50f978e311634c96d65c873 100644 --- a/ohos-project/entry/src/main/module.json5 +++ b/ohos-project/entry/src/main/module.json5 @@ -21,7 +21,8 @@ "EntryAbility" ], "when": "inuse" - } + }, + "reason": "$string:aware" }, { "name": "ohos.permission.LOCATION", @@ -30,7 +31,8 @@ "EntryAbility" ], "when": "inuse" - } + }, + "reason": "$string:aware" }, { "name": "ohos.permission.MICROPHONE", @@ -38,8 +40,9 @@ "abilities": [ "EntryAbility" ], - "when": "inuse" - } + "when": "inuse", + }, + "reason": "$string:aware" }, ], diff --git a/ohos-project/entry/src/main/resources/base/element/string.json b/ohos-project/entry/src/main/resources/base/element/string.json index 86623f3988d4b6caae928d032b1748fbb48eaba5..1054297fc9e74fea4021297eec727b7cf195ec71 100644 --- a/ohos-project/entry/src/main/resources/base/element/string.json +++ b/ohos-project/entry/src/main/resources/base/element/string.json @@ -19,6 +19,10 @@ { "name": "button_text", "value": "Draw Rectangle" + }, + { + "name": "aware", + "value": "Request permission" } ] } \ No newline at end of file diff --git a/ohos-project/entry/src/main/resources/en_US/element/string.json b/ohos-project/entry/src/main/resources/en_US/element/string.json index 86623f3988d4b6caae928d032b1748fbb48eaba5..1054297fc9e74fea4021297eec727b7cf195ec71 100644 --- a/ohos-project/entry/src/main/resources/en_US/element/string.json +++ b/ohos-project/entry/src/main/resources/en_US/element/string.json @@ -19,6 +19,10 @@ { "name": "button_text", "value": "Draw Rectangle" + }, + { + "name": "aware", + "value": "Request permission" } ] } \ No newline at end of file diff --git a/ohos-project/entry/src/main/resources/zh_CN/element/string.json b/ohos-project/entry/src/main/resources/zh_CN/element/string.json index 0b4b9807fa0bb04dc19bd3a72bddf2255fd47e32..b1b62b9d6e054b8115de494c9226d9a3586117ec 100644 --- a/ohos-project/entry/src/main/resources/zh_CN/element/string.json +++ b/ohos-project/entry/src/main/resources/zh_CN/element/string.json @@ -19,6 +19,10 @@ { "name": "button_text", "value": "绘制矩形" + }, + { + "name": "aware", + "value": "请求权限" } ] } \ No newline at end of file diff --git a/src/audio/ohos/SDL_ohosaudio.h b/src/audio/ohos/SDL_ohosaudio.h index 996b1a591a16f94457519db86d26c60b7c4c7e59..ec745de9839558ce2f3723367fbd2004cdf0af11 100644 --- a/src/audio/ohos/SDL_ohosaudio.h +++ b/src/audio/ohos/SDL_ohosaudio.h @@ -37,6 +37,9 @@ struct SDL_PrivateAudioData void OHOSAUDIO_ResumeDevices(void); void OHOSAUDIO_PauseDevices(void); +extern void OHOSAUDIO_PageResume(void); +extern void OHOSAUDIO_PagePause(void); + #endif /* SDL_ohosaudio_h_ */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/audio/ohos/SDL_ohosaudiomanager.c b/src/audio/ohos/SDL_ohosaudiomanager.c index e858400a14ba729e48edb0d9885e988ccd614455..1e56ced1858ae0429608468cb73cdf7e1fe98285 100644 --- a/src/audio/ohos/SDL_ohosaudiomanager.c +++ b/src/audio/ohos/SDL_ohosaudiomanager.c @@ -52,6 +52,8 @@ static SDL_bool audioPlayCondition = SDL_FALSE; static SDL_mutex *audioPlayLock; static SDL_cond *audioPlayCond; +static OH_AudioStream_State gAudioRendorStatus; + /* * Audio Capturer Callbacks */ @@ -548,18 +550,17 @@ int OHOSAUDIO_NATIVE_CaptureAudioBuffer(void *buffer, int buflen) OH_AudioCapturer_GetCurrentState(audioCapturer, &iStatus); if (AUDIOSTREAM_STATE_PAUSED == iStatus) { OH_AudioCapturer_Start(audioCapturer); - } + } OHOS_AUDIOBUFFER_ReadCaptureBuffer(buffer, buflen); return buflen; } void OHOSAUDIO_NATIVE_FlushCapturedAudio(void) { OH_AudioStream_State iStatus; - OH_AudioCapturer_Flush(audioCapturer); OH_AudioCapturer_GetCurrentState(audioCapturer, &iStatus); if (AUDIOSTREAM_STATE_RUNNING == iStatus) { OH_AudioCapturer_Pause(audioCapturer); - } + } OHOS_AUDIOBUFFER_FlushBuffer(); return; } @@ -616,16 +617,15 @@ void OHOSAUDIO_NATIVE_CloseAudioDevice(const int iscapture) { // 销毁构造器 if(iscapture){ - if (NULL != builder2) { - iRet = OH_AudioStreamBuilder_Destroy(builder2); - if (AUDIOSTREAM_SUCCESS != iRet) { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "CloseAudioDevice", + if (NULL != builder2) { + iRet = OH_AudioStreamBuilder_Destroy(builder2); + if (AUDIOSTREAM_SUCCESS != iRet) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "CloseAudioDevice", "SDL audio: OH_AudioStreamBuilder_Destroy error,error code = %{public}d", iRet); + } + builder2 = NULL; } - builder2 = NULL; - } - } - else{ + } else { if (NULL != builder) { iRet = OH_AudioStreamBuilder_Destroy(builder); if (AUDIOSTREAM_SUCCESS != iRet) { @@ -633,8 +633,23 @@ void OHOSAUDIO_NATIVE_CloseAudioDevice(const int iscapture) { "SDL audio: OH_AudioStreamBuilder_Destroy error,error code = %{public}d", iRet); } builder = NULL; - } + } OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "CloseAudioDevice", "close device leave..."); return; -}} + } +} + +void OHOSAUDIO_PageResume(void) +{ + if (audioRenderer != NULL && gAudioRendorStatus == AUDIOSTREAM_STATE_RUNNING) { + OH_AudioRenderer_Start(audioRenderer); + } +} + +void OHOSAUDIO_PagePause(void) +{ + if (audioRenderer != NULL) { + OH_AudioRenderer_GetCurrentState(audioRenderer, &gAudioRendorStatus); + } +} diff --git a/src/core/ohos/SDL_ohos.cpp b/src/core/ohos/SDL_ohos.cpp index 8a688e1b77eaec4dae193ca86a07582bfda3b9f1..5f8529adf8d8611c9c45385fd05ec4d83fcf0148 100644 --- a/src/core/ohos/SDL_ohos.cpp +++ b/src/core/ohos/SDL_ohos.cpp @@ -25,6 +25,7 @@ extern "C" { #include "../events/../../events/SDL_events_c.h" #include "../events/../../events/SDL_keyboard_c.h" #include "../../video/ohos/SDL_ohosvideo.h" +#include "../../audio/ohos/SDL_ohosaudio.h" #include "SDL_ohos.h" #include "SDL_quit.h" #include "SDL_ohos.h" @@ -581,12 +582,14 @@ napi_value SDLNapi::OHOS_NativeQuit(napi_env env, napi_callback_info info) napi_value SDLNapi::OHOS_NativeResume(napi_env env, napi_callback_info info) { SDL_SemPost(OHOS_ResumeSem); + OHOSAUDIO_PageResume(); return nullptr; } napi_value SDLNapi::OHOS_NativePause(napi_env env, napi_callback_info info) { SDL_SemPost(OHOS_PauseSem); + OHOSAUDIO_PagePause(); return nullptr; } @@ -705,7 +708,7 @@ napi_module OHOSNapiModule = { .nm_flags = 0, .nm_filename = nullptr, .nm_register_func = SDLNapiInit, - .nm_modname = "SDLNapi", + .nm_modname = "SDL2d", .nm_priv = ((void *)0), .reserved = {0}, };