Audio 将音频文件添加到我的android应用程序
我正在尝试创建一个ar android应用程序。但我不能这么做。我尝试使用SoundPool,但音频文件从未播放过。有人能告诉我如何使用soundpool吗?我是一个完全的初学者。a设计用于播放小文件,通常不超过30秒。您可以这样构造一个声音池:Audio 将音频文件添加到我的android应用程序,audio,android,Audio,Android,我正在尝试创建一个ar android应用程序。但我不能这么做。我尝试使用SoundPool,但音频文件从未播放过。有人能告诉我如何使用soundpool吗?我是一个完全的初学者。a设计用于播放小文件,通常不超过30秒。您可以这样构造一个声音池: SoundPool player = new SoundPool(int maxStreams, int streamType, 0); 加载声音文件的方式如下: int soundID = player.load(Context ctxt,int
SoundPool player = new SoundPool(int maxStreams, int streamType, 0);
加载声音文件的方式如下:
int soundID = player.load(Context ctxt,int audioFile, int priority);
其中audioFile是R.raw.somesound
(不包括文件扩展名)。请注意,您希望保留.load方法的返回值,否则将无法播放声音
您播放的声音如下:
int streamID = player.play(soundID, float leftVolume, float rightVolume ,int priority, int loop, float rate);
其中leftVolume和rightVolume是从0到1的浮动,不包括在内。您可能希望保留streamID,以便稍后暂停或停止声音。请注意,必须等待声音加载后才能播放(使用setOnLoadCompleteListener方法)
有关更多信息,请参阅