Unity C#Android音频延迟

时间:2018-08-16 15:16:17

标签: c# android unity3d audio

在使用内置的统一资源时,我一直在与这种音频延迟作斗争。我一直在尝试按照本帖子(https://forum.unity.com/threads/android-sound-latency-fix.319943/)使其本机运行。我可以使音频统一工作,但不能在android上工作。我在Resources / Sounds和StreamingAssets / Resources / Sounds文件夹中都有声音文件。这两个脚本都放置在场景中的游戏对象上以进行初始化。这是我用来调用声音的脚本。 OnTest()只是链接到屏幕上的按钮。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class temp : MonoBehaviour {

// Use this for initialization
void Start () {
    int soundId = AudioCenter.loadSound("screech");
    AudioCenter.playSound(soundId);
}

public void OnTest() {
    int soundId = AudioCenter.loadSound("screech");
    AudioCenter.playSound(soundId);
}

} 

这是AudioCenter脚本的android部分(在包装中),但我发布它只是为了便于理解我的问题。

    public static AndroidJavaClass unityActivityClass ;
    public static AndroidJavaObject activityObj ;
    private static AndroidJavaObject soundObj ;

    public static void playSound( int soundId ) {
        soundObj.Call( "playSound", new object[] { soundId } );
    }

    public static void playSound( int soundId, float volume ) {
        soundObj.Call( "playSound", new object[] { soundId, volume } );
    }

    public static void playSound( int soundId, float leftVolume, float rightVolume, int priority, int loop, float rate  ) {
        soundObj.Call( "playSound", new object[] { soundId, leftVolume, rightVolume, priority, loop, rate } );
    }

    public static int loadSound( string soundName ) {
        return soundObj.Call<int>( "loadSound", new object[] { "Resources/Sounds/" +  soundName + ".wav" } );
    }

    public static void unloadSound( int soundId ) {
        soundObj.Call( "unloadSound", new object[] { soundId } );
    }

zip下载中软件包中的所有文件都与它们来时完全一样。我尝试了WAV和MP3,但都没有在android上播放。任何帮助将不胜感激!

0 个答案:

没有答案