Question

Je joue mp3 / wav de fichier pour créer un effet de poussée. Cependant sur une tablette à base de CPU Atom PC, il y a un retard quand je touche le bouton.

Je vais essayer de jouer wav / mp3 de la mémoire à la place du système de fichiers. Quelqu'un peut-il donner un extrait de code ou un indice?

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

La solution

Quelque chose comme ça?

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();
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top