从内存中播放wav/mp3



我从文件中播放mp3/wav来创建推送效果。然而,在基于Atom CPU的平板电脑上,当我触摸按钮时会出现延迟。

我将尝试从内存而不是文件系统播放wav/mp3。有人能给出代码片段或线索吗?

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = System.Windows.Forms.Application.StartupPath + "\beep-7.wav";
player.Play();

类似的东西?

public class MediaPlayer
{
    System.Media.SoundPlayer soundPlayer;
    public MediaPlayer(byte[] buffer)
    {
        var memoryStream = new MemoryStream(buffer, true);
        soundPlayer = new System.Media.SoundPlayer(memoryStream);
    }
    public void Play()
    {
        soundPlayer.Play();
    }
    public void Play(byte[] buffer)
    {
        soundPlayer.Stream.Seek(0, SeekOrigin.Begin);
        soundPlayer.Stream.Write(buffer, 0, buffer.Length);
        soundPlayer.Play();
    }
}

相关内容

  • 没有找到相关文章

最新更新