コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite.

概要

Game.loader.js:303 Invoking error handler due to
TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite.
at _startPlayback (http://localhost:63752/Build/Game.framework.js:2103:38)
    at MediaElementAudioSourceNode.source.start (http://localhost:63752/Build/Game.framework.js:2123:7)
    at Object.resume (http://localhost:63752/Build/Game.framework.js:2030:18)
    at _JS_Sound_SetPaused (http://localhost:63752/Build/Game.framework.js:2372:45)
    at SoundChannelInstance::UpdatePauseState() (http://localhost:63752/Build/Game.wasm:wasm-function[20205]:0x4c3cb8)
    at AudioSource::UpdatePauseState() (http://localhost:63752/Build/Game.wasm:wasm-function[20101]:0x4af929)
    at AudioModule::SetApplicationPause(bool) (http://localhost:63752/Build/Game.wasm:wasm-function[20321]:0x4cd50b)
    at SetPlayerPause(PlayerPause, bool) (http://localhost:63752/Build/Game.wasm:wasm-function[22260]:0x5ed405)
    at FocusCallback(int, EmscriptenFocusEvent const*, void*) (http://localhost:63752/Build/Game.wasm:wasm-function[22205]:0x5eacf8)
    at dynCall_iiii (http://localhost:63752/Build/Game.wasm:wasm-function[24026]:0x69a918)
    at http://localhost:63752/Build/Game.framework.js:1035:20
    at http://localhost:63752/Build/Game.framework.js:9030:24
    at Object.focusEventHandlerFunc [as handlerFunc] (http://localhost:63752/Build/Game.framework.js:9031:4)
    at jsEventHandler (http://localhost:63752/Build/Game.framework.js:8040:17)
Game.framework.js:2103 Uncaught TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite.
    at _startPlayback (:63752/Build/Game.framework.js:2103:38)
    at MediaElementAudioSourceNode.source.start (:63752/Build/Game.framework.js:2123:7)
    at Object.resume (:63752/Build/Game.framework.js:2030:18)
    at _JS_Sound_SetPaused (:63752/Build/Game.framework.js:2372:45)
    at SoundChannelInstance::UpdatePauseState() (:63752/Build/Game.wasm)
    at AudioSource::UpdatePauseState() (:63752/Build/Game.wasm)
    at AudioModule::SetApplicationPause(bool) (:63752/Build/Game.wasm)
    at SetPlayerPause(PlayerPause, bool) (:63752/Build/Game.wasm)
    at FocusCallback(int, EmscriptenFocusEvent const*, void*) (:63752/Build/Game.wasm)
    at dynCall_iiii (:63752/Build/Game.wasm)
    at :63752/Build/Game.framework.js:1035:20
    at :63752/Build/Game.framework.js:9030:24
    at Object.focusEventHandlerFunc [as handlerFunc] (:63752/Build/Game.framework.js:9031:4)
    at jsEventHandler (:63752/Build/Game.framework.js:8040:17)

Unity 2021.2.11f1 で WebGL ビルドしてゲームを起動して
AudioSource を再生した状態でフォーカスを外してから再度フォーカスしたら
上記のエラーが発生する現象に遭遇した

f:id:baba_s:20220216153924p:plain

Project Settings で Run in Background をオンにしてから WebGL ビルドしたら
エラーが発生しなくなった