Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. play wavefile

play wavefile

Scheduled Pinned Locked Moved C#
questionhelpworkspace
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    treah
    wrote on last edited by
    #1

    hi, i want to play wave file i have written following code but its not working.plz tell me how can i do this? private void playsound() { string sysRoot = System.Environment.SystemDirectory; OpenFileDialog dlg = new OpenFileDialog(); dlg.AddExtension = true; dlg.Filter = "Wave files (*.wav)|*.wav|All files (*.*)|*.*"; sysRoot = "C:\\WINNT\\Media\\ir_begin.wav"; dlg.InitialDirectory = sysRoot + @"\..\Media"; // start in media folder int err = 0; // last error try { string tbFileName = dlg.FileName; // play the sound from the selected filename if (!PlaySound(tbFileName, IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC)) MessageBox.Show(this, "Unable to find specified sound file or default Windows sound"); } catch { err = Marshal.GetLastWin32Error(); if (err != 0) MessageBox.Show(this, "Error " + err.ToString(), "PlaySound() failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } i have written this function to play wave file.:(

    G L 2 Replies Last reply
    0
    • T treah

      hi, i want to play wave file i have written following code but its not working.plz tell me how can i do this? private void playsound() { string sysRoot = System.Environment.SystemDirectory; OpenFileDialog dlg = new OpenFileDialog(); dlg.AddExtension = true; dlg.Filter = "Wave files (*.wav)|*.wav|All files (*.*)|*.*"; sysRoot = "C:\\WINNT\\Media\\ir_begin.wav"; dlg.InitialDirectory = sysRoot + @"\..\Media"; // start in media folder int err = 0; // last error try { string tbFileName = dlg.FileName; // play the sound from the selected filename if (!PlaySound(tbFileName, IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC)) MessageBox.Show(this, "Unable to find specified sound file or default Windows sound"); } catch { err = Marshal.GetLastWin32Error(); if (err != 0) MessageBox.Show(this, "Error " + err.ToString(), "PlaySound() failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } i have written this function to play wave file.:(

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      Why don't you use SoundPlayer class which is built in .NET?

      #region signature my articles #endregion

      1 Reply Last reply
      0
      • T treah

        hi, i want to play wave file i have written following code but its not working.plz tell me how can i do this? private void playsound() { string sysRoot = System.Environment.SystemDirectory; OpenFileDialog dlg = new OpenFileDialog(); dlg.AddExtension = true; dlg.Filter = "Wave files (*.wav)|*.wav|All files (*.*)|*.*"; sysRoot = "C:\\WINNT\\Media\\ir_begin.wav"; dlg.InitialDirectory = sysRoot + @"\..\Media"; // start in media folder int err = 0; // last error try { string tbFileName = dlg.FileName; // play the sound from the selected filename if (!PlaySound(tbFileName, IntPtr.Zero, SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC)) MessageBox.Show(this, "Unable to find specified sound file or default Windows sound"); } catch { err = Marshal.GetLastWin32Error(); if (err != 0) MessageBox.Show(this, "Error " + err.ToString(), "PlaySound() failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } i have written this function to play wave file.:(

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        treah wrote:

        sysRoot = "C:\\WINNT\\Media\\ir_begin.wav"; dlg.InitialDirectory = sysRoot + @"\..\Media"; // start in media folder

        This does not work, .. removes one level of directory provided there is no filename in between try sysRoot = "C:\\WINNT\\Media\\"; dlg.InitialDirectory = sysRoot; // start in media folder :)

        Luc Pattyn [My Articles] [Forum Guidelines]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups