How can I play compressed sound files in C# in a portable way?

前端 未结 9 1804
陌清茗
陌清茗 2020-12-14 02:43

Is there a portable, not patent-restricted way to play compressed sound files in C# / .Net? I want to play short \"jingle\" sounds on various events occuring in the program.

9条回答
  •  一向
    一向 (楼主)
    2020-12-14 03:24

    Calling something which is located in 'System.Diagnostics' to play a sound looks like a pretty bad idea to me. Here is what that function is meant for:

        //
        // Summary:
        //     Starts a process resource by specifying the name of a document or application
        //     file and associates the resource with a new System.Diagnostics.Process component.
        //
        // Parameters:
        //   fileName:
        //     The name of a document or application file to run in the process.
        //
        // Returns:
        //     A new System.Diagnostics.Process component that is associated with the process
        //     resource, or null, if no process resource is started (for example, if an
        //     existing process is reused).
        //
        // Exceptions:
        //   System.ComponentModel.Win32Exception:
        //     There was an error in opening the associated file.
        //
        //   System.ObjectDisposedException:
        //     The process object has already been disposed.
        //
        //   System.IO.FileNotFoundException:
        //     The PATH environment variable has a string containing quotes.
    

提交回复
热议问题