2

我使用以下方法播放声音:

public class NotificationFunction implements FREFunction {
  public FREObject call(FREContext context, FREObject[] args) {
    Context appContext = context.getActivity().getApplicationContext();
    AudioManager mAudioManager = (AudioManager)     
    appContext.getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.loadSoundEffects();
    mAudioManager.playSoundEffect(0);

它播放默认音效,我怎样才能让它播放自定义音效。

我也尝试实现声音池但它不起作用,我以标准方式实现它但它不起作用。任何想法为什么?或者如果我可以使用音频管理器来代替声音?

4

1 回答 1

0

检查以下代码

using (AudioManager am= (AudioManager)WebViewActivity.Instance.GetSystemService(Context.AudioService))
        {
            int maxVol = am.GetStreamMaxVolume(Stream.Music);
            float myVol= maxVol  * volume;

            am.SetStreamVolume(Stream.Music, (int)(myVol), 0);

            using (SoundPool soundPool = new SoundPool(1, Stream.Music, 0))
            {
                int soundFileId = soundPool.Load(soundFilePath, 1);

                soundPool.LoadComplete += (sender, eventArgs) =>
                {
                    using (SoundPool soundPoolLoaded = sender as SoundPool)
                    {
                      soundPoolLoaded.Play(soundFileId, myVol, 
                                          myVol, 0, 0, 1.0f);
                    }
                };
            }
        }
于 2015-08-11T09:31:59.143 回答