SoundPlayer (Clase)
Controla la Reproducción del sonido de archivo .wav un.
Jerarquía de herencia
Sistema . Object
System . MarshalByRefObject
System.ComponentModel . Componente
System.Media . SoundPlayer Sintaxis
System . MarshalByRefObject
System.ComponentModel . Componente
System.Media . SoundPlayer Sintaxis
# VB Declaración '
<SerializableAttribute> _
<HostProtectionAttribute (SecurityAction.LinkDemand, la Interfaz de Usuario: = True)> _
Public Class SoundPlayer _
Hereda de Componentes _
Implementa ISerializable
C onstructores
Nombre | Descripción | |
---|---|---|
![]() | SoundPlayer | |
![]() | SoundPlayer (Stream) | |
![]() | SoundPlayer (String) | |
![]() | SoundPlayer (SerializationInfo, StreamingContext) |
Propiedades
Nombre | Descripción | |
---|---|---|
![]() | CanRaiseEvents | |
![]() | Contenedor | |
![]() | DesignMode | |
![]() | Eventos | |
![]() | IsLoadCompleted | |
![]() | LoadTimeout | |
![]() | Sitio | |
![]() | SoundLocation | |
![]() | Corriente | |
![]() | Etiqueta |
Métodos
Nombre | Descripción | |
---|---|---|
![]() | CreateObjRef | |
![]() | Enajenante | |
![]() | Deseche (booleano) | |
![]() | Equals (Object) | |
![]() | Ultimar | |
![]() | GetHashCode | |
![]() | GetLifetimeService | |
![]() | GetService | |
![]() | GetType | |
![]() | InitializeLifetimeService | |
![]() | Carga | |
![]() | LoadAsync | |
![]() | MemberwiseClone | |
![]() | MemberwiseClone (Boolean) | |
![]() | OnLoadCompleted | |
![]() | OnSoundLocationChanged | |
![]() | OnStreamChanged | |
![]() | Jugar | |
![]() | PlayLooping | |
![]() | PlaySync | |
![]() | Deténgase | |
![]() | Encadenar |
Eventos
Nombre | Descripción | |
---|---|---|
![]() | Dispuesto | |
![]() | LoadCompleted | |
![]() | SoundLocationChanged | |
![]() | StreamChanged |
Implementaciones de Interfaz Explicita
Nombre | Descripción | |
---|---|---|
![]() ![]() | ISerializable . GetObjectData |
EJEMPLOS
En El Ejemplo de código siguiente se Muestra el USO de la clase SoundPlayer Parr Reproducir Archivos .wav de Una ruta de acceso acceso local o la ONU Identificador uniforme de recursos (URI).
Imports System Imports System.Collections Imports System.ComponentModel Imports System.Diagnostics Imports System.Drawing Imports System.Media Imports System.Windows.Forms Public Class SoundTestForm Inherits System.Windows.Forms.Form Private label1 As System.Windows.Forms.Label Private WithEvents filepathTextbox As System.Windows.Forms.TextBox Private WithEvents playOnceSyncButton As System.Windows.Forms.Button Private WithEvents playOnceAsyncButton As System.Windows.Forms.Button Private WithEvents playLoopAsyncButton As System.Windows.Forms.Button Private WithEvents selectFileButton As System.Windows.Forms.Button Private WithEvents stopButton As System.Windows.Forms.Button Private statusBar As System.Windows.Forms.StatusBar Private WithEvents loadSyncButton As System.Windows.Forms.Button Private WithEvents loadAsyncButton As System.Windows.Forms.Button Private player As SoundPlayer Public Sub Nueva () 'Inicializar diseñador de formularios de código Generado. InitializeComponent () 'Controles de Reproducción Deshabilitar Hasta Que ONU archivo .wav válido de Correo. Selecciona EnablePlaybackControls ( Falso ) 'Configurar la barra de estado y Otros Controles. InitializeControls () 'Configurar el Objeto SoundPlayer. InitializeSound () End Sub 'Establece la barra de estado y Otros Controles. Private Sub InitializeControls () 'Configurar la barra de estado. Dim Panel de Como Nuevo StatusBarPanel panel.BorderStyle = StatusBarPanelBorderStyle.Sunken panel.Text = "Listo". panel.AutoSize = StatusBarPanelAutoSize.Spring Me .statusBar.ShowPanels = Verdadero Mí .statusBar.Panels.Add (el panel) End Sub 'Establece el Objeto SoundPlayer. Private Sub InitializeSound () "Crear Una instancia de la clase SoundPlayer. Reproductor = Nuevo SoundPlayer 'ESCUCHE EL EVENTO LoadCompleted. AddHandler player.LoadCompleted, AddressOf player_LoadCompleted 'ESCUCHE el evento SoundLocationChanged. AddHandler player.SoundLocationChanged, AddressOf player_LocationChanged End Sub Private Sub selectFileButton_Click ( ByVal remitente Como Object , _ ByVal e Como System.EventArgs) Maneja selectFileButton.Click 'Nuevo ONU Crear OpenFileDialog. Dim DLG Como Nuevo OpenFileDialog "Asegurese De que los Controles de Diálogo Para La Existencia del archivo Seleccionado ". dlg.CheckFileExists = Verdadero . 'Permitir Selección de Archivos .wav Solamente dlg.Filter = "WAV Archivos (* .wav) | * .wav" dlg.DefaultExt = ".wav" 'Activar el cuadro de Diálogo de Selección de Archivos. Si dlg.ShowDialog () = System.Windows.Forms.DialogResult.OK then 'Obtener la ruta del archivo Seleccionado en el Diálogo. Me .filepathTextbox.Text = dlg.FileName 'Asignar la ruta del archivo Seleccionado al Objeto SoundPlayer. player.SoundLocation = filepathTextbox.Text Termine Si End Sub "Método de conveniencia de establecer el texto del Mensaje en "la barra de estado. Private Sub ReportStatus ( ByVal StatusMessage Como Cadena ) "Si la Persona que llama pasa en un ... Mensaje de Si (StatusMessage IsNot Nada ) AndAlso _ StatusMessage <> [ cadena ] .Empty LUEGO '... enviar el Mensaje de la Persona que llama a la barra de estado. Me .statusBar.Panels (0) .Texto = StatusMessage Fin de Si End Sub 'Activa y Desactiva Juegan Controles. Privadas Sub EnablePlaybackControls ( ByVal habilitadas Como booleana ) Me .playOnceSyncButton.Enabled = enabled Me .playOnceAsyncButton.Enabled = habilitado Me .playLoopAsyncButton.Enabled = habilitado Me .stopButton.Enabled = Activado End Sub Private Sub filepathTextbox_TextChanged ( ByVal remitente Como Object , _ ByVal e Como EventArgs) Maneja filepathTextbox.TextChanged 'Controles de Reproducción Deshabilitar Hasta Que se carga el nuevo .wav. EnablePlaybackControls ( Falso ) End Sub Private Sub loadSyncButton_Click ( ByVal remitente Como Object , _ ByVal e Como System.EventArgs) Maneja loadSyncButton.Click 'Controles de Reproducción Deshabilitar Hasta Que el Éxito se .wav 'Cargados. El Controlador de eventos LoadCompleted les permitira. EnablePlaybackControls ( Falso ) TraR 'Asignar la ruta del archivo Seleccionado al Objeto SoundPlayer. player.SoundLocation = filepathTextbox.Text '.wav Archivo Cargar el. player.Load () Catch ex Como Excepción ReportStatus (ex.Message) End Try End Sub Private Sub loadAsyncButton_Click ( ByVal remitente Como System.Object, _ ByVal e Como System.EventArgs) Maneja loadAsyncButton.Click 'Controles de Reproducción Deshabilitar Hasta Que el Éxito se .wav 'Cargados. El Controlador de eventos LoadCompleted les permitira. EnablePlaybackControls ( Falso ) TraR 'Asignar la ruta del archivo Seleccionado al Objeto SoundPlayer. player.SoundLocation = Me .filepathTextbox.Text '.wav Archivo Cargar el. player.LoadAsync () Catch ex Como Excepción ReportStatus (ex.Message) End Try End Sub 'Seleccionado Una Vez Sincrónicamente Reproducir el archivo .wav. "Si el archivo es grande, La Respuesta de la Interfaz de Usuario Será visible 'Afectada. Private Sub playOnceSyncButton_Click ( ByVal remitente Como Object , _ ByVal e Como System.EventArgs) Maneja playOnceSyncButton. Haga clic en ReportStatus ( "Jugar .wav PRESENTAR de forma sincrónica." ) player.PlaySync () ReportStatus ( "termino jugando .wav archivo de forma sincrónica." ) End Sub 'Seleccionado Una Vez asincrónica Reproducir el archivo .wav. Private Sub playOnceAsyncButton_Click ( ByVal remitente Como Object , _ ByVal e Como System.EventArgs) Maneja playOnceAsyncButton.Click ReportStatus ( "Jugar .wav PRESENTAR de forma asíncrona." ) player.Play () End Sub 'Asincrónica Reproducir el archivo .wav Seleccionado Hasta Que el usuario "Hace clic en El Botón Detener. Private Sub playLoopAsyncButton_Click ( ByVal remitente Como Object , _ ByVal e Como System.EventArgs) Maneja playLoopAsyncButton.Click ReportStatus ( "Looping .wav PRESENTAR de forma asíncrona." ) player.PlayLooping () End Sub 'Detiene el archivo .wav Que se està reproduciendo, en su Caso. Privado Sub stopButton_Click ( ByVal remitente Como System.Object, _ ByVal e Como System.EventArgs) Maneja stopButton.Click Jugador. Detener () ReportStatus ( "Detenido por el usuario." ) End Sub 'Controlador Para El evento LoadCompleted. Privado Sub player_LoadCompleted ( ByVal remitente Como Objeto , _ ByVal e Como AsyncCompletedEventArgs) Dim Mensaje Como Cadena = [ cadena ] .formato ( "LoadCompleted: {0}" , _ Me .filepathTextbox.Text) ReportStatus (Mensaje) EnablePlaybackControls ( Verdadero ) End Sub 'Controlador Para El evento SoundLocationChanged. Privado Sub (player_LocationChanged ByVal remitente Como Objeto , _ ByVal e Como EventArgs) Dim Mensaje Como Cadena = [ cadena ] .formato ( "SoundLocationChanged: {0}" , _ player.SoundLocation) ReportStatus (Mensaje) End Sub Private Sub playSoundFromResource ( ByVal remitente Como Object , _ ByVal e Como EventArgs) Dim Una Medida System.Reflection. Asamblea = System.Reflection. Asamblea .GetExecutingAssembly () Dim s Como System.IO.Stream = a.GetManifestResourceStream ( "<AssemblyName> .chimes.wav " ) Dim Jugador Como SoundPlayer = Nuevo SoundPlayer (s) player.Play () End Sub Private Sub InitializeComponent () Me .filepathTextbox = Nuevo System.Windows.Forms.TextBox Me .selectFileButton = Nuevo System.Windows.Forms.Button Me .label1 = Nuevo System.Windows.Forms.Label Me .loadSyncButton = Nuevos System.Windows. Forms.Button Me .playOnceSyncButton = Nuevo System.Windows.Forms.Button Me .playOnceAsyncButton = Nuevo System.Windows.Forms.Button Me .stopButton = Nuevos System.Windows.Forms.Button Me .playLoopAsyncButton = Nuevos System.Windows.Forms. Botón Me .statusBar = Nuevo System.Windows.Forms.StatusBar Me .loadAsyncButton = Nuevo System.Windows.Forms.Button Me .SuspendLayout () ' 'filepathTextbox ' Me .filepathTextbox.Anchor System.Windows.Forms.AnchorStyles) Me .filepathTextbox .location = Nuevo System.Drawing.Point (7, 25) Me .filepathTextbox.Name = "filepathTextbox" Me .filepathTextbox.Size = Nuevo System.Drawing.Size (263, 20) Me .filepathTextbox.TabIndex = 1 Me .filepathTextbox .text = "" ' 'selectFileButton ' Me .selectFileButton.Anchor = CType (System.Windows.Forms.AnchorStyles.Top O System.Windows.Forms.AnchorStyles.Right, Sistema. Windows.Forms.AnchorStyles) Me .selectFileButton.Location = Nuevo System.Drawing.Point (276, 25) Me .selectFileButton.Name = "selectFileButton" Me .selectFileButton.Size = Nuevo System.Drawing.Size (23, 21) de Mí .selectFileButton.TabIndex = 2 Me .selectFileButton. Text = "..." ' 'label1 ' Me .label1.Location = Nuevo System.Drawing.Point (7, 7) Me .label1.Name = "label1" Me .label1 Clasifique = Nuevo System.Drawing.Size (145 17) Me .label1.TabIndex = 3 Me .label1.Text = ".wav camino o URL:" ' 'loadSyncButton ' Me .loadSyncButton.Location = Nuevo System.Drawing. Point (7, 53) Me .loadSyncButton.Name = "loadSyncButton" Me .loadSyncButton.Size = Nuevo System.Drawing.Size (142, 23) Me .loadSyncButton.TabIndex = 4 Me .loadSyncButton.Text = "Cargar síncrono" ' 'playOnceSyncButton ' Me .playOnceSyncButton.Location = Nuevo Sistema. Drawing.Point (7, 86) Me .playOnceSyncButton.Name = "playOnceSyncButton" Me .playOnceSyncButton.Size = Nuevo System.Drawing.Size (142, 23) Me .playOnceSyncButton. TabIndex = 5 Me .playOnceSyncButton.Text = "Reproducir Una Vez síncrono" ' 'playOnceAsyncButton ' Me .playOnceAsyncButton.Location = Nuevo System.Drawing.Point (149, 86) Me .playOnceAsyncButton.Name = "playOnceAsyncButton" Me .playOnceAsyncButton.Size = Nueva System.Drawing.Size (147, 23) Me .playOnceAsyncButton.TabIndex = 6 Me .playOnceAsyncButton.Text = "Reproducir Una Vez asincrónica" ' 'stopButton ' Me .stopButton.Location = Nuevo System.Drawing.Point (149, 109) Me .stopButton.Name = "stopButton" Mí .stopButton.Size = Nuevo System.Drawing.Size (147, 23) Me .stopButton.TabIndex = 7 Me .stopButton.Text = "Stop" ' 'playLoopAsyncButton ' Mí . playLoopAsyncButton. Descripción de la ubicación = Nuevo System.Drawing.Point (7, 109) Me .playLoopAsyncButton.Name = "playLoopAsyncButton" Me .playLoopAsyncButton.Size = Nuevo System.Drawing.Size (142, 23) Me .playLoopAsyncButton.TabIndex = 8 Mí . playLoopAsyncButton. Text = "asincrónica Loop" ' 'de estado ' Me .statusBar.Location = Nuevo System.Drawing.Point (0, 146) Me .statusBar.Name = "barra de estado" Me .statusBar.Size = Nuevo Sistema. Dibujo. Tamaño (306 22) Me .statusBar.SizingGrip = False Me .statusBar.TabIndex = 9 Me .statusBar.Text = "(estado pecado)" ' 'loadAsyncButton ' Me .loadAsyncButton.Location = Nuevo System.Drawing.Point (149, 53) Me .loadAsyncButton.Name = "loadAsyncButton" Me .loadAsyncButton.Size = Nuevo System.Drawing.Size (147, 23) Me .loadAsyncButton.TabIndex = 10 Me .loadAsyncButton.Text = "Carga asincrónica" ' 'SoundTestForm ' Mí .ClientSize = Nueva System.Drawing.Size (306, = Nueva System.Drawing.Size (310, 165) Me .Nombre = "SoundTestForm" Me .SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show Me .Texto = "API Formulario Prueba de sonido" Me .ResumeLayout ( False ) End Sub 'InitializeComponent <STAThread ()> _ Shared Sub Principal () Application.Run ( Nueva SoundTestForm) End Sub End Class SoundTestForm '
-------------------------------------------------- -----------------------------
No hay comentarios:
Publicar un comentario