2011-06-14 13 views
6

Juego mp3/wav desde el archivo para crear un efecto push. Sin embargo, en una tableta PC basada en CPU Atom, hay una demora cuando toco el botón.Reproducir wav/mp3 desde la memoria

Intentaré reproducir archivos wav/mp3 desde la memoria en lugar del sistema de archivos. ¿Alguien puede dar un fragmento de código o una pista?

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

'File.ReadAllBytes (ruta)' – SLaks

Respuesta

15

¿Alló como esto?

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(); 
    } 
} 
+0

quiero jugar mp4 de la memoria utilizando Windows Media Player CompoNet. ¿Puedo usar esta muestra? – saeed

Cuestiones relacionadas