mscorlib(4.0.0.0) API with additions
SoundPlayer.cs
2 using System.IO;
3 using System.Net;
6 using System.Security;
8 using System.Threading;
9 
10 namespace System.Media
11 {
13  [Serializable]
14  [ToolboxItem(false)]
15  [HostProtection(SecurityAction.LinkDemand, UI = true)]
17  {
18  private class IntSecurity
19  {
20  private static volatile CodeAccessPermission safeSubWindows;
21 
22  internal static CodeAccessPermission SafeSubWindows
23  {
24  get
25  {
26  if (safeSubWindows == null)
27  {
28  safeSubWindows = new UIPermission(UIPermissionWindow.SafeSubWindows);
29  }
30  return safeSubWindows;
31  }
32  }
33 
34  private IntSecurity()
35  {
36  }
37  }
38 
39  private class NativeMethods
40  {
41  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
42  internal class MMCKINFO
43  {
44  internal int ckID;
45 
46  internal int cksize;
47 
48  internal int fccType;
49 
50  internal int dwDataOffset;
51 
52  internal int dwFlags;
53  }
54 
55  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
56  internal class WAVEFORMATEX
57  {
58  internal short wFormatTag;
59 
60  internal short nChannels;
61 
62  internal int nSamplesPerSec;
63 
64  internal int nAvgBytesPerSec;
65 
66  internal short nBlockAlign;
67 
68  internal short wBitsPerSample;
69 
70  internal short cbSize;
71  }
72 
73  internal const int WAVE_FORMAT_PCM = 1;
74 
75  internal const int WAVE_FORMAT_ADPCM = 2;
76 
77  internal const int WAVE_FORMAT_IEEE_FLOAT = 3;
78 
79  internal const int MMIO_READ = 0;
80 
81  internal const int MMIO_ALLOCBUF = 65536;
82 
83  internal const int MMIO_FINDRIFF = 32;
84 
85  internal const int SND_SYNC = 0;
86 
87  internal const int SND_ASYNC = 1;
88 
89  internal const int SND_NODEFAULT = 2;
90 
91  internal const int SND_MEMORY = 4;
92 
93  internal const int SND_LOOP = 8;
94 
95  internal const int SND_PURGE = 64;
96 
97  internal const int SND_FILENAME = 131072;
98 
99  internal const int SND_NOSTOP = 16;
100 
101  private NativeMethods()
102  {
103  }
104  }
105 
106  private class UnsafeNativeMethods
107  {
108  private UnsafeNativeMethods()
109  {
110  }
111 
112  [DllImport("winmm.dll", CharSet = CharSet.Auto)]
113  internal static extern bool PlaySound([MarshalAs(UnmanagedType.LPWStr)] string soundName, IntPtr hmod, int soundFlags);
114 
115  [DllImport("winmm.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
116  internal static extern bool PlaySound(byte[] soundName, IntPtr hmod, int soundFlags);
117 
118  [DllImport("winmm.dll", CharSet = CharSet.Auto)]
119  internal static extern IntPtr mmioOpen(string fileName, IntPtr not_used, int flags);
120 
121  [DllImport("winmm.dll", CharSet = CharSet.Auto)]
122  internal static extern int mmioAscend(IntPtr hMIO, NativeMethods.MMCKINFO lpck, int flags);
123 
124  [DllImport("winmm.dll", CharSet = CharSet.Auto)]
125  internal static extern int mmioDescend(IntPtr hMIO, [MarshalAs(UnmanagedType.LPStruct)] NativeMethods.MMCKINFO lpck, [MarshalAs(UnmanagedType.LPStruct)] NativeMethods.MMCKINFO lcpkParent, int flags);
126 
127  [DllImport("winmm.dll", CharSet = CharSet.Auto)]
128  internal static extern int mmioRead(IntPtr hMIO, [MarshalAs(UnmanagedType.LPArray)] byte[] wf, int cch);
129 
130  [DllImport("winmm.dll", CharSet = CharSet.Auto)]
131  internal static extern int mmioClose(IntPtr hMIO, int flags);
132  }
133 
134  private const int blockSize = 1024;
135 
136  private const int defaultLoadTimeout = 10000;
137 
138  private Uri uri;
139 
140  private string soundLocation = string.Empty;
141 
142  private int loadTimeout = 10000;
143 
144  private object tag;
145 
146  private ManualResetEvent semaphore = new ManualResetEvent(initialState: true);
147 
148  private Thread copyThread;
149 
150  private int currentPos;
151 
152  private Stream stream;
153 
154  private bool isLoadCompleted;
155 
156  private Exception lastLoadException;
157 
158  private bool doesLoadAppearSynchronous;
159 
160  private byte[] streamData;
161 
162  private AsyncOperation asyncOperation;
163 
164  private readonly SendOrPostCallback loadAsyncOperationCompleted;
165 
166  private static readonly object EventLoadCompleted = new object();
167 
168  private static readonly object EventSoundLocationChanged = new object();
169 
170  private static readonly object EventStreamChanged = new object();
171 
174  public int LoadTimeout
175  {
176  get
177  {
178  return loadTimeout;
179  }
180  set
181  {
182  if (value < 0)
183  {
184  throw new ArgumentOutOfRangeException("LoadTimeout", value, SR.GetString("SoundAPILoadTimeout"));
185  }
186  loadTimeout = value;
187  }
188  }
189 
192  public string SoundLocation
193  {
194  get
195  {
196  if (uri != null && uri.IsFile)
197  {
198  FileIOPermission fileIOPermission = new FileIOPermission(PermissionState.None);
199  fileIOPermission.AllFiles = FileIOPermissionAccess.PathDiscovery;
200  fileIOPermission.Demand();
201  }
202  return soundLocation;
203  }
204  set
205  {
206  if (value == null)
207  {
208  value = string.Empty;
209  }
210  if (!soundLocation.Equals(value))
211  {
212  SetupSoundLocation(value);
214  }
215  }
216  }
217 
220  public Stream Stream
221  {
222  get
223  {
224  if (uri != null)
225  {
226  return null;
227  }
228  return stream;
229  }
230  set
231  {
232  if (stream != value)
233  {
234  SetupStream(value);
236  }
237  }
238  }
239 
243  public bool IsLoadCompleted => isLoadCompleted;
244 
247  public object Tag
248  {
249  get
250  {
251  return tag;
252  }
253  set
254  {
255  tag = value;
256  }
257  }
258 
261  {
262  add
263  {
264  base.Events.AddHandler(EventLoadCompleted, value);
265  }
266  remove
267  {
268  base.Events.RemoveHandler(EventLoadCompleted, value);
269  }
270  }
271 
274  {
275  add
276  {
277  base.Events.AddHandler(EventSoundLocationChanged, value);
278  }
279  remove
280  {
281  base.Events.RemoveHandler(EventSoundLocationChanged, value);
282  }
283  }
284 
286  public event EventHandler StreamChanged
287  {
288  add
289  {
290  base.Events.AddHandler(EventStreamChanged, value);
291  }
292  remove
293  {
294  base.Events.RemoveHandler(EventStreamChanged, value);
295  }
296  }
297 
299  public SoundPlayer()
300  {
301  loadAsyncOperationCompleted = LoadAsyncOperationCompleted;
302  }
303 
307  public SoundPlayer(string soundLocation)
308  : this()
309  {
310  if (soundLocation == null)
311  {
312  soundLocation = string.Empty;
313  }
314  SetupSoundLocation(soundLocation);
315  }
316 
319  public SoundPlayer(Stream stream)
320  : this()
321  {
322  this.stream = stream;
323  }
324 
329  protected SoundPlayer(SerializationInfo serializationInfo, StreamingContext context)
330  {
331  SerializationInfoEnumerator enumerator = serializationInfo.GetEnumerator();
332  while (enumerator.MoveNext())
333  {
334  SerializationEntry current = enumerator.Current;
335  switch (current.Name)
336  {
337  case "SoundLocation":
338  SetupSoundLocation((string)current.Value);
339  break;
340  case "Stream":
341  stream = (Stream)current.Value;
342  if (stream.CanSeek)
343  {
344  stream.Seek(0L, SeekOrigin.Begin);
345  }
346  break;
347  case "LoadTimeout":
348  LoadTimeout = (int)current.Value;
349  break;
350  }
351  }
352  }
353 
357  public void LoadAsync()
358  {
359  if (uri != null && uri.IsFile)
360  {
361  isLoadCompleted = true;
362  FileInfo fileInfo = new FileInfo(uri.LocalPath);
363  if (!fileInfo.Exists)
364  {
365  throw new FileNotFoundException(SR.GetString("SoundAPIFileDoesNotExist"), soundLocation);
366  }
367  OnLoadCompleted(new AsyncCompletedEventArgs(null, cancelled: false, null));
368  }
369  else if (copyThread == null || copyThread.ThreadState != 0)
370  {
371  isLoadCompleted = false;
372  streamData = null;
373  currentPos = 0;
374  asyncOperation = AsyncOperationManager.CreateOperation(null);
375  LoadStream(loadSync: false);
376  }
377  }
378 
379  private void LoadAsyncOperationCompleted(object arg)
380  {
382  }
383 
384  private void CleanupStreamData()
385  {
386  currentPos = 0;
387  streamData = null;
388  isLoadCompleted = false;
389  lastLoadException = null;
390  doesLoadAppearSynchronous = false;
391  copyThread = null;
392  semaphore.Set();
393  }
394 
398  public void Load()
399  {
400  if (uri != null && uri.IsFile)
401  {
402  FileInfo fileInfo = new FileInfo(uri.LocalPath);
403  if (!fileInfo.Exists)
404  {
405  throw new FileNotFoundException(SR.GetString("SoundAPIFileDoesNotExist"), soundLocation);
406  }
407  isLoadCompleted = true;
408  OnLoadCompleted(new AsyncCompletedEventArgs(null, cancelled: false, null));
409  }
410  else
411  {
412  LoadSync();
413  }
414  }
415 
416  private void LoadAndPlay(int flags)
417  {
418  if (string.IsNullOrEmpty(soundLocation) && stream == null)
419  {
421  }
422  else if (uri != null && uri.IsFile)
423  {
424  string localPath = uri.LocalPath;
425  FileIOPermission fileIOPermission = new FileIOPermission(FileIOPermissionAccess.Read, localPath);
426  fileIOPermission.Demand();
427  isLoadCompleted = true;
428  IntSecurity.SafeSubWindows.Demand();
429  System.ComponentModel.IntSecurity.UnmanagedCode.Assert();
430  try
431  {
432  ValidateSoundFile(localPath);
433  UnsafeNativeMethods.PlaySound(localPath, IntPtr.Zero, 2 | flags);
434  }
435  finally
436  {
438  }
439  }
440  else
441  {
442  LoadSync();
443  ValidateSoundData(streamData);
444  IntSecurity.SafeSubWindows.Demand();
445  System.ComponentModel.IntSecurity.UnmanagedCode.Assert();
446  try
447  {
448  UnsafeNativeMethods.PlaySound(streamData, IntPtr.Zero, 6 | flags);
449  }
450  finally
451  {
453  }
454  }
455  }
456 
457  private void LoadSync()
458  {
459  if (!semaphore.WaitOne(LoadTimeout, exitContext: false))
460  {
461  if (copyThread != null)
462  {
463  copyThread.Abort();
464  }
465  CleanupStreamData();
466  throw new TimeoutException(SR.GetString("SoundAPILoadTimedOut"));
467  }
468  if (streamData != null)
469  {
470  return;
471  }
472  if (uri != null && !uri.IsFile && stream == null)
473  {
474  WebPermission webPermission = new WebPermission(NetworkAccess.Connect, uri.AbsolutePath);
475  webPermission.Demand();
476  WebRequest webRequest = WebRequest.Create(uri);
477  webRequest.Timeout = LoadTimeout;
478  WebResponse response = webRequest.GetResponse();
479  stream = response.GetResponseStream();
480  }
481  if (stream.CanSeek)
482  {
483  LoadStream(loadSync: true);
484  }
485  else
486  {
487  doesLoadAppearSynchronous = true;
488  LoadStream(loadSync: false);
489  if (!semaphore.WaitOne(LoadTimeout, exitContext: false))
490  {
491  if (copyThread != null)
492  {
493  copyThread.Abort();
494  }
495  CleanupStreamData();
496  throw new TimeoutException(SR.GetString("SoundAPILoadTimedOut"));
497  }
498  doesLoadAppearSynchronous = false;
499  if (lastLoadException != null)
500  {
501  throw lastLoadException;
502  }
503  }
504  copyThread = null;
505  }
506 
507  private void LoadStream(bool loadSync)
508  {
509  if (loadSync && stream.CanSeek)
510  {
511  int num = (int)stream.Length;
512  currentPos = 0;
513  streamData = new byte[num];
514  stream.Read(streamData, 0, num);
515  isLoadCompleted = true;
516  OnLoadCompleted(new AsyncCompletedEventArgs(null, cancelled: false, null));
517  }
518  else
519  {
520  semaphore.Reset();
521  copyThread = new Thread(WorkerThread);
522  copyThread.Start();
523  }
524  }
525 
530  public void Play()
531  {
532  LoadAndPlay(1);
533  }
534 
539  public void PlaySync()
540  {
541  LoadAndPlay(0);
542  }
543 
548  public void PlayLooping()
549  {
550  LoadAndPlay(9);
551  }
552 
553  private static Uri ResolveUri(string partialUri)
554  {
555  Uri uri = null;
556  try
557  {
558  uri = new Uri(partialUri);
559  }
560  catch (UriFormatException)
561  {
562  }
563  if (uri == null)
564  {
565  try
566  {
567  uri = new Uri(Path.GetFullPath(partialUri));
568  return uri;
569  }
570  catch (UriFormatException)
571  {
572  return uri;
573  }
574  }
575  return uri;
576  }
577 
578  private void SetupSoundLocation(string soundLocation)
579  {
580  if (copyThread != null)
581  {
582  copyThread.Abort();
583  CleanupStreamData();
584  }
585  uri = ResolveUri(soundLocation);
586  this.soundLocation = soundLocation;
587  stream = null;
588  if (uri == null)
589  {
590  if (!string.IsNullOrEmpty(soundLocation))
591  {
592  throw new UriFormatException(SR.GetString("SoundAPIBadSoundLocation"));
593  }
594  }
595  else if (!uri.IsFile)
596  {
597  streamData = null;
598  currentPos = 0;
599  isLoadCompleted = false;
600  }
601  }
602 
603  private void SetupStream(Stream stream)
604  {
605  if (copyThread != null)
606  {
607  copyThread.Abort();
608  CleanupStreamData();
609  }
610  this.stream = stream;
611  soundLocation = string.Empty;
612  streamData = null;
613  currentPos = 0;
614  isLoadCompleted = false;
615  if (stream != null)
616  {
617  uri = null;
618  }
619  }
620 
622  public void Stop()
623  {
624  IntSecurity.SafeSubWindows.Demand();
625  UnsafeNativeMethods.PlaySound((byte[])null, IntPtr.Zero, 64);
626  }
627 
630  protected virtual void OnLoadCompleted(AsyncCompletedEventArgs e)
631  {
632  ((AsyncCompletedEventHandler)base.Events[EventLoadCompleted])?.Invoke(this, e);
633  }
634 
637  protected virtual void OnSoundLocationChanged(EventArgs e)
638  {
639  ((EventHandler)base.Events[EventSoundLocationChanged])?.Invoke(this, e);
640  }
641 
644  protected virtual void OnStreamChanged(EventArgs e)
645  {
646  ((EventHandler)base.Events[EventStreamChanged])?.Invoke(this, e);
647  }
648 
649  private void WorkerThread()
650  {
651  try
652  {
653  if (uri != null && !uri.IsFile && stream == null)
654  {
655  WebRequest webRequest = WebRequest.Create(uri);
656  WebResponse response = webRequest.GetResponse();
657  stream = response.GetResponseStream();
658  }
659  streamData = new byte[1024];
660  int num = stream.Read(streamData, currentPos, 1024);
661  int num2 = num;
662  while (num > 0)
663  {
664  currentPos += num;
665  if (streamData.Length < currentPos + 1024)
666  {
667  byte[] destinationArray = new byte[streamData.Length * 2];
668  Array.Copy(streamData, destinationArray, streamData.Length);
669  streamData = destinationArray;
670  }
671  num = stream.Read(streamData, currentPos, 1024);
672  num2 += num;
673  }
674  lastLoadException = null;
675  }
676  catch (Exception ex)
677  {
678  Exception ex2 = lastLoadException = ex;
679  }
680  if (!doesLoadAppearSynchronous)
681  {
682  asyncOperation.PostOperationCompleted(loadAsyncOperationCompleted, new AsyncCompletedEventArgs(lastLoadException, cancelled: false, null));
683  }
684  isLoadCompleted = true;
685  semaphore.Set();
686  }
687 
688  private unsafe void ValidateSoundFile(string fileName)
689  {
690  NativeMethods.MMCKINFO mMCKINFO = new NativeMethods.MMCKINFO();
691  NativeMethods.MMCKINFO mMCKINFO2 = new NativeMethods.MMCKINFO();
692  NativeMethods.WAVEFORMATEX wAVEFORMATEX = null;
693  IntPtr intPtr = UnsafeNativeMethods.mmioOpen(fileName, IntPtr.Zero, 65536);
694  if (intPtr == IntPtr.Zero)
695  {
696  throw new FileNotFoundException(SR.GetString("SoundAPIFileDoesNotExist"), soundLocation);
697  }
698  try
699  {
700  mMCKINFO.fccType = mmioFOURCC('W', 'A', 'V', 'E');
701  if (UnsafeNativeMethods.mmioDescend(intPtr, mMCKINFO, null, 32) != 0)
702  {
703  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveFile", soundLocation));
704  }
705  while (UnsafeNativeMethods.mmioDescend(intPtr, mMCKINFO2, mMCKINFO, 0) == 0)
706  {
707  if (mMCKINFO2.dwDataOffset + mMCKINFO2.cksize > mMCKINFO.dwDataOffset + mMCKINFO.cksize)
708  {
709  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
710  }
711  if (mMCKINFO2.ckID == mmioFOURCC('f', 'm', 't', ' ') && wAVEFORMATEX == null)
712  {
713  int num = mMCKINFO2.cksize;
714  if (num < Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX)))
715  {
716  num = Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX));
717  }
718  wAVEFORMATEX = new NativeMethods.WAVEFORMATEX();
719  byte[] array = new byte[num];
720  if (UnsafeNativeMethods.mmioRead(intPtr, array, num) != num)
721  {
722  throw new InvalidOperationException(SR.GetString("SoundAPIReadError", soundLocation));
723  }
724  try
725  {
726  byte[] array2 = array;
727  fixed (byte* value = array2)
728  {
729  Marshal.PtrToStructure((IntPtr)(void*)value, (object)wAVEFORMATEX);
730  }
731  }
732  finally
733  {
734  }
735  }
736  UnsafeNativeMethods.mmioAscend(intPtr, mMCKINFO2, 0);
737  }
738  if (wAVEFORMATEX == null)
739  {
740  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
741  }
742  if (wAVEFORMATEX.wFormatTag != 1 && wAVEFORMATEX.wFormatTag != 2 && wAVEFORMATEX.wFormatTag != 3)
743  {
744  throw new InvalidOperationException(SR.GetString("SoundAPIFormatNotSupported"));
745  }
746  }
747  finally
748  {
749  if (intPtr != IntPtr.Zero)
750  {
751  UnsafeNativeMethods.mmioClose(intPtr, 0);
752  }
753  }
754  }
755 
756  private static void ValidateSoundData(byte[] data)
757  {
758  int num = 0;
759  short num2 = -1;
760  bool flag = false;
761  if (data.Length < 12)
762  {
763  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
764  }
765  if (data[0] != 82 || data[1] != 73 || data[2] != 70 || data[3] != 70)
766  {
767  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
768  }
769  if (data[8] != 87 || data[9] != 65 || data[10] != 86 || data[11] != 69)
770  {
771  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
772  }
773  num = 12;
774  int num3 = data.Length;
775  while (!flag && num < num3 - 8)
776  {
777  if (data[num] == 102 && data[num + 1] == 109 && data[num + 2] == 116 && data[num + 3] == 32)
778  {
779  flag = true;
780  int num4 = BytesToInt(data[num + 7], data[num + 6], data[num + 5], data[num + 4]);
781  int num5 = 16;
782  if (num4 != num5)
783  {
784  int num6 = 18;
785  if (num3 < num + 8 + num6 - 1)
786  {
787  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
788  }
789  short num7 = BytesToInt16(data[num + 8 + num6 - 1], data[num + 8 + num6 - 2]);
790  if (num7 + num6 != num4)
791  {
792  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
793  }
794  }
795  if (num3 < num + 9)
796  {
797  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
798  }
799  num2 = BytesToInt16(data[num + 9], data[num + 8]);
800  num += num4 + 8;
801  }
802  else
803  {
804  num += 8 + BytesToInt(data[num + 7], data[num + 6], data[num + 5], data[num + 4]);
805  }
806  }
807  if (!flag)
808  {
809  throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
810  }
811  if (num2 != 1 && num2 != 2 && num2 != 3)
812  {
813  throw new InvalidOperationException(SR.GetString("SoundAPIFormatNotSupported"));
814  }
815  }
816 
817  private static short BytesToInt16(byte ch0, byte ch1)
818  {
819  int num = ch1 | (ch0 << 8);
820  return (short)num;
821  }
822 
823  private static int BytesToInt(byte ch0, byte ch1, byte ch2, byte ch3)
824  {
825  return mmioFOURCC((char)ch3, (char)ch2, (char)ch1, (char)ch0);
826  }
827 
828  private static int mmioFOURCC(char ch0, char ch1, char ch2, char ch3)
829  {
830  int num = 0;
831  num |= ch0;
832  num |= (int)((uint)ch1 << 8);
833  num |= (int)((uint)ch2 << 16);
834  return num | (int)((uint)ch3 << 24);
835  }
836 
840  [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
842  {
843  if (!string.IsNullOrEmpty(soundLocation))
844  {
845  info.AddValue("SoundLocation", soundLocation);
846  }
847  if (stream != null)
848  {
849  info.AddValue("Stream", stream);
850  }
851  info.AddValue("LoadTimeout", loadTimeout);
852  }
853  }
854 }
Provides concurrency management for classes that support asynchronous method calls....
SoundPlayer()
Initializes a new instance of the T:System.Media.SoundPlayer class.
Definition: SoundPlayer.cs:299
object Tag
Gets or sets the T:System.Object that contains data about the T:System.Media.SoundPlayer.
Definition: SoundPlayer.cs:248
Users can only use F:System.Security.Permissions.UIPermissionWindow.SafeSubWindows for drawing,...
Describes a set of security permissions applied to code. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
abstract int Read([In] [Out] byte[] buffer, int offset, int count)
When overridden in a derived class, reads a sequence of bytes from the current stream and advances th...
bool IsLoadCompleted
Gets a value indicating whether loading of a .wav file has successfully completed.
Definition: SoundPlayer.cs:243
delegate void SendOrPostCallback(object state)
Represents a method to be called when a message is to be dispatched to a synchronization context.
Tracks the lifetime of an asynchronous operation.
string LocalPath
Gets a local operating-system representation of a file name.
Definition: Uri.cs:372
virtual void OnLoadCompleted(AsyncCompletedEventArgs e)
Raises the E:System.Media.SoundPlayer.LoadCompleted event.
Definition: SoundPlayer.cs:630
void Load()
Loads a sound synchronously.
Definition: SoundPlayer.cs:398
AsyncCompletedEventHandler LoadCompleted
Occurs when a .wav file has been successfully or unsuccessfully loaded.
Definition: SoundPlayer.cs:261
abstract bool CanSeek
When overridden in a derived class, gets a value indicating whether the current stream supports seeki...
Definition: Stream.cs:587
NetworkAccess
Specifies network access permissions.
Definition: NetworkAccess.cs:5
bool Set()
Sets the state of the event to signaled, allowing one or more waiting threads to proceed.
bool IsFile
Gets a value indicating whether the specified T:System.Uri is a file URI.
Definition: Uri.cs:472
Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
Definition: WebRequest.cs:21
LayoutKind
Controls the layout of an object when exported to unmanaged code.
Definition: LayoutKind.cs:7
Definition: __Canon.cs:3
ThreadState ThreadState
Gets a value containing the states of the current thread.
Definition: Thread.cs:166
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static int SizeOf(object structure)
Returns the unmanaged size of an object in bytes.
Definition: Marshal.cs:159
void PlayLooping()
Plays and loops the .wav file using a new thread, and loads the .wav file first if it has not been lo...
Definition: SoundPlayer.cs:548
Stream Stream
Gets or sets the T:System.IO.Stream from which to load the .wav file.
Definition: SoundPlayer.cs:221
EventHandler StreamChanged
Occurs when a new T:System.IO.Stream audio source for this T:System.Media.SoundPlayer has been set.
Definition: SoundPlayer.cs:287
UIPermissionWindow
Specifies the type of windows that code is allowed to use.
SerializationInfoEnumerator GetEnumerator()
Returns a T:System.Runtime.Serialization.SerializationInfoEnumerator used to iterate through the name...
SoundPlayer(Stream stream)
Initializes a new instance of the T:System.Media.SoundPlayer class, and attaches the ....
Definition: SoundPlayer.cs:319
void Play()
Plays the system sound type.
Definition: SystemSound.cs:30
static SystemSound Beep
Gets the sound associated with the Beep program event in the current Windows sound scheme.
Definition: SystemSounds.cs:51
Controls playback of a sound from a .wav file.
Definition: SoundPlayer.cs:16
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: EventArgs.cs:9
Describes the source and destination of a given serialized stream, and provides an additional caller-...
virtual int Timeout
Gets or sets the length of time, in milliseconds, before the request times out.
Definition: WebRequest.cs:370
virtual bool WaitOne(int millisecondsTimeout, bool exitContext)
Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal,...
Definition: WaitHandle.cs:162
Retrieves sounds associated with a set of Windows operating system sound-event types....
Definition: SystemSounds.cs:7
SoundPlayer(SerializationInfo serializationInfo, StreamingContext context)
Initializes a new instance of the T:System.Media.SoundPlayer class.
Definition: SoundPlayer.cs:329
SeekOrigin
Specifies the position in a stream to use for seeking.
Definition: SeekOrigin.cs:9
SoundPlayer(string soundLocation)
Initializes a new instance of the T:System.Media.SoundPlayer class, and attaches the specified ....
Definition: SoundPlayer.cs:307
Provides data for the MethodNameCompleted event.
SecurityAction
Specifies the security actions that can be performed using declarative security.
string AbsolutePath
Gets the absolute path of the URI.
Definition: Uri.cs:303
Provides a response from a Uniform Resource Identifier (URI). This is an abstract class.
Definition: WebResponse.cs:10
static readonly EventArgs Empty
Provides a value to use with events that do not have event data.
Definition: EventArgs.cs:13
Provides properties and instance methods for the creation, copying, deletion, moving,...
Definition: FileInfo.cs:14
UnmanagedType
Identifies how to marshal parameters or fields to unmanaged code.
Definition: UnmanagedType.cs:7
delegate void EventHandler(object sender, EventArgs e)
Represents the method that will handle an event that has no event data.
Controls rights to access HTTP Internet resources.
Controls the permissions related to user interfaces and the Clipboard. This class cannot be inherited...
Definition: UIPermission.cs:9
Defines the underlying structure of all code access permissions.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Notifies one or more waiting threads that an event has occurred. This class cannot be inherited.
Provides the base implementation for the T:System.ComponentModel.IComponent interface and enables obj...
Definition: Component.cs:9
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
static string GetFullPath(string path)
Returns the absolute path for the specified path string.
Definition: Path.cs:446
abstract long Seek(long offset, SeekOrigin origin)
When overridden in a derived class, sets the position within the current stream.
FileIOPermissionAccess AllFiles
Gets or sets the permitted access to all files.
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
void Stop()
Stops playback of the sound if playback is occurring.
Definition: SoundPlayer.cs:622
static void RevertAssert()
Causes any previous M:System.Security.CodeAccessPermission.Assert for the current frame to be removed...
void Start()
Causes the operating system to change the state of the current instance to F:System....
Definition: Thread.cs:480
void Abort(object stateInfo)
Raises a T:System.Threading.ThreadAbortException in the thread on which it is invoked,...
Definition: Thread.cs:601
void LoadAsync()
Loads a .wav file from a stream or a Web resource using a new thread.
Definition: SoundPlayer.cs:357
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
virtual void OnSoundLocationChanged(EventArgs e)
Raises the E:System.Media.SoundPlayer.SoundLocationChanged event.
Definition: SoundPlayer.cs:637
virtual void OnStreamChanged(EventArgs e)
Raises the E:System.Media.SoundPlayer.StreamChanged event.
Definition: SoundPlayer.cs:644
abstract long Length
When overridden in a derived class, gets the length in bytes of the stream.
Definition: Stream.cs:621
void Play()
Plays the .wav file using a new thread, and loads the .wav file first if it has not been loaded.
Definition: SoundPlayer.cs:530
The exception that is thrown when an attempt to access a file that does not exist on disk fails.
EventHandler SoundLocationChanged
Occurs when a new audio source path for this T:System.Media.SoundPlayer has been set.
Definition: SoundPlayer.cs:274
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Definition: Array.cs:1275
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
static void PtrToStructure(IntPtr ptr, object structure)
Marshals data from an unmanaged block of memory to a managed object.
Definition: Marshal.cs:1198
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
static AsyncOperation CreateOperation(object userSuppliedState)
Returns an T:System.ComponentModel.AsyncOperation for tracking the duration of a particular asynchron...
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Definition: IntPtr.cs:20
void PostOperationCompleted(SendOrPostCallback d, object arg)
Ends the lifetime of an asynchronous operation.
int LoadTimeout
Gets or sets the time, in milliseconds, in which the .wav file must load.
Definition: SoundPlayer.cs:175
Holds the value, T:System.Type, and name of a serialized object.
virtual WebResponse GetResponse()
When overridden in a descendant class, returns a response to an Internet request.
Definition: WebRequest.cs:725
Controls the ability to access files and folders. This class cannot be inherited.
void PlaySync()
Plays the .wav file and loads the .wav file first if it has not been loaded.
Definition: SoundPlayer.cs:539
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition: Uri.cs:19
virtual Stream GetResponseStream()
When overridden in a descendant class, returns the data stream from the Internet resource.
Definition: WebResponse.cs:184
Provides a formatter-friendly mechanism for parsing the data in T:System.Runtime.Serialization....
override bool Exists
Gets a value indicating whether a file exists.
Definition: FileInfo.cs:115
delegate void AsyncCompletedEventHandler(object sender, AsyncCompletedEventArgs e)
Represents the method that will handle the MethodNameCompleted event of an asynchronous operation.
object Value
Gets the value contained in the object.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
string Name
Gets the name of the object.
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
string SoundLocation
Gets or sets the file path or URL of the .wav file to load.
Definition: SoundPlayer.cs:193
bool Reset()
Sets the state of the event to nonsignaled, causing threads to block.
The exception that is thrown when an invalid Uniform Resource Identifier (URI) is detected.
bool MoveNext()
Updates the enumerator to the next item.
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
Definition: Stream.cs:16
Creates and controls a thread, sets its priority, and gets its status.
Definition: Thread.cs:18