Home > Net >  C # directsound prompt "value is beyond the scope of the expected"
C # directsound prompt "value is beyond the scope of the expected"

Time:09-15

Var fileName="D:/work mp3";
DevicesCollection sound_devices=new DevicesCollection ();
Device sound_device_output=new Device (sound_devices [1]. The DriverGuid);
Sound_device_output. SetCooperativeLevel (new WindowInteropHelper (this). Handle, CooperativeLevel. Normal);//set the equipment level of collaboration
SecondaryBuffer secondary_buffer=new SecondaryBuffer (fileName, sound_device_output);//value is beyond the scope of the expected
Secondary_buffer. Play (0, BufferPlayFlags. Looping);//set the buffer to looping



Don't know what the reason, tried various methods, checked all kinds of information, did not solve, have know bosses help below the answer, thank you ~
SecondaryBuffer a overloading parameters is to use file streams, I give the correct audio exile in still, it should not be audio file path problem,
Sound_device_output audio device has two, both tried, useless,
Macsoft. Directx. Directsound. DLL also replaced the several versions, useless,
Really makes the head bald ~

CodePudding user response:

Var fileName="D:/work mp3";
DevicesCollection sound_devices=new DevicesCollection ();
Device sound_device_output=new Device (sound_devices [1]. The DriverGuid);

If the code is not complete, in fact, the red part should be an error, sound_devices just created, the collection is empty, no element, so the red part of the reference sound_devices [1] is null, the other file name don't write, easy to get wrong, or with System. IO. Path function to synthesize filename, so that is not affected by the operating System,

CodePudding user response:

reference 1st floor datafansbj response:
var fileName="D:/work mp3";
DevicesCollection sound_devices=new DevicesCollection ();
Device sound_device_output=new Device (sound_devices [1]. The DriverGuid);

If the code is not complete, in fact, the red part should be an error, sound_devices just created, the collection is empty, no element, so the red part of the reference sound_devices [1] is null, the other file name don't write, easy to get wrong, or with System. IO. Path function to synthesize filename, it is not affected by the operating System,


Breakpoint is seen, sound_devices new means has two elements, sound_devices [1] is not null.
Check code is a lot of information, so, don't know why I had problem ~
File name so write only convenient test, won't write so under normal circumstances,
  •  Tags:  
  • C#
  • Related