DirectX:Optage,Afspille
Hvordan optager man og afspiller i directX ved brug af DirectSound, uden brug af winforms.flg. kodeeksempel, er lavet vha. opskriften fra : http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_m/directx/sound/playingsounds/playing_sounds_entry.asp
Problemet er at der skal sættes "SetCooperativeLevel" som enten tager en IntPtr eller System.Windows.Forms.Control, og jeg ønsker IKKE at bruge winforms, idet jeg er ved at udvilke et API.
Jeg har lavet en løsning for at kunne optage og gemme i en fil, men jeg kan ikke afspille, pga. førnævnte problemstilling
Andre løsningsforslag er velkomne, bare der bruges directX.DirectSound, C# og .Net .
Kodeeksempel:
using System;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
namespace AudioPlayer
{
class AudioPlayer
{
private Device dsDevice = null;
private SecondaryBuffer secBuff = null;
private BufferDescription buffDesc = null;
private IntPtr ptr ;
public AudioPlayer()
{
BufferCaps buffCaps = new BufferCaps();
ptr = new IntPtr();
dsDevice = new Device(DSoundHelper.DefaultVoicePlaybackDevice);
dsDevice.SetCooperativeLevel(ptr,CooperativeLevel.WritePrimary);
buffDesc = new BufferDescription();
secBuff = new SecondaryBuffer("c:/temp/test.wav",buffDesc,dsDevice);
}
public void player()
{
secBuff.Play(0,BufferPlayFlags.Looping);
}
static void Main()
{
AudioPlayer t = new AudioPlayer();
t.player();
}
}
}
