الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

run a sound wave

مغلق
بدأه Ayah في 29 مايو 2005 · 9 رد · 767 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

Salam

I have a question about how I can run a sound.wav file into the C# please anyone can help me ??

ok am trying to write the code but I have the following error

اقتباس
An unhandled exception of type 'System.TypeLoadException' occurred in Unknown Module.

Additional information: Could not load type soundfile.WAVSounds from assembly soundfile, Version=1.0.1975.35952, Culture=neutral, PublicKeyToken=null because the method PlaySound has no RVA.

engine.wav

soundfile.txt

تم تعديل هذه المشاركة بواسطة Ayah في 29 مايو 2005 في 21:01

1+1=10

#2

انا مجربتش ال Code بس اول حاجة شوفتها

//[DllImport("WinMM.dll")]

دا Comment ليه؟؟؟؟؟

شيل ال //

ahabdeen.jpg

<marquee>

مش موجود بصفة دايمة للامتحانات

</marquee>

#3

if I remove it I have an error

1+1=10

#4

لان تعريف الfunction خطأ

هذا هو التعريف الصحيح

  [DllImport("winmm.dll", EntryPoint="PlaySound",CharSet=CharSet.Auto)]
  private static extern int PlaySound(String pszSound, int hmod, int falgs);

Sr. Software Development Engineer
Hulu, LLC
My Blogs

#5

thx

but the code still not working why??

1+1=10

#6

what is the error?

Sr. Software Development Engineer
Hulu, LLC
My Blogs

#7

when I press the button to run the sound, I cant hear anything WHY??

1+1=10

#8

This is a working code

using System;
using System.Runtime.InteropServices;
using System.IO;

namespace PlaySound
{	
	/// <summary>
	/// Helper for playing wav files and System Events stored under HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default
	/// </summary>
	public class WPlaySound
	{
  [DllImport("winmm.dll", EntryPoint="PlaySound",CharSet=CharSet.Auto)]
  private static extern int PlaySound(String pszSound, int hmod, int falgs);

  /// <summary>
  ///
  /// </summary>
  public WPlaySound()
  {
  }
  /// <summary>
  /// API Parameter Flags for PlaySound method
  /// </summary>
  public enum SND
  {
 	 SND_SYNC            = 0x0000  ,/* play synchronously (default) */
 	 SND_ASYNC           = 0x0001 , /* play asynchronously */
 	 SND_NODEFAULT       = 0x0002 , /* silence (!default) if sound not found */
 	 SND_MEMORY          = 0x0004 , /* pszSound points to a memory file */
 	 SND_LOOP            = 0x0008 , /* loop the sound until next sndPlaySound */
 	 SND_NOSTOP          = 0x0010 , /* don't stop any currently playing sound */
 	 SND_NOWAIT 	 = 0x00002000, /* don't wait if the driver is busy */
 	 SND_ALIAS 	 = 0x00010000 ,/* name is a registry alias */
 	 SND_ALIAS_ID  = 0x00110000, /* alias is a pre d ID */
 	 SND_FILENAME  = 0x00020000, /* name is file name */
 	 SND_RESOURCE  = 0x00040004, /* name is resource name or atom */
 	 SND_PURGE           = 0x0040,  /* purge non-static events for task */
 	 SND_APPLICATION     = 0x0080  /* look for application specific association */
  }
  /// <summary>
  /// Plays specified wav file.
  /// </summary>
  /// <param name="pszSound">Path points to the wave file.</param>
  /// <returns></returns>
  public static void PlaySound(String pszSound)
  {
 	 if(File.Exists(pszSound))
 	 {
    PlaySound(pszSound,0,(int) (SND.SND_ASYNC | SND.SND_FILENAME | SND.SND_NOWAIT));
 	 }

  }
  /// <summary>
  /// Play System Event stored under HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default
  /// </summary>
  /// <param name="pszSound">SystemEvent Verb</param>
  public static void PlaySoundEvent(String pszSound)
  {	
 	 PlaySound(pszSound,0,(int) (SND.SND_ASYNC | SND.SND_ALIAS | SND.SND_NOWAIT));
  }
	}

}

Sr. Software Development Engineer
Hulu, LLC
My Blogs

#9

and this is another working code

thanx for you

soundfile.txt

تم تعديل هذه المشاركة بواسطة Ayah في 30 مايو 2005 في 01:36

1+1=10

#10

لازم يكون الملف wav يعنى mp3 مش حيشتغل

ahabdeen.jpg

<marquee>

مش موجود بصفة دايمة للامتحانات

</marquee>

هذا الموضوع مغلق.

مواضيع مشابهة