' REPRODUCTOR DE MP3, AVI Y M3U --- OCX visible --- 29/Mayo/2003
Public Class frmPlayer
Inherits System.Windows.Forms.Form
#Region " Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
Friend WithEvents Panel2 As System.Windows.Forms.Panel
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents lbTitulo As System.Windows.Forms.Label
Friend WithEvents lbAutor As System.Windows.Forms.Label
Friend WithEvents ocxPlayer As AxWMPLib.AxWindowsMediaPlayer
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmPlayer))
Me.Panel2 = New System.Windows.Forms.Panel
Me.lbAutor = New System.Windows.Forms.Label
Me.lbTitulo = New System.Windows.Forms.Label
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.ocxPlayer = New AxWMPLib.AxWindowsMediaPlayer
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.Panel2.SuspendLayout()
CType(Me.ocxPlayer, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Panel2
'
Me.Panel2.BackColor = System.Drawing.SystemColors.Control
Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Panel2.Controls.Add(Me.lbAutor)
Me.Panel2.Controls.Add(Me.lbTitulo)
Me.Panel2.Location = New System.Drawing.Point(8, 264)
Me.Panel2.Name = "Panel2"
Me.Panel2.Size = New System.Drawing.Size(320, 56)
Me.Panel2.TabIndex = 4
'
'lbAutor
'
Me.lbAutor.BackColor = System.Drawing.SystemColors.Control
Me.lbAutor.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.lbAutor.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lbAutor.ForeColor = System.Drawing.Color.Navy
Me.lbAutor.Location = New System.Drawing.Point(8, 32)
Me.lbAutor.Name = "lbAutor"
Me.lbAutor.Size = New System.Drawing.Size(304, 16)
Me.lbAutor.TabIndex = 3
Me.lbAutor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.ToolTip1.SetToolTip(Me.lbAutor, "Intérprete de la canción")
'
'lbTitulo
'
Me.lbTitulo.BackColor = System.Drawing.SystemColors.Control
Me.lbTitulo.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.lbTitulo.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lbTitulo.ForeColor = System.Drawing.Color.Navy
Me.lbTitulo.Location = New System.Drawing.Point(8, 8)
Me.lbTitulo.Name = "lbTitulo"
Me.lbTitulo.Size = New System.Drawing.Size(304, 16)
Me.lbTitulo.TabIndex = 1
Me.lbTitulo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.ToolTip1.SetToolTip(Me.lbTitulo, "Título de la canción")
'
'OpenFileDialog1
'
Me.OpenFileDialog1.RestoreDirectory = True
'
'ocxPlayer
'
Me.ocxPlayer.Enabled = True
Me.ocxPlayer.Location = New System.Drawing.Point(8, 8)
Me.ocxPlayer.Name = "ocxPlayer"
Me.ocxPlayer.OcxState = CType(resources.GetObject("ocxPlayer.OcxState"), System.Windows.Forms.AxHost.State)
Me.ocxPlayer.Size = New System.Drawing.Size(320, 248)
Me.ocxPlayer.TabIndex = 3
Me.ocxPlayer.TabStop = False
'
'ToolTip1
'
Me.ToolTip1.AutomaticDelay = 300
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem3})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = "Abrir archivo"
'
'MenuItem2
'
Me.MenuItem2.Index = 1
Me.MenuItem2.Text = "Ver código"
'
'MenuItem3
'
Me.MenuItem3.Index = 2
Me.MenuItem3.Text = "Salir"
'
'frmPlayer
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(334, 324)
Me.Controls.Add(Me.Panel2)
Me.Controls.Add(Me.ocxPlayer)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Menu = Me.MainMenu1
Me.Name = "frmPlayer"
Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Me.Text = "MP3 | M3U | AVI"
Me.Panel2.ResumeLayout(False)
CType(Me.ocxPlayer, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmPlayer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Top = 80 ' posición y del formulario
Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) \ 4 ' posición x del formulario
End Sub
' Mostrar información de la canción al cambiar el estado del reproductor (PlayStateChange)
' al tener autostart = true simplemente con elegir un archivo cambia el estado de reproducción
Private Sub ocxPlayer_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles ocxPlayer.PlayStateChange
' vaciar la información de la canción anterior
lbTitulo.Text = ""
lbAutor.Text = ""
Dim cadena As String ' para guardar la extensión del archivo (3 últimos caracteres)
' Math.Max sive para evitar errores si la cadena mide menos de 3 caracteres (índice negativo)
cadena = ocxPlayer.URL.Substring(Math.Max(0, ocxPlayer.URL.Length - 3))
If Not cadena = "avi" Then ' si no es un AVI mostrar toda la información
lbTitulo.Text = ocxPlayer.currentMedia.getItemInfobyType("title", "", 0) ' título
lbAutor.Text = ocxPlayer.currentMedia.getItemInfobyType("author", "", 0) ' autor
ElseIf cadena = "avi" Then ' si es un AVI mostrar sólo el título
lbAutor.Text = ""
End If
End Sub
' Abre el cuadro de diálogo
Private Sub MenuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
' presentar al usuario un cuadro de diálogo
Dim openFile As New OpenFileDialog
' mostrar solamente archivos M3U, MP3 y AVI
openFile.Filter = "Listas de canciones (*.m3u)|*.m3u|Archivos Mpeg Layer 3 (*.mp3)|*.mp3|Archivos de vídeo (*.avi)|*.avi"
' si elegimos algún archivo
If openFile.ShowDialog() = DialogResult.OK Then
' abrir el archivo elegido en el reproductor
ocxPlayer.URL = openFile.FileName
' vaciar la información de la canción anterior
lbTitulo.Text = ""
lbAutor.Text = ""
End If
End Sub
' Muestra el segundo formulario
Private Sub MenuItem2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Dim code As New Form2 ' crear una nueva instancia de la clase formulario
code.ShowDialog() ' mostrar el formulario
End Sub
' Cierra el formulario
Private Sub MenuItem3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Close()
End Sub
End Class